bugfix
This commit is contained in:
19
helpers.py
19
helpers.py
@@ -126,7 +126,7 @@ def retry_on_failure(func):
|
|||||||
decorator_logger.warning(f"Wiederhole Versuch {attempt + 1}/{max_retries_config} fuer '{effective_func_name}'...")
|
decorator_logger.warning(f"Wiederhole Versuch {attempt + 1}/{max_retries_config} fuer '{effective_func_name}'...")
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
|
|
||||||
except (gspread.exceptions.SpreadsheetNotFound, AuthenticationError, ValueError) as e:
|
except (gspread.exceptions.SpreadsheetNotFound, AuthenticationError, ValueError, InvalidRequestError) as e:
|
||||||
decorator_logger.critical(f"❌ ENDGUELTIGER FEHLER bei '{effective_func_name}': Permanentes Problem erkannt. {type(e).__name__} - {str(e)[:150]}...")
|
decorator_logger.critical(f"❌ ENDGUELTIGER FEHLER bei '{effective_func_name}': Permanentes Problem erkannt. {type(e).__name__} - {str(e)[:150]}...")
|
||||||
decorator_logger.exception("Details:")
|
decorator_logger.exception("Details:")
|
||||||
raise e
|
raise e
|
||||||
@@ -769,21 +769,24 @@ def call_openai_chat(prompt, temperature=0.3, model=None):
|
|||||||
current_model = model if model else getattr(Config, 'TOKEN_MODEL', 'gpt-3.5-turbo')
|
current_model = model if model else getattr(Config, 'TOKEN_MODEL', 'gpt-3.5-turbo')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Optional: Token-Zählung für Debugging
|
# NEU: OpenAI v1.x Client-Instanziierung
|
||||||
# prompt_tokens = token_count(prompt, model=current_model)
|
# Es ist Best Practice, einen Client zu erstellen, anstatt die globalen Methoden zu verwenden.
|
||||||
# logger.debug(f"Sende Prompt an OpenAI ({current_model}, geschaetzt {prompt_tokens} Tokens)...")
|
# Der API-Schlüssel wird automatisch aus der Umgebungsvariable oder der Konfiguration gelesen.
|
||||||
|
client = openai.OpenAI(api_key=Config.API_KEYS.get('openai'))
|
||||||
|
|
||||||
response = openai.ChatCompletion.create(
|
# logger.debug(f"Sende Prompt an OpenAI ({current_model})...")
|
||||||
|
|
||||||
|
response = client.chat.completions.create(
|
||||||
model=current_model,
|
model=current_model,
|
||||||
messages=[{"role": "user", "content": prompt}],
|
messages=[{"role": "user", "content": prompt}],
|
||||||
temperature=temperature
|
temperature=temperature
|
||||||
)
|
)
|
||||||
|
|
||||||
if not response or not hasattr(response, 'choices') or not response.choices:
|
if not response or not response.choices:
|
||||||
logger.error(f"OpenAI Call erfolgreich, aber keine Choices in der Antwort erhalten. Response: {str(response)[:200]}...")
|
logger.error(f"OpenAI Call erfolgreich, aber keine Choices in der Antwort erhalten. Response: {str(response)[:200]}...")
|
||||||
raise openai.error.APIError("Keine Choices in OpenAI Antwort erhalten.")
|
raise APIError("Keine Choices in OpenAI Antwort erhalten.", request=None, body=None)
|
||||||
|
|
||||||
result = response.choices[0].message.content.strip() if hasattr(response.choices[0], 'message') and hasattr(response.choices[0].message, 'content') else ""
|
result = response.choices[0].message.content.strip() if response.choices[0].message and response.choices[0].message.content else ""
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
logger.warning(f"OpenAI Call erfolgreich, erhielt aber leeren Inhalt in der Antwort. Prompt Anfang: {prompt[:100]}...")
|
logger.warning(f"OpenAI Call erfolgreich, erhielt aber leeren Inhalt in der Antwort. Prompt Anfang: {prompt[:100]}...")
|
||||||
|
|||||||
Reference in New Issue
Block a user