Spaces:
Sleeping
Sleeping
File size: 884 Bytes
da0fdaf de3da4c 9945c15 de3da4c 9945c15 de3da4c 40e9cae 9945c15 40e9cae |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
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)
|