mirror of
https://github.com/R0m1k3/Priceflow.git
synced 2026-10-22 22:58:11 +02:00
Merge pull request #262 from R0m1k3/antigravity
feat: Add core AI service for LLM interaction, configuration, respons…
This commit is contained in:
1 file changed
+12
-2
@@ -6,9 +6,11 @@ import time
|
|||||||
from typing import Any, TypedDict
|
from typing import Any, TypedDict
|
||||||
|
|
||||||
from litellm import acompletion
|
from litellm import acompletion
|
||||||
|
import litellm
|
||||||
from pydantic import ValidationError
|
from pydantic import ValidationError
|
||||||
from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_exponential
|
from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_exponential
|
||||||
|
|
||||||
|
|
||||||
from app import models
|
from app import models
|
||||||
from app.ai_schema import (
|
from app.ai_schema import (
|
||||||
PROMPT_VERSION,
|
PROMPT_VERSION,
|
||||||
@@ -21,6 +23,11 @@ from app.database import SessionLocal
|
|||||||
from app.utils.image import encode_image
|
from app.utils.image import encode_image
|
||||||
from app.utils.text import clean_text
|
from app.utils.text import clean_text
|
||||||
|
|
||||||
|
# Suppress Litellm verbose logging to avoid Pydantic serialization warnings
|
||||||
|
litellm.suppress_debug_info = True
|
||||||
|
litellm.set_verbose = False
|
||||||
|
litellm.drop_params = True
|
||||||
|
|
||||||
# Default configuration (can be overridden by DB settings)
|
# Default configuration (can be overridden by DB settings)
|
||||||
DEFAULT_PROVIDER = "ollama"
|
DEFAULT_PROVIDER = "ollama"
|
||||||
DEFAULT_MODEL = "google/gemini-flash-1.5"
|
DEFAULT_MODEL = "google/gemini-flash-1.5"
|
||||||
@@ -283,7 +290,9 @@ class AIService:
|
|||||||
|
|
||||||
# If content is empty and we used response_format, try again without it
|
# If content is empty and we used response_format, try again without it
|
||||||
if not content and "response_format" in kwargs:
|
if not content and "response_format" in kwargs:
|
||||||
logger.warning(f"Model {config['model']} returned empty content with JSON mode. Retrying without response_format.")
|
logger.warning(
|
||||||
|
f"Model {config['model']} returned empty content with JSON mode. Retrying without response_format."
|
||||||
|
)
|
||||||
del kwargs["response_format"]
|
del kwargs["response_format"]
|
||||||
response = await acompletion(**kwargs)
|
response = await acompletion(**kwargs)
|
||||||
content = response.choices[0].message.content
|
content = response.choices[0].message.content
|
||||||
@@ -348,7 +357,8 @@ class AIService:
|
|||||||
|
|
||||||
# Extract all potential prices from text for debugging
|
# Extract all potential prices from text for debugging
|
||||||
import re
|
import re
|
||||||
price_patterns = re.findall(r'\d+[,\.]\d{2}\s*€', cleaned_text)
|
|
||||||
|
price_patterns = re.findall(r"\d+[,\.]\d{2}\s*€", cleaned_text)
|
||||||
if price_patterns:
|
if price_patterns:
|
||||||
logger.info(f"Prices found in text: {price_patterns[:10]}") # First 10 prices
|
logger.info(f"Prices found in text: {price_patterns[:10]}") # First 10 prices
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in new issue
Block a user