You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hugegraph.apache.org by "MrJs133 (via GitHub)" <gi...@apache.org> on 2025/05/09 07:32:33 UTC
[PR] feat(llm):support auto llm review and fix test_api_connection [incubator-hugegraph-ai]
MrJs133 opened a new pull request, #222:
URL: https://github.com/apache/incubator-hugegraph-ai/pull/222
**Support for Automated LLM Testing**
**Core Idea**: The user provides a prompt; the candidate model generates a response based on the prompt, and a reviewer model evaluates the response and assigns scores.
As shown in the figure:

1. **Configure the reviewer model** (currently only OpenAI is supported)
2. **Configure the candidate models** (supports uploading a YAML file or entering text)
* A template YAML file has been uploaded (it cannot be used directly; keys and base URLs must be filled in)
* The textbox provides a template input format; each line represents the configuration for one LLM client, with elements separated by commas
3. Provide the **prompt**
4. Provide the **reference answer**
5. **Evaluation results** will be displayed in the **Output** box
--
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 auto llm review and fix test_api_connection [incubator-hugegraph-ai]
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #222:
URL: https://github.com/apache/incubator-hugegraph-ai/pull/222#discussion_r2081107559
##########
hugegraph-llm/src/hugegraph_llm/utils/other_tool_utils.py:
##########
@@ -0,0 +1,212 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import json
+import re
+import gradio as gr
+import yaml
+
+from hugegraph_llm.config import PromptConfig
+from hugegraph_llm.utils.log import log
+from hugegraph_llm.models.llms.ollama import OllamaClient
+from hugegraph_llm.models.llms.openai import OpenAIClient
+from hugegraph_llm.models.llms.qianfan import QianfanClient
+from hugegraph_llm.models.llms.litellm import LiteLLMClient
+def judge(answers, standard_answer, review_model_name, review_max_tokens, key, base):
+ try:
+ review_client = OpenAIClient(
+ api_key=key,
+ api_base=base,
+ model_name=review_model_name,
+ max_tokens=int(review_max_tokens)
+ )
+ review_prompt = PromptConfig.review_prompt.format(standard_answer=standard_answer)
+ for idx, (model_name, answer) in enumerate(answers.items(), start=1):
+ review_prompt += f"### {model_name}:\n{answer.strip()}\n\n"
+ log.debug("Review_prompt: %s", review_prompt)
+ response = review_client.generate(prompt=review_prompt)
+ log.debug("orig_review_response: %s", response)
+ match = re.search(r'```json\n(.*?)\n```', response, re.DOTALL)
+ if match:
+ response = match.group(1).strip()
+ reviews = json.loads(response)
+ return reviews
+ except Exception as e:
+ log.error("Review failed: %s", str(e))
+ reviews = {"error": f"Review error: {str(e)}"}
+
+def parse_llm_configurations(config_text: str):
+ configs = []
+ lines = config_text.strip().split("\n")
+ for i, line in enumerate(lines, 1):
+ fields = [x.strip() for x in line.split(",")]
+ if not fields:
+ continue
+ llm_type = fields[0]
+ try:
+ if llm_type == "openai":
+ # openai, model_name, api_key, api_base, max_tokens
+ model_name, api_key, api_base, max_tokens = fields[1:5]
+ configs.append({
+ "type": "openai",
+ "model_name": model_name,
+ "api_key": api_key,
+ "api_base": api_base,
+ "max_tokens": int(max_tokens),
+ })
+ elif llm_type == "qianfan_wenxin":
+ # qianfan_wenxin, model_name, api_key, secret_key
+ model_name, api_key, secret_key = fields[1:4]
+ configs.append({
+ "type": "qianfan_wenxin",
+ "model_name": model_name,
+ "api_key": api_key,
+ "secret_key": secret_key,
+ })
+ elif llm_type == "ollama/local":
+ # ollama/local, model_name, host, port, max_tokens
+ model_name, host, port, max_tokens = fields[1:5]
+ configs.append({
+ "type": "ollama/local",
+ "model_name": model_name,
+ "host": host,
+ "port": int(port),
+ "max_tokens": int(max_tokens),
+ })
+ elif llm_type == "litellm":
+ # litellm, model_name, api_key, api_base, max_tokens
+ model_name, api_key, api_base, max_tokens = fields[1:5]
+ configs.append({
+ "type": "litellm",
+ "model_name": model_name,
+ "api_key": api_key,
+ "api_base": api_base,
+ "max_tokens": int(max_tokens),
+ })
+ else:
+ raise ValueError(f"Unsupported llm type '{llm_type}' in line {i}")
+ except Exception as e:
+ raise ValueError(f"Error parsing line {i}: {line}\nDetails: {e}")
+ return configs
+
+def parse_llm_configurations_from_yaml(yaml_file_path: str):
+ configs = []
+ try:
+ with open(yaml_file_path, "r", encoding="utf-8") as f:
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
[Show more details](https://github.com/apache/incubator-hugegraph-ai/security/code-scanning/28)
--
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 auto llm review and fix test_api_connection [incubator-hugegraph-ai]
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #222:
URL: https://github.com/apache/incubator-hugegraph-ai/pull/222#discussion_r2081200461
##########
hugegraph-llm/src/hugegraph_llm/utils/other_tool_utils.py:
##########
@@ -0,0 +1,208 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import json
+import re
+import gradio as gr
+import yaml
+
+from hugegraph_llm.config import PromptConfig
+from hugegraph_llm.utils.log import log
+from hugegraph_llm.models.llms.ollama import OllamaClient
+from hugegraph_llm.models.llms.openai import OpenAIClient
+from hugegraph_llm.models.llms.qianfan import QianfanClient
+from hugegraph_llm.models.llms.litellm import LiteLLMClient
+def judge(answers, standard_answer, review_model_name, review_max_tokens, key, base):
+ try:
+ review_client = OpenAIClient(
+ api_key=key,
+ api_base=base,
+ model_name=review_model_name,
+ max_tokens=int(review_max_tokens)
+ )
+ review_prompt = PromptConfig.review_prompt.format(standard_answer=standard_answer)
+ for _, (model_name, answer) in enumerate(answers.items(), start=1):
+ review_prompt += f"### {model_name}:\n{answer.strip()}\n\n"
+ log.debug("Review_prompt: %s", review_prompt)
+ response = review_client.generate(prompt=review_prompt)
+ log.debug("orig_review_response: %s", response)
+ match = re.search(r'```json\n(.*?)\n```', response, re.DOTALL)
+ if match:
+ response = match.group(1).strip()
+ reviews = json.loads(response)
+ return reviews
+ except Exception as e: # pylint: disable=W0718
+ log.error("Review failed: %s", str(e))
+ reviews = {"error": f"Review error: {str(e)}"}
+ return reviews
+
+def parse_llm_configurations(config_text: str):
+ configs = []
+ lines = config_text.strip().split("\n")
+ for i, line in enumerate(lines, 1):
+ fields = [x.strip() for x in line.split(",")]
+ if not fields:
+ continue
+ llm_type = fields[0]
+ try:
+ if llm_type == "openai":
+ # openai, model_name, api_key, api_base, max_tokens
+ model_name, api_key, api_base, max_tokens = fields[1:5]
+ configs.append({
+ "type": "openai",
+ "model_name": model_name,
+ "api_key": api_key,
+ "api_base": api_base,
+ "max_tokens": int(max_tokens),
+ })
+ elif llm_type == "qianfan_wenxin":
+ # qianfan_wenxin, model_name, api_key, secret_key
+ model_name, api_key, secret_key = fields[1:4]
+ configs.append({
+ "type": "qianfan_wenxin",
+ "model_name": model_name,
+ "api_key": api_key,
+ "secret_key": secret_key,
+ })
+ elif llm_type == "ollama/local":
+ # ollama/local, model_name, host, port, max_tokens
+ model_name, host, port, max_tokens = fields[1:5]
+ configs.append({
+ "type": "ollama/local",
+ "model_name": model_name,
+ "host": host,
+ "port": int(port),
+ "max_tokens": int(max_tokens),
+ })
+ elif llm_type == "litellm":
+ # litellm, model_name, api_key, api_base, max_tokens
+ model_name, api_key, api_base, max_tokens = fields[1:5]
+ configs.append({
+ "type": "litellm",
+ "model_name": model_name,
+ "api_key": api_key,
+ "api_base": api_base,
+ "max_tokens": int(max_tokens),
+ })
+ else:
+ raise ValueError(f"Unsupported llm type '{llm_type}' in line {i}")
+ except Exception as e:
+ raise ValueError(f"Error parsing line {i}: {line}\nDetails: {e}") from e
+ return configs
+
+def parse_llm_configurations_from_yaml(yaml_file_path: str):
+ configs = []
+ with open(yaml_file_path, "r", encoding="utf-8") as f:
Review Comment:
## Uncontrolled data used in path expression
This path depends on a [user-provided value](1).
[Show more details](https://github.com/apache/incubator-hugegraph-ai/security/code-scanning/29)
--
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