Skip to content

Commit

Permalink
RAG assistant fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
artitw committed Dec 8, 2024
1 parent e9f2ef4 commit 3da8622
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="text2text",
version="1.8.4",
version="1.8.5",
author="artitw",
author_email="artitw@gmail.com",
description="Text2Text Language Modeling Toolkit",
Expand Down
12 changes: 4 additions & 8 deletions text2text/rag_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,10 @@ def __init__(self, **kwargs):
def chat_completion(self, messages=[{"role": "user", "content": "hello"}], stream=False, schema=None, **kwargs):
k = kwargs.get("k", 3)
query = messages[-1]["content"]
question_check = f"Respond YES if this is a question; otherwise respond NO: {query}"
question_check = [{"role": "user", "content": question_check}]
response = t2t.Assistant.chat_completion(self, question_check)["message"]["content"]
docs = []
if is_affirmative(response):
reword_prompt = f"Reword this question to be a demand: {query}"
reword_prompt = [{"role": "user", "content": reword_prompt}]
demand = t2t.Assistant.chat_completion(self, reword_prompt)["message"]["content"]
if len(query) > 100:
summarize_prompt = f'Summarize succinctly what the user wants in a sentence less than 10 words:\n\n"{query}"'
summarize_prompt = [{"role": "user", "content": summarize_prompt}]
demand = t2t.Assistant.chat_completion(self, summarize_prompt)["message"]["content"]
docs = self.index.retrieve([demand], k=k)[0]
else:
docs = self.index.retrieve([query], k=k)[0]
Expand Down

0 comments on commit 3da8622

Please sign in to comment.