Skip to content

Commit

Permalink
fix response typing format
Browse files Browse the repository at this point in the history
  • Loading branch information
bassner committed Aug 19, 2024
1 parent 408b9d4 commit 66b5c52
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/llm/external/openai_chat.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import logging
import time
import traceback
from datetime import datetime
from typing import Literal, Any

from openai import OpenAI
from openai.lib.azure import AzureOpenAI
from openai.types.chat import ChatCompletionMessage, ChatCompletionMessageParam
from openai.types.chat.completion_create_params import ResponseFormat
from openai.types.shared_params import ResponseFormatJSONObject

from ...common.message_converters import map_str_to_role, map_role_to_str
from app.domain.data.text_message_content_dto import TextMessageContentDTO
Expand Down Expand Up @@ -93,7 +95,7 @@ def chat(
messages=convert_to_open_ai_messages(messages),
temperature=arguments.temperature,
max_tokens=arguments.max_tokens,
response_format=ResponseFormat(type="json_object"),
response_format=ResponseFormatJSONObject(type="json_object"),
)
else:
response = self._client.chat.completions.create(
Expand All @@ -106,6 +108,7 @@ def chat(
except Exception as e:
wait_time = initial_delay * (backoff_factor**attempt)
logging.warning(f"Exception on attempt {attempt + 1}: {e}")
traceback.print_exc()
logging.info(f"Retrying in {wait_time} seconds...")
time.sleep(wait_time)
logging.error("Failed to interpret image after several attempts.")
Expand Down

0 comments on commit 66b5c52

Please sign in to comment.