mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-24 07:38:13 +02:00
Merge pull request #89 from R0m1k3/antigravity
feat: Introduce AI service for data extraction, including dynamic con…
This commit is contained in:
1 file changed
+15
-4
@@ -273,10 +273,17 @@ class AIService:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
response = await acompletion(**kwargs)
|
response = await acompletion(**kwargs)
|
||||||
|
content = response.choices[0].message.content
|
||||||
|
|
||||||
|
# If content is empty and we used response_format, try again without it
|
||||||
|
if not content and "response_format" in kwargs:
|
||||||
|
logger.warning(f"Model {config['model']} returned empty content with JSON mode. Retrying without response_format.")
|
||||||
|
del kwargs["response_format"]
|
||||||
|
response = await acompletion(**kwargs)
|
||||||
|
content = response.choices[0].message.content
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Check for BadRequestError (often due to unsupported parameters like response_format)
|
# Check for BadRequestError (often due to unsupported parameters like response_format)
|
||||||
# We check string representation or type if possible, but litellm errors can be tricky
|
|
||||||
# The user log showed: litellm.exceptions.BadRequestError
|
|
||||||
is_bad_request = "BadRequestError" in str(type(e).__name__) or "400" in str(e)
|
is_bad_request = "BadRequestError" in str(type(e).__name__) or "400" in str(e)
|
||||||
|
|
||||||
if is_bad_request and "response_format" in kwargs:
|
if is_bad_request and "response_format" in kwargs:
|
||||||
@@ -287,10 +294,10 @@ class AIService:
|
|||||||
del kwargs["response_format"]
|
del kwargs["response_format"]
|
||||||
# Retry without json mode
|
# Retry without json mode
|
||||||
response = await acompletion(**kwargs)
|
response = await acompletion(**kwargs)
|
||||||
|
content = response.choices[0].message.content
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
content = response.choices[0].message.content
|
|
||||||
return content or ""
|
return content or ""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -336,7 +343,11 @@ class AIService:
|
|||||||
# Call LLM
|
# Call LLM
|
||||||
response_text = await cls.call_llm(prompt, data_url, config)
|
response_text = await cls.call_llm(prompt, data_url, config)
|
||||||
|
|
||||||
logger.info(f"AI Response: {response_text[:200]}...")
|
logger.info(f"AI Response (Length: {len(response_text)}): {response_text[:500]!r}")
|
||||||
|
|
||||||
|
if not response_text or not response_text.strip():
|
||||||
|
logger.error("AI returned empty response")
|
||||||
|
return None
|
||||||
|
|
||||||
# Parse and validate response
|
# Parse and validate response
|
||||||
repair_used = False
|
repair_used = False
|
||||||
|
|||||||
Reference in new issue
Block a user