Skip to content

Instantly share code, notes, and snippets.

View elijahbenizzy's full-sized avatar

Elijah ben Izzy elijahbenizzy

View GitHub Profile
action, _, state = app.run(
halt_after=["format_results"],
inputs={"query": "What's the weather like in San Francisco?"},
)
print(state["final_output"])
@elijahbenizzy
elijahbenizzy / app.py
Last active September 28, 2024 00:02
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),
@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",
TYPE_MAP = {
str: "string",
int: "integer",
float: "number",
bool: "boolean",
}
OPENAI_TOOLS = [
{
"type": "function",
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:
app = (
ApplicationBuilder()
.with_entrypoint("prompt")
.with_state(chat_history=[])
.with_actions(
...
)
.with_transitions(
...
)
from burr.integrations.opentelemetry import OpenTelemetryBridge
app = (
ApplicationBuilder()
.with_entrypoint("prompt")
.with_state(chat_history=[])
.with_actions(
...
)
.with_transitions(
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(
@elijahbenizzy
elijahbenizzy / choose_mode_instrumented.py
Created August 14, 2024 22:05
choose_mode_instrumented.py
@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},
],
from opentelemetry.instrumentation.openai import OpenAIInstrumentor
OpenAIInstrumentor().instrument()