omarsol commited on
Commit
2e97e50
·
1 Parent(s): a620b08

Add Gradio API documentation for chat endpoint and usage examples

Browse files
Files changed (1) hide show
  1. README.md +74 -0
README.md CHANGED
@@ -40,6 +40,80 @@ The Gradio demo is deployed on Hugging Face Spaces at: [AI Tutor Chatbot on Hugg
40
 
41
  Starts the Gradio AI Tutor interface.
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  ### Rebuild Local Retrieval Index
44
 
45
  After updating the JSONL corpus, rebuild the local Chroma index with:
 
40
 
41
  Starts the Gradio AI Tutor interface.
42
 
43
+ ### Gradio API
44
+
45
+ The chat endpoint is exposed as `chat`, so the API flow is:
46
+
47
+ ```bash
48
+ POST /gradio_api/call/chat
49
+ GET /gradio_api/call/chat/{event_id}
50
+ ```
51
+
52
+ The `POST` body must send `data` in this exact order:
53
+
54
+ 1. User message: string
55
+ 2. History: array
56
+ 3. Sources: array of source labels exactly as shown in the UI
57
+ 4. Model: `provider:model` string
58
+ 5. Show Gemini thoughts: boolean
59
+ 6. Thread ID: string, empty for a new conversation
60
+
61
+ Example first turn:
62
+
63
+ ```bash
64
+ curl -s http://127.0.0.1:7860/gradio_api/call/chat \
65
+ -H 'Content-Type: application/json' \
66
+ -d '{
67
+ "data": [
68
+ "What is LoRA?",
69
+ [],
70
+ ["PEFT Docs", "Transformers Docs"],
71
+ "openai:gpt-4o-mini",
72
+ false,
73
+ ""
74
+ ]
75
+ }'
76
+ ```
77
+
78
+ That returns an `event_id`. Open the server-sent event stream with:
79
+
80
+ ```bash
81
+ curl -N http://127.0.0.1:7860/gradio_api/call/chat/<event_id>
82
+ ```
83
+
84
+ The streamed payloads look like this:
85
+
86
+ ```json
87
+ ["Partial assistant text", null, "thread-id"]
88
+ ```
89
+
90
+ - `data[0]`: current streamed assistant text
91
+ - `data[1]`: Gradio's hidden state placeholder, ignore this
92
+ - `data[2]`: `thread_id` to reuse on the next turn
93
+
94
+ Example follow-up turn on the same conversation:
95
+
96
+ ```bash
97
+ curl -s http://127.0.0.1:7860/gradio_api/call/chat \
98
+ -H 'Content-Type: application/json' \
99
+ -d '{
100
+ "data": [
101
+ "How is it different from adapters?",
102
+ [],
103
+ ["PEFT Docs", "Transformers Docs"],
104
+ "openai:gpt-4o-mini",
105
+ false,
106
+ "thread-id-from-previous-response"
107
+ ]
108
+ }'
109
+ ```
110
+
111
+ Notes:
112
+
113
+ - API clients should usually send `[]` for history and continue the conversation with `thread_id`.
114
+ - The source filter is request-scoped, so you can keep the same `thread_id` while changing sources between turns.
115
+ - Sending an empty `thread_id` starts a new backend conversation.
116
+
117
  ### Rebuild Local Retrieval Index
118
 
119
  After updating the JSONL corpus, rebuild the local Chroma index with: