Explorar el Código

Turn the relative date in question to absolute date (#3372)

### What problem does this PR solve?


### Type of change

- [x] Performance Improvement
tags/v0.14.0
Kevin Hu hace 11 meses
padre
commit
667d0e5537
No account linked to committer's email address
Se han modificado 1 ficheros con 18 adiciones y 3 borrados
  1. 18
    3
      api/db/services/dialog_service.py

+ 18
- 3
api/db/services/dialog_service.py Ver fichero

@@ -19,8 +19,8 @@ import json
import re
from copy import deepcopy
from timeit import default_timer as timer
import datetime
from datetime import timedelta
from api.db import LLMType, ParserType,StatusEnum
from api.db.db_models import Dialog, Conversation,DB
from api.db.services.common_service import CommonService
@@ -526,9 +526,16 @@ def full_question(tenant_id, llm_id, messages):
if m["role"] not in ["user", "assistant"]: continue
conv.append("{}: {}".format(m["role"].upper(), m["content"]))
conv = "\n".join(conv)
today = datetime.date.today().isoformat()
yesterday = (datetime.date.today() - timedelta(days=1)).isoformat()
tomorrow = (datetime.date.today() + timedelta(days=1)).isoformat()
prompt = f"""
Role: A helpful assistant
Task: Generate a full user question that would follow the conversation.

Task and steps:
1. Generate a full user question that would follow the conversation.
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}.
Requirements & Restrictions:
- Text generated MUST be in the same language of the original user's question.
- 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?
###############
Output: What's the full name of Donald Trump's mother Mary Trump?

------------
# Example 3
## Conversation
USER: What's the weather today in London?
ASSISTANT: Cloudy.
USER: What's about tomorrow in Rochester?
###############
Output: What's the weather in Rochester on {tomorrow}?
######################

# Real Data

Cargando…
Cancelar
Guardar