Refactor agent API structure and add core functionality with FastAPI integration
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
from dotenv import load_dotenv
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
load_dotenv(Path(__file__).resolve().parent.parent.parent / ".env")
|
||||
|
||||
DEEPSEEK_API_KEY = os.getenv("DEEPSEEK_API_KEY")
|
||||
@@ -0,0 +1,7 @@
|
||||
from openai import OpenAI
|
||||
from .config import DEEPSEEK_API_KEY
|
||||
|
||||
client = OpenAI(
|
||||
api_key=DEEPSEEK_API_KEY,
|
||||
base_url="https://api.deepseek.com"
|
||||
)
|
||||
@@ -0,0 +1,32 @@
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
|
||||
from .core.llm import client
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
# ---- request model ----
|
||||
class ChatRequest(BaseModel):
|
||||
message: str
|
||||
|
||||
|
||||
# ---- basic health check ----
|
||||
@app.get("/")
|
||||
def root():
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
# ---- test LLM endpoint ----
|
||||
@app.post("/chat")
|
||||
def chat(req: ChatRequest):
|
||||
response = client.chat.completions.create(
|
||||
model="deepseek-chat",
|
||||
messages=[
|
||||
{"role": "user", "content": req.message}
|
||||
]
|
||||
)
|
||||
|
||||
return {
|
||||
"response": response.choices[0].message.content
|
||||
}
|
||||
Reference in New Issue
Block a user