Functions

Overview

Lillo implements a standardized function calling system across compatible LLM providers. This system enables AI models to interact with external services and perform specific actions through a well-defined interface.

Supported Providers

Full Support

  • OpenAI (gpt-4o)

  • Grok (grok-2-latest)

  • DeepSeek (deepseek-chat)

No Support

  • Gemini (gemini-pro)

Core Functions

Image Generation

{
  name: "generate_image",
  description: "Generate an image based on the user's request",
  parameters: {
    type: "object",
    properties: {
      prompt: {
        type: "string",
        description: "The description of the image to generate"
      }
    },
    required: ["prompt"]
  }
}

Implementation:

  • Uses DALL-E for image generation

  • Supports detailed prompts

  • Returns image URL

  • Handles style preferences

Weather Data

{
  name: "get_weather",
  description: "Get current weather data for any major city",
  parameters: {
    type: "object",
    properties: {
      location: {
        type: "object",
        properties: {
          name: { type: "string" },
          country: { type: "string" },
          coordinates: {
            type: "object",
            properties: {
              lat: { type: "number" },
              lon: { type: "number" }
            }
          }
        }
      },
      type: {
        type: "string",
        enum: ["current", "forecast"]
      }
    }
  }
}

Implementation:

  • Real-time weather data

  • Location validation

  • Coordinate resolution

  • Forecast support

Market Data

{
  name: "get_market_data",
  description: "Get cryptocurrency market data",
  parameters: {
    type: "object",
    properties: {
      type: {
        type: "string",
        enum: ["token", "trending", "top", "latest", "boosted"]
      },
      query: {
        type: "string",
        description: "Token symbol or address"
      }
    },
    required: ["type"]
  }
}

Implementation:

  • Real-time market data

  • Multiple data types

  • Token validation

  • Price tracking

Time Information

{
  name: "get_time",
  description: "Gets the current time for a location",
  parameters: {
    type: "object",
    properties: {
      location: {
        type: "object",
        properties: {
          name: { type: "string" },
          country: { type: "string" },
          coordinates: {
            type: "object",
            properties: {
              lat: { type: "number" },
              lon: { type: "number" }
            }
          }
        }
      }
    }
  }
}

Implementation:

  • Timezone resolution

  • Location validation

  • Format customization

  • DST handling

Implementation Details

Provider Integration

// OpenAI Example
const response = await this.client.chat.completions.create({
  model: 'gpt-4o',
  messages: formattedMessages,
  tools: [{
    type: "function",
    function: functions.generate_image
  },
  {
    type: "function",
    function: functions.get_weather
  },
  {
    type: "function",
    function: functions.get_market_data
  },
  {
    type: "function",
    function: functions.get_time
  }]
});

Response Handling

interface LLMResponse {
  content: string;
  totalTokens?: number;
  toolCalls?: Array<{
    id: string;
    type: 'function';
    function: {
      name: string;
      arguments: string;
    }
  }>;
}

Best Practices

Function Design

  • Clear descriptions

  • Required parameters

  • Type validation

  • Error handling

Response Processing

  • Validate function calls

  • Handle missing data

  • Format responses

  • Cache results

Error Handling

  • Invalid parameters

  • Service unavailability

  • Rate limiting

  • Timeout handling

Security

  • Input validation

  • API key management

  • Response sanitization

  • Access control

Last updated