-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathexample.py
More file actions
48 lines (40 loc) · 1.8 KB
/
example.py
File metadata and controls
48 lines (40 loc) · 1.8 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
"""Simple Example."""
from portia.config import Config, LogLevel
from portia.execution_context import execution_context
from portia.open_source_tools.registry import example_tool_registry
from portia.runner import Runner
from portia.workflow import WorkflowState
runner = Runner(
Config.from_default(default_log_level=LogLevel.DEBUG),
tools=example_tool_registry,
)
# Simple Example
workflow = runner.execute_query(
"Get the temperature in London and Sydney and then add the two temperatures rounded to 2DP",
)
# We can also provide additional execution context to the process
with execution_context(end_user_id="123", additional_data={"email_address": "hello@portialabs.ai"}):
plan = runner.execute_query(
"Get the temperature in London and Sydney and then add the two temperatures rounded to 2DP",
)
# When we hit a clarification we can ask our end user for clarification then resume the process
with execution_context(end_user_id="123", additional_data={"email_address": "hello@portialabs.ai"}):
workflow = runner.execute_query(
"Get the temperature in London and Sydney and then add the two temperatures rounded to 2DP",
)
# Fetch workflow
workflow = runner.storage.get_workflow(workflow.id)
# Update clarifications
if workflow.state == WorkflowState.NEED_CLARIFICATION:
for c in workflow.get_outstanding_clarifications():
# Here you prompt the user for the response to the clarification
# via whatever mechanism makes sense for your use-case.
new_value = "Answer"
workflow = runner.resolve_clarification(
workflow=workflow,
clarification=c,
response=new_value,
)
# Execute again with the same execution context
with execution_context(context=workflow.execution_context):
runner.execute_workflow(workflow)