Skip to content

Instantly share code, notes, and snippets.

@elijahbenizzy
Created August 14, 2024 22:05
Show Gist options
  • Save elijahbenizzy/b72ba6f20305ffe24ef1c3cb9a4a025a to your computer and use it in GitHub Desktop.
Save elijahbenizzy/b72ba6f20305ffe24ef1c3cb9a4a025a to your computer and use it in GitHub Desktop.
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},
],
)
tracer.log_attributes(prompt=prompt, model="gpt-4", result=json.dumps(result))
... # continue as normal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment