This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
action, _, state = app.run( | |
halt_after=["format_results"], | |
inputs={"query": "What's the weather like in San Francisco?"}, | |
) | |
print(state["final_output"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app = ( | |
ApplicationBuilder() | |
.with_actions( | |
process_input, | |
select_tool, | |
format_results, | |
query_weather=call_tool.bind(tool_function=_weather_tool), | |
text_wife=call_tool.bind(tool_function=_text_wife_tool), | |
order_coffee=call_tool.bind(tool_function=_order_coffee_tool), | |
fallback=call_tool.bind(tool_function=_fallback), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@action(reads=["query"], writes=["tool_parameters", "tool"]) | |
def select_tool(state: State) -> State: | |
messages = [ | |
{ | |
"role": "system", | |
"content": ( | |
"You are a helpful assistant. Use the supplied tools to assist the user", | |
", if they apply in any way. Remember to use the tools!", | |
" They can do stuff you can't.", | |
"If you can't use only the tools provided to answer the question", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TYPE_MAP = { | |
str: "string", | |
int: "integer", | |
float: "number", | |
bool: "boolean", | |
} | |
OPENAI_TOOLS = [ | |
{ | |
"type": "function", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _weather_tool(latitude: float, longitude: float) -> dict: | |
"""Queries the weather for a given latitude and longitude.""" | |
api_key = os.environ.get("TOMORROW_API_KEY") | |
url = f"https://api.tomorrow.io/v4/weather/forecast?location={latitude},{longitude}&apikey={api_key}" | |
response = requests.get(url) | |
# Check if the request was successful | |
if response.status_code == 200: | |
return response.json() | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app = ( | |
ApplicationBuilder() | |
.with_entrypoint("prompt") | |
.with_state(chat_history=[]) | |
.with_actions( | |
... | |
) | |
.with_transitions( | |
... | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from burr.integrations.opentelemetry import OpenTelemetryBridge | |
app = ( | |
ApplicationBuilder() | |
.with_entrypoint("prompt") | |
.with_state(chat_history=[]) | |
.with_actions( | |
... | |
) | |
.with_transitions( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app = ( | |
ApplicationBuilder() | |
.with_entrypoint("prompt") | |
.with_state(chat_history=[]) | |
.with_actions( | |
prompt=process_prompt, | |
check_safety=check_safety, | |
decide_mode=choose_mode, | |
generate_image=image_response, | |
generate_code=chat_response.bind( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@action(reads=["prompt"], writes=["mode"]) | |
def choose_mode(state: State, __tracer) -> Tuple[dict, State]: | |
prompt = ... | |
with __tracer("query_openai") as tracer: | |
result = _get_openai_client().chat.completions.create( | |
model="gpt-4", | |
messages=[ | |
{"role": "system", "content": "You are a helpful assistant"}, | |
{"role": "user", "content": prompt}, | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from opentelemetry.instrumentation.openai import OpenAIInstrumentor | |
OpenAIInstrumentor().instrument() |
NewerOlder