Move user_prompt to system prompt
- Refactor query prompt handling to separate user prompts in system context - Simplify user_query to only contain query - Apply changes to both kg_query and naive_query
This commit is contained in:
parent
058ce83dba
commit
fba2356c81
2 changed files with 17 additions and 11 deletions
|
|
@ -2392,15 +2392,14 @@ async def kg_query(
|
|||
# Build system prompt
|
||||
sys_prompt_temp = system_prompt if system_prompt else PROMPTS["rag_response"]
|
||||
sys_prompt = sys_prompt_temp.format(
|
||||
user_prompt=f"```\n{query_param.user_prompt}\n```"
|
||||
if query_param.user_prompt
|
||||
else "n/a",
|
||||
context_data=context_result.context,
|
||||
response_type=query_param.response_type,
|
||||
)
|
||||
|
||||
user_query = (
|
||||
"\n\n".join([query, query_param.user_prompt])
|
||||
if query_param.user_prompt
|
||||
else query
|
||||
)
|
||||
user_query = query
|
||||
|
||||
if query_param.only_need_prompt:
|
||||
prompt_content = "\n\n".join([sys_prompt, "---User Query---", user_query])
|
||||
|
|
@ -4264,18 +4263,17 @@ async def naive_query(
|
|||
if query_param.only_need_context and not query_param.only_need_prompt:
|
||||
return QueryResult(content=context_content, raw_data=raw_data)
|
||||
|
||||
user_query = (
|
||||
"\n\n".join([query, query_param.user_prompt])
|
||||
if query_param.user_prompt
|
||||
else query
|
||||
)
|
||||
|
||||
sys_prompt_temp = system_prompt if system_prompt else PROMPTS["naive_rag_response"]
|
||||
sys_prompt = sys_prompt_temp.format(
|
||||
user_prompt=f"```\n{query_param.user_prompt}\n```"
|
||||
if query_param.user_prompt
|
||||
else "n/a",
|
||||
content_data=text_units_str,
|
||||
response_type=query_param.response_type,
|
||||
)
|
||||
|
||||
user_query = query
|
||||
|
||||
if query_param.only_need_prompt:
|
||||
prompt_content = "\n\n".join([sys_prompt, "---User Query---", user_query])
|
||||
return QueryResult(content=prompt_content, raw_data=raw_data)
|
||||
|
|
|
|||
|
|
@ -243,6 +243,7 @@ Consider the conversation history if provided to maintain conversational flow an
|
|||
- The Document Title in the citation must retain its original language.
|
||||
- Output each citation on an individual line
|
||||
- Provide maximum of 5 most relevant citations.
|
||||
- Do not generate footnotes section or any text after the references.
|
||||
|
||||
5. **Reference Section Example:**
|
||||
```
|
||||
|
|
@ -252,6 +253,9 @@ Consider the conversation history if provided to maintain conversational flow an
|
|||
* [3] Document Title Three
|
||||
```
|
||||
|
||||
6. **Additional Instructions**: {user_prompt}
|
||||
|
||||
|
||||
---Source Data---
|
||||
Knowledge Graph and Document Chunks:
|
||||
|
||||
|
|
@ -291,6 +295,7 @@ Consider the conversation history if provided to maintain conversational flow an
|
|||
- The Document Title in the citation must retain its original language.
|
||||
- Output each citation on an individual line
|
||||
- Provide maximum of 5 most relevant citations.
|
||||
- Do not generate footnotes section or any text after the references.
|
||||
|
||||
5. **Reference Section Example:**
|
||||
```
|
||||
|
|
@ -300,6 +305,9 @@ Consider the conversation history if provided to maintain conversational flow an
|
|||
* [3] Document Title Three
|
||||
```
|
||||
|
||||
6. **Additional Instructions**: {user_prompt}
|
||||
|
||||
|
||||
---Source Data---
|
||||
Document Chunks:
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue