You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's add on to the ChatLab metadata decorator (see #38) to allow people to modify what the little details tab shows.
𝑓 Flipped a coin!
Input:
{}
Output:
"tails"
As part of this we'll want metadata to be applied for the following states around the function (for use by our display calls)
calling - While the function is "trying" to be called
succeeded - what to show when the function successfully finishes
failed - what to show when the function fails (an exception)
At its most basic, it could work like this:
@on_success("Flipped a coin!")@on_failure("Failed to flip a coin. :(")defflip_a_coin():
'''Returns heads or tails'''returnrandom.choice(['heads', 'tails'])
Advanced Formatting options
Since we work with named parameters, we could apply the arguments to strings with named parameters.
importrequestsimportchatlabclassPokemonFetchError(Exception):
"""An error for when we fail to fetch a pokemon, tailored for LLM output"""def__init__(self, pokemon_name):
self.pokemon_name=pokemon_nameself.message=f"Failed to fetch information for Pokemon '{self.pokemon_name}'. Please make sure the Pokemon name is correct."super().__init__(self.message)
@on_success("Go {name}!")@on_failure("Failed to fetch Pokemon {name}")deffetch_pokemon(name: str):
"""Fetch information about a pokemon by name"""url=f"https://pokeapi.co/api/v2/pokemon/{name}"try:
response=requests.get(url)
response.raise_for_status() # will raise an HTTPError if the response status code is 4xx or 5xxreturnresponse.json()
exceptrequests.HTTPError:
raisePokemonFetchError(name)
Get me information about murkrow.
𝑓 Go murkrow!
Input:
{ "name": "murkrow" }
Output:
<<information about murkrow here>>
The text was updated successfully, but these errors were encountered:
Let's add on to the ChatLab metadata decorator (see #38) to allow people to modify what the little details tab shows.
𝑓 Flipped a coin!
Input:
Output:
"tails"
As part of this we'll want metadata to be applied for the following states around the function (for use by our
display
calls)calling
- While the function is "trying" to be calledsucceeded
- what to show when the function successfully finishesfailed
- what to show when the function fails (an exception)At its most basic, it could work like this:
Advanced Formatting options
Since we work with named parameters, we could apply the arguments to strings with named parameters.
𝑓 Go murkrow!
Input:
Output:
<<information about murkrow here>>
The text was updated successfully, but these errors were encountered: