37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
from fastapi import FastAPI
|
|
from openai import OpenAI
|
|
import os
|
|
|
|
app = FastAPI()
|
|
|
|
# DeepSeek OpenAI-compatible endpoint
|
|
client = OpenAI(
|
|
api_key=os.getenv("DEEPSEEK_API_KEY"),
|
|
base_url="https://api.deepseek.com"
|
|
)
|
|
|
|
@app.post("/v1/chat/completions")
|
|
async def chat(data: dict):
|
|
|
|
messages = data["messages"]
|
|
|
|
repo_context = """
|
|
This assistant has access to the repository.
|
|
Help the user understand the codebase.
|
|
This repo is building an chatbot, currently still in early stages. The main files are:
|
|
- app.py: The main FastAPI application that defines the API endpoints and integrates with the Deep seek API.
|
|
- agent.py: Contains the logic for the chatbot agent, including how it processes messages and generates responses.
|
|
"""
|
|
|
|
messages.insert(0, {
|
|
"role": "system",
|
|
"content": repo_context
|
|
})
|
|
|
|
response = client.chat.completions.create(
|
|
model="deepseek-v4-flash",
|
|
messages=messages,
|
|
temperature=0.3
|
|
)
|
|
|
|
return response.model_dump() |