-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
76 lines (61 loc) · 2.12 KB
/
example.py
File metadata and controls
76 lines (61 loc) · 2.12 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
68
69
70
71
72
73
74
75
76
import asyncio
# OLD IMPORTS
# from client.ds_cli import DeepSeekClient, DeepSeekFlow
from client import DeepSeekClient, DeepSeekFlow
async def single_client_example():
"""
Example 1: Single DeepSeekClient usage.
Classic flow with one client, one session.
"""
# OLD implementation
# client = DeepSeekClient(**CONFIG)
# try:
# await client.start_session(headless=True)
# response = await client('Hi, who are you?')
# print("Single client response:\n", response)
# except Exception as e:
# print("Error in single client example:", e)
# NEW implementation using DeepSeekFlow u ca use both versions
async with DeepSeekClient() as client:
flow = DeepSeekFlow(client=client)
response = await flow.run_query("Who are u?")
print(response)
async def multi_agent_example():
"""
Example 2: Multi-agent usage with a single shared browser.
Each agent has its own BrowserContext and Page for isolated queries.
"""
# Start one browser instance
playwright, browser = await DeepSeekClient.create_browser(headless=True)
# Create multiple clients (agents) sharing the same browser
agents = [
DeepSeekClient(external_browser=browser)
for _ in range(3) # Number of agents
]
# Start a session for each agent
for agent in agents:
await agent.start_session()
# Define queries for each agent
queries = [
"Hi, who are you?",
"Tell me a joke",
"Explain basic algebra briefly"
]
# Run queries concurrently
results = await asyncio.gather(*[
DeepSeekFlow(client=agent).run_query(query)
for agent, query in zip(agents, queries)
])
# Print each agent's result
for i, result in enumerate(results):
print(f"Agent {i+1} response:\n{result}\n{'-'*50}")
# Close the browser and stop Playwright
await browser.close()
await playwright.stop()
async def main():
# Run single client example
await single_client_example()
# Run multi-agent example
# await multi_agent_example()
if __name__ == '__main__':
asyncio.run(main())