diff --git a/app/__pycache__/main.cpython-313.pyc b/app/__pycache__/main.cpython-313.pyc index 60050dd..61185d5 100644 Binary files a/app/__pycache__/main.cpython-313.pyc and b/app/__pycache__/main.cpython-313.pyc differ diff --git a/app/api/v1/voice.py b/app/api/v1/voice.py new file mode 100644 index 0000000..67bdede --- /dev/null +++ b/app/api/v1/voice.py @@ -0,0 +1,10 @@ +from fastapi import APIRouter +from app.models.voice import VoiceRequest, VoiceResponse +from app.services.voice import generate_voice + +router = APIRouter() + +@router.post("/", response_model=VoiceResponse) +async def voice(request: VoiceRequest): + voice = await generate_voice(request.text) + return VoiceResponse(voice=voice) diff --git a/app/core/__pycache__/deepseek_client.cpython-313.pyc b/app/core/__pycache__/deepseek_client.cpython-313.pyc index 27ebb7c..5d4ceee 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/deepseek_client.py b/app/core/deepseek_client.py index 1c25d5e..37223c8 100644 --- a/app/core/deepseek_client.py +++ b/app/core/deepseek_client.py @@ -1,27 +1,35 @@ # app/services/openai_service.py import openai from openai import OpenAI -from app.core.config import OPENAI_API_KEY, OPENAI_MODEL -from app.core.config import OPENAI_API_BASE +import openai +from app.core.config import OPENAI_API_KEY, OPENAI_MODEL, OPENAI_API_BASE + +# Initialize OpenAI client with DeepSeek's API +DEEPSEEK_API_BASE = "https://api.deepseek.com/v1" +DEEPSEEK_MODEL = "deepseek-chat" -# Set OpenAI API key from the environment openai.api_key = OPENAI_API_KEY -openai.api_base = OPENAI_API_BASE - -print(openai.api_key) -print(OPENAI_MODEL) -print(OPENAI_API_BASE) +openai.api_base = DEEPSEEK_API_BASE async def chat_with_openai(messages: list): - # Use the model from environment variable or fallback to default - model = OPENAI_MODEL - client = OpenAI(api_key=openai.api_key, base_url=openai.api_base) - - response = client.chat.completions.create( - model="deepseek-chat", # Or the model you want - messages=messages, # Update this according to the new API syntax - max_tokens=100, # Example parameter - stream=False + client = OpenAI( + api_key=openai.api_key, + base_url=DEEPSEEK_API_BASE ) - - return response.choices[0].message.content + + try: + response = client.chat.completions.create( + model=DEEPSEEK_MODEL, + messages=messages, + max_tokens=1000, + temperature=0.7, + stream=False + ) + + if response.choices and len(response.choices) > 0: + return response.choices[0].message.content + return "No response from the model" + + except Exception as e: + print(f"Error calling DeepSeek API: {str(e)}") + raise diff --git a/app/main.py b/app/main.py index 4786958..a4ac1a4 100644 --- a/app/main.py +++ b/app/main.py @@ -1,7 +1,9 @@ from fastapi import FastAPI from app.api.v1 import translate +# from app.api.v1 import voice app = FastAPI() # Include your routes app.include_router(translate.router, prefix="/api/v1/translate", tags=["translate"]) +# app.include_router(voice.router, prefix="/api/v1/voice", tags=["voice"]) \ No newline at end of file diff --git a/app/models/voice.py b/app/models/voice.py new file mode 100644 index 0000000..0efb19d --- /dev/null +++ b/app/models/voice.py @@ -0,0 +1,8 @@ +from pydantic import BaseModel + + +class VoiceRequest(BaseModel): + text: str + +class VoiceResponse(BaseModel): + voice: str