-
Notifications
You must be signed in to change notification settings - Fork 349
Expand file tree
/
Copy path04_server_http.py
More file actions
38 lines (27 loc) · 1.16 KB
/
Copy path04_server_http.py
File metadata and controls
38 lines (27 loc) · 1.16 KB
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
35
36
37
38
"""Example 4 — talk to the server over plain HTTP (OpenAI-compatible).
Use this when the caller is NOT this Python process: another language, a tool,
or a different machine. The server speaks the OpenAI Chat Completions shape.
First, start the server in another terminal:
python app.py
Then run this from the project root:
python examples/04_server_http.py
Each response includes Copilot's `conversation_id` as an extra field; send it
back to continue the same thread.
"""
import requests
URL = "http://localhost:8000/v1/chat/completions"
# Turn 1 — new conversation.
first = requests.post(URL, json={
"model": "copilot",
"messages": [{"role": "user", "content": "My name is Ada. Remember it."}],
}).json()
print("Copilot:", first["choices"][0]["message"]["content"])
cid = first["conversation_id"]
print("conversation_id:", cid)
# Turn 2 — continue by sending the conversation_id back in the body.
second = requests.post(URL, json={
"model": "copilot",
"conversation_id": cid,
"messages": [{"role": "user", "content": "What's my name? Just the name."}],
}).json()
print("Copilot:", second["choices"][0]["message"]["content"]) # -> recalls "Ada"