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

Update plugins.json #100

Merged
merged 2 commits into from
Oct 7, 2024
Merged

Update plugins.json #100

merged 2 commits into from
Oct 7, 2024

Conversation

lucagobbi
Copy link
Contributor

The CaterpillarForms plugin is an extension of the current CatForm feature. It enables a new decorator @caterpillar_forms to build conversational form in which devs are forced to provide a model_getter(). In this way we can dynamically provide a different schema based on user info or context data.

Example:

from pydantic import BaseModel, Field
from cat.plugins.CaterpillarForms.caterpillarforms import CaterpillarForm, caterpillar_form
from datetime import date

from pydantic import BaseModel, Field


class HotelBookingBasic(BaseModel):
    check_in_date: date = Field(..., description="Check-in date")
    check_out_date: date = Field(..., description="Check-out date")
    num_guests: int = Field(..., description="Number of guests")

class HotelBookingPremium(HotelBookingBasic):
    room_type: str = Field(..., description="Type of room (e.g., Standard, Deluxe, Suite)")
    special_requests: str = Field("", description="Any special requests or accommodations")

@caterpillar_form
class HotelBookingForm(CaterpillarForm):
    description = "Hotel Room Booking"
    
    start_examples = [
        "I want to book a hotel room",
        "Make a hotel reservation",
    ]
    stop_examples = [
        "Cancel hotel booking",
        "Stop booking process",
    ]
    ask_confirm = True

    def model_getter(self) -> BaseModel:
        if self._cat.user_id == "premium_member":
            return HotelBookingPremium
        else:
            return HotelBookingBasic

    def submit(self, form_data):
        return {
            "output": f"Hotel booking confirmed: {form_data}"
        }

lucagobbi and others added 2 commits October 6, 2024 23:45
@pieroit pieroit merged commit f326a62 into cheshire-cat-ai:main Oct 7, 2024
1 check passed
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.

2 participants