Text Gen Functions

Example

Many of the LLM models support function calling.

main.py

from ugly_bot import *

@export("user_location_get")
def func():
    return "Seattle, WA"

@export("message_direct")
def text_gen_example(message):
    tool = TextGenTool(
        name="user_location_get",
        description="Get the location of the user",
    )

    history = message_history(limit=50)
    text = text_gen(
        model=TextGenModel.OPENAI_GPT_4O,
        instruction='You are funny and always making jokes.',
        messages=history,
        tools=[tool]
    )
    message_send(markdown=text)

start()

Note

In the TextGenTool it specifies the name of function to call in the name parameter. Make sure your bot exports a function with a matching name. If you need parameters for your function specify the parameters field using JSON schema. Ugly will map those parameters to your named arguments.

Glossary