forked from temporalio/samples-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflows.py
More file actions
33 lines (26 loc) · 1.02 KB
/
Copy pathworkflows.py
File metadata and controls
33 lines (26 loc) · 1.02 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
"""Basic one-shot LLM workflow with LangSmith tracing."""
from datetime import timedelta
from temporalio import workflow
with workflow.unsafe.imports_passed_through():
from langsmith import traceable
from langsmith_tracing.basic.activities import OpenAIRequest, call_openai
@workflow.defn
class BasicLLMWorkflow:
# Do not decorate @workflow.run with @traceable — it would violate
# replay safety and produce duplicate or orphaned traces. Instead,
# wrap an inner function.
@workflow.run
async def run(self, prompt: str) -> str:
@traceable(
name=f"Ask: {prompt[:60]}",
run_type="chain",
metadata={"workflow_id": workflow.info().workflow_id},
tags=["basic-llm"],
)
async def _run() -> str:
return await workflow.execute_activity(
call_openai,
OpenAIRequest(model="gpt-4o-mini", input=prompt),
start_to_close_timeout=timedelta(seconds=60),
)
return await _run()