leafspark commited on
Commit
9945c15
·
verified ·
1 Parent(s): de3da4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -1,7 +1,11 @@
1
  import gradio as gr
2
  import json
3
 
4
- def chat_completions(message):
 
 
 
 
5
  response = {
6
  "id": "chatcmpl-123",
7
  "object": "chat.completion",
@@ -10,7 +14,7 @@ def chat_completions(message):
10
  "index": 0,
11
  "message": {
12
  "role": "assistant",
13
- "content": "This is a placeholder response. The real model isn't loaded yet."
14
  },
15
  "finish_reason": "stop"
16
  }],
@@ -24,11 +28,15 @@ def chat_completions(message):
24
 
25
  demo = gr.Interface(
26
  fn=chat_completions,
27
- inputs="json",
28
- outputs="json",
29
  title="Chat Completions API",
30
  description="Send a POST request to /v1/chat/completions"
31
  )
32
 
33
  if __name__ == "__main__":
34
- demo.launch()
 
 
 
 
 
1
  import gradio as gr
2
  import json
3
 
4
+ def chat_completions(request: gr.Request):
5
+ # Parse the incoming JSON request
6
+ data = request.json
7
+
8
+ # Create a placeholder response
9
  response = {
10
  "id": "chatcmpl-123",
11
  "object": "chat.completion",
 
14
  "index": 0,
15
  "message": {
16
  "role": "assistant",
17
+ "content": f"Placeholder response. Received: {data['messages'][-1]['content']}"
18
  },
19
  "finish_reason": "stop"
20
  }],
 
28
 
29
  demo = gr.Interface(
30
  fn=chat_completions,
31
+ inputs=None,
32
+ outputs=None,
33
  title="Chat Completions API",
34
  description="Send a POST request to /v1/chat/completions"
35
  )
36
 
37
  if __name__ == "__main__":
38
+ demo.launch()
39
+
40
+ demo.queue()
41
+ demo.launch()
42
+ api = gr.mount_gradio_app(demo, "/v1/chat/completions", api_name="chat_completions")