forked from temporalio/samples-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstarter.py
More file actions
52 lines (40 loc) · 1.33 KB
/
Copy pathstarter.py
File metadata and controls
52 lines (40 loc) · 1.33 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
"""Starter for the basic LangSmith sample."""
import asyncio
import sys
from langsmith import traceable
from temporalio.client import Client
from temporalio.contrib.langsmith import LangSmithPlugin
from temporalio.envconfig import ClientConfig
from langsmith_tracing.basic.workflows import BasicLLMWorkflow
PROJECT_NAME = "langsmith-basic"
@traceable(
name="Basic LLM Request",
run_type="chain",
# CRITICAL: Client-side @traceable runs outside the LangSmithPlugin's scope.
# Make sure client-side traces use the same project_name as what is given to
# the plugin.
project_name=PROJECT_NAME,
tags=["client-side"],
)
async def main() -> str:
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=PROJECT_NAME,
add_temporal_runs=add_temporal_runs,
)
client = await Client.connect(
**config,
plugins=[plugin],
)
result = await client.execute_workflow(
BasicLLMWorkflow.run,
"What is Temporal?",
id="langsmith-basic-workflow-id",
task_queue="langsmith-basic-task-queue",
)
print(f"Workflow result: {result}")
return result
if __name__ == "__main__":
asyncio.run(main())