Skip to main content

OpenAI Integration

This guide shows how to use Danube tools with OpenAI’s function calling feature, enabling GPT models to execute real-world actions through Danube’s tool marketplace.

Overview

OpenAI’s function calling allows GPT models to:
  1. Receive a list of available functions (tools)
  2. Decide which function to call based on user input
  3. Generate structured arguments for the function
  4. Process the function result and respond to the user
Danube provides hundreds of pre-built tools that can be converted to OpenAI function format and executed seamlessly.

Prerequisites

Basic Example

Here’s a complete example of using Danube tools with OpenAI:

Full Agent Example

Here’s a more complete agent implementation with conversation history:

Dynamic Tool Loading

You can dynamically load tools based on the conversation:

Best Practices

1. Tool Selection

Don’t load too many tools at once - it increases token usage and can confuse the model:

2. Error Handling

Always handle tool execution errors gracefully:

3. Parameter Validation

Validate parameters before execution:

4. Streaming Responses

For long-running tools, consider streaming:

Complete Working Example

See the full example in the SDK repository: