Kevin Hu
commited on
Commit
·
31f09e1
1
Parent(s):
58f507b
Turn the relative date in question to absolute date (#3372)
Browse files### What problem does this PR solve?
### Type of change
- [x] Performance Improvement
api/db/services/dialog_service.py
CHANGED
@@ -19,8 +19,8 @@ import json
|
|
19 |
import re
|
20 |
from copy import deepcopy
|
21 |
from timeit import default_timer as timer
|
22 |
-
|
23 |
-
|
24 |
from api.db import LLMType, ParserType,StatusEnum
|
25 |
from api.db.db_models import Dialog, Conversation,DB
|
26 |
from api.db.services.common_service import CommonService
|
@@ -526,9 +526,16 @@ def full_question(tenant_id, llm_id, messages):
|
|
526 |
if m["role"] not in ["user", "assistant"]: continue
|
527 |
conv.append("{}: {}".format(m["role"].upper(), m["content"]))
|
528 |
conv = "\n".join(conv)
|
|
|
|
|
|
|
529 |
prompt = f"""
|
530 |
Role: A helpful assistant
|
531 |
-
|
|
|
|
|
|
|
|
|
532 |
Requirements & Restrictions:
|
533 |
- Text generated MUST be in the same language of the original user's question.
|
534 |
- If the user's latest question is completely, don't do anything, just return the original question.
|
@@ -557,6 +564,14 @@ User: What's her full name?
|
|
557 |
###############
|
558 |
Output: What's the full name of Donald Trump's mother Mary Trump?
|
559 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
560 |
######################
|
561 |
|
562 |
# Real Data
|
|
|
19 |
import re
|
20 |
from copy import deepcopy
|
21 |
from timeit import default_timer as timer
|
22 |
+
import datetime
|
23 |
+
from datetime import timedelta
|
24 |
from api.db import LLMType, ParserType,StatusEnum
|
25 |
from api.db.db_models import Dialog, Conversation,DB
|
26 |
from api.db.services.common_service import CommonService
|
|
|
526 |
if m["role"] not in ["user", "assistant"]: continue
|
527 |
conv.append("{}: {}".format(m["role"].upper(), m["content"]))
|
528 |
conv = "\n".join(conv)
|
529 |
+
today = datetime.date.today().isoformat()
|
530 |
+
yesterday = (datetime.date.today() - timedelta(days=1)).isoformat()
|
531 |
+
tomorrow = (datetime.date.today() + timedelta(days=1)).isoformat()
|
532 |
prompt = f"""
|
533 |
Role: A helpful assistant
|
534 |
+
|
535 |
+
Task and steps:
|
536 |
+
1. Generate a full user question that would follow the conversation.
|
537 |
+
2. If the user's question involves relative date, you need to convert it into absolute date based on the current date, which is {today}. For example: 'yesterday' would be converted to {yesterday}.
|
538 |
+
|
539 |
Requirements & Restrictions:
|
540 |
- Text generated MUST be in the same language of the original user's question.
|
541 |
- If the user's latest question is completely, don't do anything, just return the original question.
|
|
|
564 |
###############
|
565 |
Output: What's the full name of Donald Trump's mother Mary Trump?
|
566 |
|
567 |
+
------------
|
568 |
+
# Example 3
|
569 |
+
## Conversation
|
570 |
+
USER: What's the weather today in London?
|
571 |
+
ASSISTANT: Cloudy.
|
572 |
+
USER: What's about tomorrow in Rochester?
|
573 |
+
###############
|
574 |
+
Output: What's the weather in Rochester on {tomorrow}?
|
575 |
######################
|
576 |
|
577 |
# Real Data
|