zrguo commited on
Commit
65da904
·
2 Parent(s): 51a5e11 72cd55c

Merge pull request #343 from sebastianschramm/ses/fix_language_templating_in_prompts

Browse files
Files changed (2) hide show
  1. lightrag/operate.py +8 -1
  2. lightrag/prompt.py +3 -3
lightrag/operate.py CHANGED
@@ -59,6 +59,9 @@ async def _handle_entity_relation_summary(
59
  llm_max_tokens = global_config["llm_model_max_token_size"]
60
  tiktoken_model_name = global_config["tiktoken_model_name"]
61
  summary_max_tokens = global_config["entity_summary_to_max_tokens"]
 
 
 
62
 
63
  tokens = encode_string_by_tiktoken(description, model_name=tiktoken_model_name)
64
  if len(tokens) < summary_max_tokens: # No need for summary
@@ -70,6 +73,7 @@ async def _handle_entity_relation_summary(
70
  context_base = dict(
71
  entity_name=entity_or_relation_name,
72
  description_list=use_description.split(GRAPH_FIELD_SEP),
 
73
  )
74
  use_prompt = prompt_template.format(**context_base)
75
  logger.debug(f"Trigger summary: {entity_or_relation_name}")
@@ -444,6 +448,9 @@ async def kg_query(
444
  )
445
  else:
446
  examples = "\n".join(PROMPTS["keywords_extraction_examples"])
 
 
 
447
 
448
  # Set mode
449
  if query_param.mode not in ["local", "global", "hybrid"]:
@@ -453,7 +460,7 @@ async def kg_query(
453
  # LLM generate keywords
454
  use_model_func = global_config["llm_model_func"]
455
  kw_prompt_temp = PROMPTS["keywords_extraction"]
456
- kw_prompt = kw_prompt_temp.format(query=query, examples=examples)
457
  result = await use_model_func(kw_prompt)
458
  logger.info("kw_prompt result:")
459
  print(result)
 
59
  llm_max_tokens = global_config["llm_model_max_token_size"]
60
  tiktoken_model_name = global_config["tiktoken_model_name"]
61
  summary_max_tokens = global_config["entity_summary_to_max_tokens"]
62
+ language = global_config["addon_params"].get(
63
+ "language", PROMPTS["DEFAULT_LANGUAGE"]
64
+ )
65
 
66
  tokens = encode_string_by_tiktoken(description, model_name=tiktoken_model_name)
67
  if len(tokens) < summary_max_tokens: # No need for summary
 
73
  context_base = dict(
74
  entity_name=entity_or_relation_name,
75
  description_list=use_description.split(GRAPH_FIELD_SEP),
76
+ language=language,
77
  )
78
  use_prompt = prompt_template.format(**context_base)
79
  logger.debug(f"Trigger summary: {entity_or_relation_name}")
 
448
  )
449
  else:
450
  examples = "\n".join(PROMPTS["keywords_extraction_examples"])
451
+ language = global_config["addon_params"].get(
452
+ "language", PROMPTS["DEFAULT_LANGUAGE"]
453
+ )
454
 
455
  # Set mode
456
  if query_param.mode not in ["local", "global", "hybrid"]:
 
460
  # LLM generate keywords
461
  use_model_func = global_config["llm_model_func"]
462
  kw_prompt_temp = PROMPTS["keywords_extraction"]
463
+ kw_prompt = kw_prompt_temp.format(query=query, examples=examples, language=language)
464
  result = await use_model_func(kw_prompt)
465
  logger.info("kw_prompt result:")
466
  print(result)
lightrag/prompt.py CHANGED
@@ -33,7 +33,7 @@ Format each relationship as ("relationship"{tuple_delimiter}<source_entity>{tupl
33
  3. Identify high-level key words that summarize the main concepts, themes, or topics of the entire text. These should capture the overarching ideas present in the document.
34
  Format the content-level key words as ("content_keywords"{tuple_delimiter}<high_level_keywords>)
35
 
36
- 4. Return output in English as a single list of all the entities and relationships identified in steps 1 and 2. Use **{record_delimiter}** as the list delimiter.
37
 
38
  5. When finished, output {completion_delimiter}
39
 
@@ -131,7 +131,7 @@ Given one or two entities, and a list of descriptions, all related to the same e
131
  Please concatenate all of these into a single, comprehensive description. Make sure to include information collected from all the descriptions.
132
  If the provided descriptions are contradictory, please resolve the contradictions and provide a single, coherent summary.
133
  Make sure it is written in third person, and include the entity names so we the have full context.
134
- Use Chinese as output language.
135
 
136
  #######
137
  -Data-
@@ -178,7 +178,7 @@ Add sections and commentary to the response as appropriate for the length and fo
178
  PROMPTS["keywords_extraction"] = """---Role---
179
 
180
  You are a helpful assistant tasked with identifying both high-level and low-level keywords in the user's query.
181
- Use Chinese as output language.
182
 
183
  ---Goal---
184
 
 
33
  3. Identify high-level key words that summarize the main concepts, themes, or topics of the entire text. These should capture the overarching ideas present in the document.
34
  Format the content-level key words as ("content_keywords"{tuple_delimiter}<high_level_keywords>)
35
 
36
+ 4. Return output in {language} as a single list of all the entities and relationships identified in steps 1 and 2. Use **{record_delimiter}** as the list delimiter.
37
 
38
  5. When finished, output {completion_delimiter}
39
 
 
131
  Please concatenate all of these into a single, comprehensive description. Make sure to include information collected from all the descriptions.
132
  If the provided descriptions are contradictory, please resolve the contradictions and provide a single, coherent summary.
133
  Make sure it is written in third person, and include the entity names so we the have full context.
134
+ Use {language} as output language.
135
 
136
  #######
137
  -Data-
 
178
  PROMPTS["keywords_extraction"] = """---Role---
179
 
180
  You are a helpful assistant tasked with identifying both high-level and low-level keywords in the user's query.
181
+ Use {language} as output language.
182
 
183
  ---Goal---
184