You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hugegraph.apache.org by "day0n (via GitHub)" <gi...@apache.org> on 2025/06/06 15:32:25 UTC
[PR] feat(llm): Support switching prompt EN/CN. [incubator-hugegraph-ai]
day0n opened a new pull request, #269:
URL: https://github.com/apache/incubator-hugegraph-ai/pull/269
close #260
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feat(llm): Support switching prompt EN/CN. [incubator-hugegraph-ai]
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #269:
URL: https://github.com/apache/incubator-hugegraph-ai/pull/269#discussion_r2249907250
##########
hugegraph-llm/src/hugegraph_llm/demo/rag_demo/configs_block.py:
##########
@@ -64,14 +64,25 @@
return 200
-def test_api_connection(url, method="GET", headers=None, params=None, body=None, auth=None, origin_call=None) -> int:
+def test_api_connection(
+ url, method="GET", headers=None, params=None, body=None, auth=None, origin_call=None
+) -> int:
# TODO: use fastapi.request / starlette instead?
log.debug("Request URL: %s", url)
try:
if method.upper() == "GET":
- resp = requests.get(url, headers=headers, params=params, timeout=(1.0, 5.0), auth=auth)
+ resp = requests.get(
+ url, headers=headers, params=params, timeout=(1.0, 5.0), auth=auth
+ )
elif method.upper() == "POST":
- resp = requests.post(url, headers=headers, params=params, json=body, timeout=(1.0, 5.0), auth=auth)
+ resp = requests.post(
+ url,
+ headers=headers,
+ params=params,
+ json=body,
+ timeout=(1.0, 5.0),
+ auth=auth,
+ )
Review Comment:
## Full server-side request forgery
The full URL of this request depends on a [user-provided value](1).
The full URL of this request depends on a [user-provided value](2).
The full URL of this request depends on a [user-provided value](3).
[Show more details](https://github.com/apache/incubator-hugegraph-ai/security/code-scanning/31)
##########
hugegraph-llm/src/hugegraph_llm/demo/rag_demo/configs_block.py:
##########
@@ -64,14 +64,25 @@
return 200
-def test_api_connection(url, method="GET", headers=None, params=None, body=None, auth=None, origin_call=None) -> int:
+def test_api_connection(
+ url, method="GET", headers=None, params=None, body=None, auth=None, origin_call=None
+) -> int:
# TODO: use fastapi.request / starlette instead?
log.debug("Request URL: %s", url)
try:
if method.upper() == "GET":
- resp = requests.get(url, headers=headers, params=params, timeout=(1.0, 5.0), auth=auth)
+ resp = requests.get(
+ url, headers=headers, params=params, timeout=(1.0, 5.0), auth=auth
+ )
Review Comment:
## Full server-side request forgery
The full URL of this request depends on a [user-provided value](1).
The full URL of this request depends on a [user-provided value](2).
The full URL of this request depends on a [user-provided value](3).
[Show more details](https://github.com/apache/incubator-hugegraph-ai/security/code-scanning/30)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feat(llm): Support switching prompt EN/CN. [incubator-hugegraph-ai]
Posted by "day0n (via GitHub)" <gi...@apache.org>.
day0n commented on code in PR #269:
URL: https://github.com/apache/incubator-hugegraph-ai/pull/269#discussion_r2228647951
##########
hugegraph-llm/src/hugegraph_llm/config/models/base_prompt_config.py:
##########
@@ -61,71 +69,74 @@ def ensure_yaml_file_exists(self):
# Load existing values from the YAML file into the class attributes
for key, value in data.items():
setattr(self, key, value)
+
+ # Check if the language in the .env file matches the language in the YAML file
+ env_lang = self.llm_settings.language.lower() if hasattr(self, 'llm_settings') and self.llm_settings.language else 'en'
+ yaml_lang = data.get('_language_generated', 'en').lower()
+
+ if env_lang.strip() != yaml_lang.strip():
+ log.warning(
+ f"Prompt was changed '.env' language is '{env_lang}', "
+ f"but '{F_NAME}' was generated for '{yaml_lang}'. "
+ f"Regenerating the prompt file..."
+ )
+ if self.llm_settings.language.lower() == "cn":
+ self.answer_prompt = self.answer_prompt_CN
+ self.extract_graph_prompt = self.extract_graph_prompt_CN
+ self.gremlin_generate_prompt = self.gremlin_generate_prompt_CN
+ self.keywords_extract_prompt = self.keywords_extract_prompt_CN
+ self.doc_input_text = self.doc_input_text_CN
+ else:
+ self.answer_prompt = self.answer_prompt_EN
+ self.extract_graph_prompt = self.extract_graph_prompt_EN
+ self.gremlin_generate_prompt = self.gremlin_generate_prompt_EN
+ self.keywords_extract_prompt = self.keywords_extract_prompt_EN
+ self.doc_input_text = self.doc_input_text_EN
else:
self.generate_yaml_file()
log.info("Prompt file '%s' doesn't exist, create it.", yaml_file_path)
Review Comment:
Can but not necessary
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feat(llm): Support switching prompt EN/CN. [incubator-hugegraph-ai]
Posted by "day0n (via GitHub)" <gi...@apache.org>.
day0n commented on code in PR #269:
URL: https://github.com/apache/incubator-hugegraph-ai/pull/269#discussion_r2228570995
##########
hugegraph-llm/src/hugegraph_llm/config/models/base_prompt_config.py:
##########
@@ -61,71 +69,74 @@ def ensure_yaml_file_exists(self):
# Load existing values from the YAML file into the class attributes
for key, value in data.items():
setattr(self, key, value)
+
+ # Check if the language in the .env file matches the language in the YAML file
+ env_lang = self.llm_settings.language.lower() if hasattr(self, 'llm_settings') and self.llm_settings.language else 'en'
+ yaml_lang = data.get('_language_generated', 'en').lower()
+
+ if env_lang.strip() != yaml_lang.strip():
+ log.warning(
+ f"Prompt was changed '.env' language is '{env_lang}', "
+ f"but '{F_NAME}' was generated for '{yaml_lang}'. "
+ f"Regenerating the prompt file..."
+ )
+ if self.llm_settings.language.lower() == "cn":
Review Comment:
.lower()
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feat(llm): Support switching prompt EN/CN. [incubator-hugegraph-ai]
Posted by "imbajin (via GitHub)" <gi...@apache.org>.
imbajin merged PR #269:
URL: https://github.com/apache/incubator-hugegraph-ai/pull/269
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feat(llm): Support switching prompt EN/CN. [incubator-hugegraph-ai]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #269:
URL: https://github.com/apache/incubator-hugegraph-ai/pull/269#discussion_r2218814994
##########
hugegraph-llm/src/hugegraph_llm/config/models/base_prompt_config.py:
##########
@@ -29,6 +29,13 @@
yaml_file_path = os.path.join(os.getcwd(), "src/hugegraph_llm/resources/demo", F_NAME)
+class LiteralStr(str): pass
Review Comment:
The LiteralStr class lacks documentation explaining its purpose for YAML literal string representation. Adding a docstring would improve code maintainability.
```suggestion
class LiteralStr(str):
"""
A subclass of `str` used to represent YAML literal strings.
This class is associated with a custom YAML representer (`literal_str_representer`)
that ensures strings of this type are serialized using the literal style (`|`).
"""
```
##########
hugegraph-llm/src/hugegraph_llm/config/prompt_config.py:
##########
@@ -424,4 +426,6 @@ class PromptConfig(BasePromptConfig):
{user_scenario}
## Your Generated "Graph Extract Prompt Header":
+## Language Requirement:
+Please generate the prompt in {language} language.
Review Comment:
The comment section '## Language Requirement:' appears to be incomplete. It should include more detailed documentation about how the language parameter affects prompt generation and what values are expected.
```suggestion
Please generate the prompt in {language} language.
# The `language` parameter specifies the desired output language for the generated prompt.
# It affects the language used in the generated text, including instructions, examples, and any other content.
# Expected values for the `language` parameter include standard language names (e.g., "English", "French") or language codes (e.g., "en", "fr").
# Ensure that the provided `language` value is supported by the system to avoid errors or unexpected behavior.
```
##########
hugegraph-llm/src/hugegraph_llm/config/models/base_prompt_config.py:
##########
@@ -61,71 +69,74 @@ def ensure_yaml_file_exists(self):
# Load existing values from the YAML file into the class attributes
for key, value in data.items():
setattr(self, key, value)
+
+ # Check if the language in the .env file matches the language in the YAML file
+ env_lang = self.llm_settings.language.lower() if hasattr(self, 'llm_settings') and self.llm_settings.language else 'en'
+ yaml_lang = data.get('_language_generated', 'en').lower()
+
+ if env_lang.strip() != yaml_lang.strip():
+ log.warning(
+ f"Prompt was changed '.env' language is '{env_lang}', "
+ f"but '{F_NAME}' was generated for '{yaml_lang}'. "
+ f"Regenerating the prompt file..."
+ )
+ if self.llm_settings.language.lower() == "cn":
+ self.answer_prompt = self.answer_prompt_CN
+ self.extract_graph_prompt = self.extract_graph_prompt_CN
+ self.gremlin_generate_prompt = self.gremlin_generate_prompt_CN
+ self.keywords_extract_prompt = self.keywords_extract_prompt_CN
+ self.doc_input_text = self.doc_input_text_CN
+ else:
+ self.answer_prompt = self.answer_prompt_EN
+ self.extract_graph_prompt = self.extract_graph_prompt_EN
+ self.gremlin_generate_prompt = self.gremlin_generate_prompt_EN
+ self.keywords_extract_prompt = self.keywords_extract_prompt_EN
+ self.doc_input_text = self.doc_input_text_EN
else:
self.generate_yaml_file()
log.info("Prompt file '%s' doesn't exist, create it.", yaml_file_path)
Review Comment:
The language selection logic is duplicated in lines 83-94 and 126-137. This should be extracted into a separate method to reduce code duplication and improve maintainability.
```suggestion
self._set_language_prompts()
else:
self.answer_prompt = self.answer_prompt_EN
self.extract_graph_prompt = self.extract_graph_prompt_EN
self.gremlin_generate_prompt = self.gremlin_generate_prompt_EN
self.keywords_extract_prompt = self.keywords_extract_prompt_EN
self.doc_input_text = self.doc_input_text_EN
```
##########
hugegraph-llm/src/hugegraph_llm/config/models/base_prompt_config.py:
##########
@@ -61,71 +69,74 @@ def ensure_yaml_file_exists(self):
# Load existing values from the YAML file into the class attributes
for key, value in data.items():
setattr(self, key, value)
+
+ # Check if the language in the .env file matches the language in the YAML file
+ env_lang = self.llm_settings.language.lower() if hasattr(self, 'llm_settings') and self.llm_settings.language else 'en'
+ yaml_lang = data.get('_language_generated', 'en').lower()
+
+ if env_lang.strip() != yaml_lang.strip():
+ log.warning(
+ f"Prompt was changed '.env' language is '{env_lang}', "
+ f"but '{F_NAME}' was generated for '{yaml_lang}'. "
+ f"Regenerating the prompt file..."
+ )
+ if self.llm_settings.language.lower() == "cn":
Review Comment:
The hardcoded string comparison 'cn' doesn't match the Literal type definition which uses 'CN' (uppercase). This could cause the Chinese prompts to never be selected since LLMConfig defines language as Literal['EN', 'CN'].
```suggestion
if self.llm_settings.language == "CN":
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org