# Functions

## Supported Providers

### Full Support

* OpenAI (gpt-4o)
* Grok (grok-2-latest)
* DeepSeek (deepseek-chat)

### No Support

* Gemini (gemini-pro)

## Core Functions

### Image Generation

```typescript
{
  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

```typescript
{
  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

```typescript
{
  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

```typescript
{
  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

```typescript
// 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

```typescript
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

## Related Documentation

* [LLM Factory](https://docs.lillo.ai/llm/factory)
* [Provider Configuration](https://github.com/lillo-ai/website/blob/master/docs/core/framework/configuration.md)
* [External Services](https://github.com/lillo-ai/website/blob/master/docs/core/framework/services.md)
