forked from temporalio/samples-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.py
More file actions
47 lines (34 loc) · 1.31 KB
/
Copy pathworker.py
File metadata and controls
47 lines (34 loc) · 1.31 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
"""Worker for the basic LangSmith sample."""
import asyncio
import logging
import sys
from temporalio.client import Client
from temporalio.contrib.langsmith import LangSmithPlugin
from temporalio.envconfig import ClientConfig
from temporalio.worker import Worker
from langsmith_tracing.basic.activities import call_openai
from langsmith_tracing.basic.workflows import BasicLLMWorkflow
async def main():
logging.basicConfig(level=logging.INFO)
# add_temporal_runs=True creates LangSmith runs for each Temporal
# workflow/activity execution. False (default) only propagates context.
add_temporal_runs = "--add-temporal-runs" in sys.argv
config = ClientConfig.load_client_connect_config()
config.setdefault("target_host", "localhost:7233")
plugin = LangSmithPlugin(
project_name="langsmith-basic",
add_temporal_runs=add_temporal_runs,
)
client = await Client.connect(**config)
worker = Worker(
client,
task_queue="langsmith-basic-task-queue",
workflows=[BasicLLMWorkflow],
activities=[call_openai],
plugins=[plugin],
)
label = "with" if add_temporal_runs else "without"
print(f"Worker started ({label} Temporal runs in traces), ctrl+c to exit")
await worker.run()
if __name__ == "__main__":
asyncio.run(main())