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

Generated type for tuples not compatible with OpenAI #97

Open
rgbkrk opened this issue Oct 16, 2023 · 2 comments
Open

Generated type for tuples not compatible with OpenAI #97

rgbkrk opened this issue Oct 16, 2023 · 2 comments
Labels
good first issue Good for newcomers

Comments

@rgbkrk
Copy link
Owner

rgbkrk commented Oct 16, 2023

Example

from typing import Tuple, List

def color_shades(rgb_color: Tuple[int, int, int], num_shades: int) -> List[Tuple[int, int, int]]:
    """
    Generate a list of shades for a given RGB color.

    Args:
        rgb_color: A tuple of three integers representing an RGB color.
        num_shades: The number of shades to generate.

    Returns:
        A list of tuples, each containing three integers representing an RGB color.
    """
    shades = [
        (
            max(0, min(255, int(rgb_color[0] * (1 - j / num_shades)))),
            max(0, min(255, int(rgb_color[1] * (1 - j / num_shades)))),
            max(0, min(255, int(rgb_color[2] * (1 - j / num_shades)))),
        )
        for j in range(num_shades)
    ]
    return shades

from chatlab import Chat

chat = Chat(
    chat_functions=[color_shades]
)

await chat("Compute some shades of periwinkle.")
BadRequestError: Error code: 400 - {'error': {'message': "Invalid schema for function 'color_shades': [{'type': 'integer'}, {'type': 'integer'}, {'type': 'integer'}] is not of type 'object', 'boolean'", 'type': 'invalid_request_error', 'param': None, 'code': None}}
@rgbkrk rgbkrk changed the title Tuples not processable via OpenAI Generated type for tuples not compatible with OpenAI Oct 16, 2023
@rgbkrk
Copy link
Owner Author

rgbkrk commented Oct 16, 2023

The easy solution is to switch this to accepting List[int]. Perhaps we just need to detect and knock tuples down to a list type with one inner type.

from typing import Tuple, List

def color_shades(rgb_color: List[int], num_shades: int) -> List[Tuple[int, int, int]]:
    """
    Generate a list of shades for a given RGB color.

    Args:
        rgb_color: A list of three integers representing an RGB color.
        num_shades: The number of shades to generate.

    Returns:
        A list of tuples, each containing three integers representing an RGB color.
    """
    shades = [
        (
            max(0, min(255, int(rgb_color[0] * (1 - j / num_shades)))),
            max(0, min(255, int(rgb_color[1] * (1 - j / num_shades)))),
            max(0, min(255, int(rgb_color[2] * (1 - j / num_shades)))),
        )
        for j in range(num_shades)
    ]
    return shades

@rgbkrk
Copy link
Owner Author

rgbkrk commented Feb 28, 2024

Confirmed that this is still an issue in v2.0.0.

@rgbkrk rgbkrk added the good first issue Good for newcomers label Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant