Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow customized details about function calling #28

Closed
rgbkrk opened this issue Jun 24, 2023 · 1 comment
Closed

Allow customized details about function calling #28

rgbkrk opened this issue Jun 24, 2023 · 1 comment

Comments

@rgbkrk
Copy link
Owner

rgbkrk commented Jun 24, 2023

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. :(")
def flip_a_coin():
    '''Returns heads or tails'''
    return random.choice(['heads', 'tails'])

Advanced Formatting options

Since we work with named parameters, we could apply the arguments to strings with named parameters.

import requests
import chatlab

class PokemonFetchError(Exception):
    """An error for when we fail to fetch a pokemon, tailored for LLM output"""
    def __init__(self, pokemon_name):
        self.pokemon_name = pokemon_name
        self.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}")
def fetch_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 5xx
        return response.json()
    except requests.HTTPError:
        raise PokemonFetchError(name)
Get me information about murkrow.
 𝑓  Go murkrow!

Input:

{ "name": "murkrow" }

Output:

<<information about murkrow here>>
@rgbkrk rgbkrk changed the title ChatLab metadata decorator Allow customized details about function calling Jun 25, 2023
@rgbkrk
Copy link
Owner Author

rgbkrk commented Feb 28, 2024

Closing as this is effectively done via #136 and its also way more fun.

@rgbkrk rgbkrk closed this as completed Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant