Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat with better date context #1579

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions backend/utils/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ class TopicsContext(BaseModel):


class DatesContext(BaseModel):
dates_range: List[datetime] = Field(default=[], description="Dates range. (Optional)")
dates_range: List[datetime] = Field(default=[],
examples=[['2024-12-23T00:00:00+07:00', '2024-12-23T23:59:00+07:00']],
description="Dates range. (Optional)",)


def requires_context_v1(messages: List[Message]) -> bool:
Expand Down Expand Up @@ -406,14 +408,13 @@ def retrieve_context_dates_by_question(question: str, tz: str) -> List[datetime]
prompt = f'''
You MUST determine the appropriate date range in {tz} that provides context for answering the question provided.

Current date: {datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S')} UTC.
Current date time in UTC: {datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S')}

Question:
```
{question}
```

Date range:
'''.replace(' ', '').strip()

# print(prompt)
Expand Down Expand Up @@ -563,7 +564,7 @@ def answer_omi_question(messages: List[Message], context: str) -> str:
""".replace(' ', '').strip()
return llm_mini.invoke(prompt).content

def qa_rag(uid: str, question: str, context: str, plugin: Optional[Plugin] = None, cited: Optional[bool] = False, messages: List[Message] = []) -> str:
def qa_rag(uid: str, question: str, context: str, plugin: Optional[Plugin] = None, cited: Optional[bool] = False, messages: List[Message] = [], tz: Optional[str] = "UTC") -> str:
user_name, facts_str = get_prompt_facts(uid)
facts_str = '\n'.join(facts_str.split('\n')[1:]).strip()

Expand Down Expand Up @@ -615,6 +616,10 @@ def qa_rag(uid: str, question: str, context: str, plugin: Optional[Plugin] = Non
{facts_str.strip()}
---

Question's timezone: {tz}

Current date time in UTC: {datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S')}

Anwser:
""".replace(' ', '').replace('\n\n\n', '\n\n').strip()
# print('qa_rag prompt', prompt)
Expand Down
1 change: 1 addition & 0 deletions backend/utils/retrieval/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def qa_handler(state: GraphState):
state.get("plugin_selected"),
cited=state.get("cited"),
messages=state.get("messages"),
tz=state.get("tz"),
)
return {"answer": response, "ask_for_nps": True}

Expand Down