Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| from huggingface_hub import InferenceClient | |
| import os | |
| app = FastAPI() | |
| client = InferenceClient( | |
| api_key=os.getenv("HF_TOKEN") | |
| ) | |
| class ChatRequest(BaseModel): | |
| model: str | |
| messages: list | |
| def models(): | |
| return { | |
| "data": [ | |
| { | |
| "id": "Qwen/Qwen2.5-Coder-14B-Instruct", | |
| "object": "model" | |
| } | |
| ] | |
| } | |
| async def chat(req: ChatRequest): | |
| response = client.chat.completions.create( | |
| model=req.model, | |
| messages=req.messages, | |
| max_tokens=2048 | |
| ) | |
| return response |