fix(llm): improve rag demo error handling#335
Merged
imbajin merged 8 commits intoMay 20, 2026
Conversation
Change-Id: I1658c1a7aefe353f48be4d48c7d4425aded13a3d
Change-Id: I275a618f6b6a43448c40d91fc6e4667084d26f4f
imbajin
reviewed
May 19, 2026
Change-Id: I65b37b72baea21e2cf2cf2c471ff14c56869520e
Comment on lines
+25
to
+38
| def test_response_validation_raises_http_error_with_numeric_status_body(): | ||
| response = Mock(spec=requests.Response) | ||
| response.status_code = 400 | ||
| response.text = '{"status":400,"message":"bad gremlin"}' | ||
| response.content = response.text.encode("utf-8") | ||
| response.json.return_value = {"status": 400, "message": "bad gremlin"} | ||
| response.request = Mock() | ||
| response.request.body = "g.V2()" | ||
| response.raise_for_status.side_effect = requests.exceptions.HTTPError("400 Client Error") | ||
|
|
||
| validator = ResponseValidation() | ||
|
|
||
| with pytest.raises(Exception, match="bad gremlin"): | ||
| validator(response, "POST", "/gremlin") |
Comment on lines
+63
to
+66
| except RequestException as e: | ||
| raise ValueError(f"Failed to connect HugeGraph to get schema '{self.graph_name}': {e}") from e | ||
| if not schema["vertexlabels"] and not schema["edgelabels"]: | ||
| raise Exception(f"Can not get {self.graph_name}'s schema from HugeGraph!") | ||
| raise ValueError(f"Can not get {self.graph_name}'s schema from HugeGraph!") |
Comment on lines
74
to
108
| log.info("Token usage: %s", response.usage) | ||
| return response.choices[0].message.content | ||
| except (RateLimitError, BudgetExceededError, APIError) as e: | ||
| log.error("Error in LiteLLM call: %s", e) | ||
| return f"Error: {str(e)}" | ||
| raise | ||
|
|
||
| @retry( | ||
| stop=stop_after_attempt(2), | ||
| wait=wait_exponential(multiplier=1, min=2, max=5), | ||
| retry=retry_if_exception_type((RateLimitError, BudgetExceededError, APIError)), | ||
| ) | ||
| async def agenerate( | ||
| self, | ||
| messages: Optional[List[Dict[str, Any]]] = None, | ||
| prompt: Optional[str] = None, | ||
| ) -> str: | ||
| """Generate a response to the query messages/prompt asynchronously.""" | ||
| if messages is None: | ||
| assert prompt is not None, "Messages or prompt must be provided." | ||
| messages = [{"role": "user", "content": prompt}] | ||
| try: | ||
| response = await acompletion( | ||
| model=self.model, | ||
| messages=messages, | ||
| temperature=self.temperature, | ||
| max_tokens=self.max_tokens, | ||
| api_key=self.api_key, | ||
| base_url=self.api_base, | ||
| ) | ||
| log.info("Token usage: %s", response.usage) | ||
| return response.choices[0].message.content | ||
| except (RateLimitError, BudgetExceededError, APIError) as e: | ||
| log.error("Error in async LiteLLM call: %s", e) | ||
| return f"Error: {str(e)}" | ||
| raise | ||
|
|
imbajin
reviewed
May 20, 2026
Member
imbajin
left a comment
There was a problem hiding this comment.
本轮整体方向正确,但 base_node 的 catch-all 与 schema_build 的 raise 相互抵消、ollama/litellm/openai 的契约改动缺少测试覆盖,建议先收敛错误处理边界并补齐回归测试再合入。
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Change-Id: I939ca3a2df3ecc55471f9b98155b5ab03fa43d03
Change-Id: Ib8bb730fb9c28e4b3e0a05e72d531544d0f623a9
imbajin
reviewed
May 20, 2026
Change-Id: I815753ca0350e6b5f734937973eca956d9ef422a
Contributor
Author
|
done |
imbajin
approved these changes
May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
HG_DEV_RELOADinstead of enabling reload by default.embed(input=...)API and validate malformed embedding responses.Change-Id: I1658c1a7aefe353f48be4d48c7d4425aded13a3d