30 lines
843 B
Python
30 lines
843 B
Python
# Please install OpenAI SDK first: `pip3 install openai`
|
|
import os
|
|
from openai import OpenAI
|
|
from dotenv import load_dotenv
|
|
load_dotenv()
|
|
from fastapi import FastAPI
|
|
|
|
app=FastAPI()
|
|
|
|
@app.get('/')
|
|
def call_llm(user_input,model="deepseek-v4-pro"):
|
|
client = OpenAI(
|
|
api_key=os.environ.get('DEEPSEEK_API_KEY'),
|
|
base_url="https://api.deepseek.com")
|
|
|
|
response = client.chat.completions.create(
|
|
model=model,
|
|
messages=[
|
|
{"role": "system", "content": "You are a helpful assistant"},
|
|
{"role": "user", "content": user_input},
|
|
],
|
|
stream=False,
|
|
reasoning_effort="high",
|
|
extra_body={"thinking": {"type": "enabled"}}
|
|
)
|
|
return response.choices[0].message.content
|
|
|
|
if __name__ =='__main__':
|
|
import uvicorn
|
|
uvicorn.run(app,host='0.0.0.0',port=8001) |