Commit 07a4d830 authored by Alp Deniz Ogut's avatar Alp Deniz Ogut
Browse files

Code format

parent f22c9933
Pipeline #14986 passed with stages
in 1 minute and 41 seconds
Showing with 12 additions and 10 deletions
+12 -10
......@@ -140,17 +140,19 @@ def get_feeds(
feeds = [n for n in feeds if n.id == feed_id]
return feeds
class RSSFeedChat(BaseModel):
messages: list[dict]
index_name: str = "rss_feed"
category: str = "all"
@app.post("/feed/chat")
def feed_chat(
req: RSSFeedChat,
plugin: RSSImporter = Depends(get_plugin)
):
return StreamingResponse(plugin.feed_chat(req.index_name, req.messages, req.category), media_type="text/event-stream")
def feed_chat(req: RSSFeedChat, plugin: RSSImporter = Depends(get_plugin)):
return StreamingResponse(
plugin.feed_chat(req.index_name, req.messages, req.category),
media_type="text/event-stream",
)
@app.get("/update_all_feeds")
......
......@@ -312,12 +312,10 @@ Ensure the output is a one-level bullet list without additional text.
return summary
def feed_chat(self, index_name, messages, category_text=None):
index_query = messages[-1]['content']
index_query = messages[-1]["content"]
if category_text is not None and category_text != "all":
index_query = f"{index_query} {category_text}"
print(
f"Sending chat request with query: {index_query}"
)
print(f"Sending chat request with query: {index_query}")
rss_client_kwargs = {
"url": RSS_POD_URL,
"owner_key": RSS_OWNER_KEY,
......@@ -331,6 +329,7 @@ Ensure the output is a one-level bullet list without additional text.
logger.error(f"Error during chat request stream: {e}")
return None
def bulletize_summary(summary: str) -> str:
"""Converts a summary to a bulletized list per sentence."""
nltk.download("punkt", quiet=True)
......@@ -375,6 +374,7 @@ def chat_request(index_name, messages, pod_client_kwargs, index_query=None):
logger.error(f"JSON decoding failed for LLM reply: {r}")
return reply
def chat_request_stream(index_name, messages, pod_client_kwargs, index_query=None):
data: dict = {
"index_name": index_name,
......@@ -388,7 +388,7 @@ def chat_request_stream(index_name, messages, pod_client_kwargs, index_query=Non
f"{MEMRI_BOT_URL}/v1/memory/chat", json=data, timeout=120, stream=True
).iter_lines():
if r:
yield r + b'\n'
yield r + b"\n"
def semantic_index_request(ids: list[str], documents: list[str]):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment