Skip to content

online_purchase

OnlinePurchase

Bases: FormTool

Source code in wizard_ai/conversational_engine/tools/online_purchase.py
class OnlinePurchase(FormTool):
    name = "OnlinePurchase"
    description = """Purchase an item from an online store"""
    args_schema: Type[BaseModel] = OnlinePurchasePayload


    def _run_when_complete(
        self,
        *args,
        **kwargs
    ) -> str:
        return "OK"

    def get_next_field_to_collect(
        self,
        **kwargs
    ) -> str:
        """
        The default implementation returns the first field that is not set.
        """
        if not self.form.item:
            return "item"

        if self.form.item == "book":
            if self.form.ebook == None:
                return "ebook"
            if self.form.ebook == True:
                if not self.form.email:
                    return "email"
                else:
                    return None

        if not self.form.quantity:
            return "quantity"

        if not self.form.region:
            return "region"

        if not self.form.province:
            return "province"

        if not self.form.address:
            return "address"

        return None

get_next_field_to_collect(**kwargs)

The default implementation returns the first field that is not set.

Source code in wizard_ai/conversational_engine/tools/online_purchase.py
def get_next_field_to_collect(
    self,
    **kwargs
) -> str:
    """
    The default implementation returns the first field that is not set.
    """
    if not self.form.item:
        return "item"

    if self.form.item == "book":
        if self.form.ebook == None:
            return "ebook"
        if self.form.ebook == True:
            if not self.form.email:
                return "email"
            else:
                return None

    if not self.form.quantity:
        return "quantity"

    if not self.form.region:
        return "region"

    if not self.form.province:
        return "province"

    if not self.form.address:
        return "address"

    return None