-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathruntime-client-example.py
More file actions
60 lines (49 loc) · 1.78 KB
/
runtime-client-example.py
File metadata and controls
60 lines (49 loc) · 1.78 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
import os
import asyncio
import json
from pydantic import BaseModel
from src.runtimeuse_client import (
AssistantMessageInterface,
ErrorMessageInterface,
RuntimeUseClient,
InvocationMessage,
ResultMessageInterface,
CommandInterface,
)
class Answer(BaseModel):
answer: str
async def main():
client = RuntimeUseClient(ws_url="ws://localhost:8080")
invocation = InvocationMessage(
message_type="invocation_message",
source_id="my-source",
model="gpt-5.4",
pre_agent_invocation_commands=[
CommandInterface(
command="echo 'Hello, world!'",
cwd=os.getcwd(),
env={},
)
],
system_prompt="You are a helpful assistant.",
user_prompt="Search the web to find the answer to the question: 'What is the population of France grouped by region? Once you find the answer, run a python script to compute the sum of the total population of France.'",
output_format_json_schema_str=json.dumps(
{"type": "json_schema", "schema": Answer.model_json_schema()}
),
secrets_to_redact=[],
)
async def on_result(result: ResultMessageInterface):
print(f"Result: {result.structured_output}")
async def on_assistant_message(message: AssistantMessageInterface):
print(f"Assistant message: {message.text_blocks}")
async def on_error_message(message: ErrorMessageInterface):
print(f"Error message: {message.error}")
await client.invoke(
invocation=invocation,
on_result_message=on_result,
result_message_cls=ResultMessageInterface,
on_assistant_message=on_assistant_message,
on_error_message=on_error_message,
)
if __name__ == "__main__":
asyncio.run(main())