Skip to content

Conversation

pmeier
Copy link
Member

@pmeier pmeier commented Nov 29, 2023

Addresses 1. and 2. of #217.

@pmeier
Copy link
Member Author

pmeier commented Nov 29, 2023

The code on the UI side to parse the schema could look like

from panel.widgets import EditableIntSlider

from ragna.assistants import Gpt35Turbo16k


def make_panel_widgets(schema):
    widgets = {}
    for name, parameter in schema["properties"].items():
        type_ = parameter["type"]
        if type_ == "integer":
            widget_cls = EditableIntSlider

            fixed_start = parameter.get("exclusiveMinimum")
            if fixed_start is not None:
                fixed_start += 1
            else:
                fixed_start = parameter.get("minimum")

            fixed_end = parameter.get("exclusiveMaximum")
            if fixed_end is not None:
                fixed_end -= 1
            else:
                fixed_end = parameter.get("maximum")

            kwargs = dict(fixed_start=fixed_start, fixed_end=fixed_end)
        else:
            raise Exception

        widgets[name] = widget_cls(
            value=parameter.get("default"),
            name=parameter.get("title"),
            **kwargs,
        )

    return widgets


# Just for demo purposes
# This schema would come as part of the /components endpoint
schema = Gpt35Turbo16k._protocol_model().model_json_schema()

print(make_panel_widgets(schema))

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

Successfully merging this pull request may close these issues.

1 participant