diff --git a/app/core/__pycache__/config.cpython-313.pyc b/app/core/__pycache__/config.cpython-313.pyc index eff13df..d387dd5 100644 Binary files a/app/core/__pycache__/config.cpython-313.pyc and b/app/core/__pycache__/config.cpython-313.pyc differ diff --git a/app/core/__pycache__/deepseek_client.cpython-313.pyc b/app/core/__pycache__/deepseek_client.cpython-313.pyc index 5d4ceee..5dac047 100644 Binary files a/app/core/__pycache__/deepseek_client.cpython-313.pyc and b/app/core/__pycache__/deepseek_client.cpython-313.pyc differ diff --git a/app/core/config.py b/app/core/config.py index 0c13826..b63258c 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -8,3 +8,7 @@ load_dotenv() OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", "") OPENAI_MODEL = os.getenv("OPENAI_MODEL", "gpt-3.5-turbo") OPENAI_API_BASE = os.getenv("OPENAI_API_BASE", "https://api.openai.com/v1") +DEEPSEEK_API_KEY = os.getenv("DEEPSEEK_API_KEY", "") +DEEPSEEK_API_BASE = os.getenv("DEEPSEEK_API_BASE", "https://api.deepseek.com/v1") +DEEPSEEK_MODEL = os.getenv("DEEPSEEK_MODEL", "deepseek-chat") + diff --git a/app/core/deepseek_client.py b/app/core/deepseek_client.py index 37223c8..cecf17e 100644 --- a/app/core/deepseek_client.py +++ b/app/core/deepseek_client.py @@ -1,21 +1,23 @@ # app/services/openai_service.py import openai +import os from openai import OpenAI -import openai -from app.core.config import OPENAI_API_KEY, OPENAI_MODEL, OPENAI_API_BASE +from openai import OpenAIError +from app.core.config import DEEPSEEK_API_BASE, DEEPSEEK_MODEL, DEEPSEEK_API_KEY -# Initialize OpenAI client with DeepSeek's API -DEEPSEEK_API_BASE = "https://api.deepseek.com/v1" -DEEPSEEK_MODEL = "deepseek-chat" +# Ensure the API key is properly set +if not DEEPSEEK_API_KEY: + raise ValueError("DEEPSEEK_API_KEY is not set in environment variables") -openai.api_key = OPENAI_API_KEY -openai.api_base = DEEPSEEK_API_BASE +# Initialize the client with proper configuration +client = OpenAI( + api_key=DEEPSEEK_API_KEY, + base_url=DEEPSEEK_API_BASE +) async def chat_with_openai(messages: list): - client = OpenAI( - api_key=openai.api_key, - base_url=DEEPSEEK_API_BASE - ) + if not messages: + raise ValueError("Messages list cannot be empty") try: response = client.chat.completions.create( @@ -26,10 +28,16 @@ async def chat_with_openai(messages: list): stream=False ) - if response.choices and len(response.choices) > 0: - return response.choices[0].message.content - return "No response from the model" + if not response.choices or not response.choices[0].message.content: + return "No response content from the model" + + return response.choices[0].message.content + except OpenAIError as e: + error_msg = f"DeepSeek API Error: {str(e)}" + print(error_msg) + raise Exception(error_msg) from e except Exception as e: - print(f"Error calling DeepSeek API: {str(e)}") - raise + error_msg = f"Unexpected error: {str(e)}" + print(error_msg) + raise Exception(error_msg) from e