api_all / app.py
lalashechka's picture
Create app.py
1c0e6cc verified
raw
history blame
703 Bytes
from fastapi import FastAPI, Request
from pydantic import BaseModel
app = FastAPI()
# Определяем модель для запроса
class Message(BaseModel):
role: str
content: str
class RequestBody(BaseModel):
model: str
messages: list[Message]
temperature: float
top_p: float
max_tokens: int
@app.post("/api/v1")
async def generate_response(request_body: RequestBody):
# Извлечение и подготовка сообщений
input_text = "\n".join([f"{msg.role}: {msg.content}" for msg in request_body.messages])
response = input_text
# Возвращаем ответ в формате JSON
return {"response": response}