-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample05.py
More file actions
67 lines (54 loc) · 1.61 KB
/
Copy pathexample05.py
File metadata and controls
67 lines (54 loc) · 1.61 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""
Author: L. Saetta
Last modified: 2026-03-16
License: MIT
Description:
Example script that shows how to save the conversation platform side.
This one use conversation API. Using conversation API we can use streaming.
"""
from common import (
get_inference_client,
print_example_summary,
print_runtime_config,
print_streamed_output,
)
from config import MODEL_ID
TEMPERATURE = 0.0
def main() -> None:
"""Create a conversation and stream two context-linked turns."""
print_runtime_config()
print("")
print_example_summary("Create a conversation and stream two linked turns.")
print("")
client = get_inference_client()
# 1. create a conversation
conversation = client.conversations.create(metadata={"topic": "demo"})
print("Conversation ID: ", conversation.id)
print("")
request = "Tell me something about Giorgio Parisi?"
# 2. first request
response1 = client.responses.create(
model=MODEL_ID,
temperature=TEMPERATURE,
input=request,
# link to the conversation
conversation=conversation.id,
stream=True,
)
print("Request:", request)
print_streamed_output(response1)
print("")
# 3. second turn, chaining to the first turn
request = "Tell me something about his work on Spin glasses."
response2 = client.responses.create(
model=MODEL_ID,
temperature=TEMPERATURE,
input=request,
conversation=conversation.id,
stream=True,
)
print("\nRequest:", request)
print_streamed_output(response2)
print("")
if __name__ == "__main__":
main()