Spaces:
Sleeping
Sleeping
import gradio as gr | |
import json | |
def chat_completions(request: gr.Request): | |
data = request.json | |
response = { | |
"id": "chatcmpl-123", | |
"object": "chat.completion", | |
"created": 1677652288, | |
"choices": [{ | |
"index": 0, | |
"message": { | |
"role": "assistant", | |
"content": f"Placeholder response. Received: {data['messages'][-1]['content']}" | |
}, | |
"finish_reason": "stop" | |
}], | |
"usage": { | |
"prompt_tokens": 9, | |
"completion_tokens": 12, | |
"total_tokens": 21 | |
} | |
} | |
return json.dumps(response) | |
with gr.Blocks() as demo: | |
gr.Markdown("# Chat Completions API") | |
gr.Markdown("Send a POST request to /v1/chat/completions") | |
demo.queue() | |
demo.launch() | |
app = gr.mount_gradio_app(demo, "/v1/chat/completions", chat_completions) | |