# LLM Nodes

The **LLM nodes** in Dynamiq allow users to integrate various LLM providers for natural language processing tasks such as text generation, question answering, and language comprehension. Through connections to services like OpenAI, Anthropic, and custom LLMs, users can configure and optimize workflows for various use cases, including customer support automation, content generation, and more.

<figure><img src="https://4279757243-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTbBxR0Ob7RUmbvHZkQi2%2Fuploads%2FcL6zQJ0VE6fH5tmKliM6%2Fimage.png?alt=media&#x26;token=2d5a9e51-b4d6-4c87-829f-722b39cd74d0" alt=""><figcaption></figcaption></figure>

### Supported Providers and Models

Dynamiq supports a variety of LLM providers, enabling users to choose the best model for their specific use case. Each provider offers unique models with varying capabilities, costs, and performance characteristics. Below is a list of the LLM providers integrated within Dynamiq:<br>

<table><thead><tr><th width="141">Provider</th><th width="304">Description</th><th width="151">Models</th><th>API Documentation</th></tr></thead><tbody><tr><td><strong>OpenAI</strong></td><td>Advanced language models suitable for complex language tasks.</td><td>GPT-4o, GPT-4o-mini</td><td><a href="https://platform.openai.com/docs/models">OpenAI API Documentation</a></td></tr><tr><td><strong>Anthropic</strong></td><td>Models like Claude for conversational and generative text applications.</td><td>Claude 3.5 Sonnet, Claude 3.5 Haiku</td><td><a href="https://docs.anthropic.com/en/docs">Anthropic API Documentation</a></td></tr><tr><td><strong>Cohere</strong></td><td>Text generation and embedding models, often used for content creation and analysis.</td><td>Command R+, Command R</td><td><a href="https://docs.cohere.ai/">Cohere API Documentation</a></td></tr><tr><td><strong>Gemini</strong></td><td>Models optimized for information retrieval and summarization tasks.</td><td>Gemini Pro 1.5, Gemini Flash 1.5</td><td><a href="https://docs.gemini.com/"> </a><a href="https://ai.google.dev/gemini-api/docs">Google AI API Documentation</a></td></tr><tr><td><strong>AWS Bedrock</strong></td><td>Cloud-based service offering models optimized for enterprise and general-purpose NLP tasks.</td><td>Various proprietary models</td><td><a href="https://docs.aws.amazon.com/bedrock/">AWS Bedrock Documentation</a></td></tr><tr><td><strong>Groq</strong></td><td>Models optimized for high-performance inference, often used in real-time applications.</td><td>Llama 3.1, Llama 3.2</td><td><a href="https://console.groq.com/docs/models">Groq API Documentation</a></td></tr><tr><td><strong>Mistral</strong></td><td>Specialized models focusing on efficiency in text generation and comprehension.</td><td>Mistral Large, Small, Embed</td><td><a href="https://docs.mistral.ai/getting-started/models/models_overview/">Mistral Documentation</a></td></tr><tr><td><strong>Together AI</strong></td><td>Provides collaborative NLP tools for tasks such as summarization and translation.</td><td>Llama, Gemma, Mistral models</td><td><a href="https://docs.together.ai/docs/serverless-models">Together AI Documentation</a></td></tr><tr><td><strong>Hugging Face</strong></td><td>Offers a vast repository of models, from general-purpose transformers to specialized NLP models.</td><td>Open-source models</td><td><a href="https://huggingface.co/models">Hugging Face Documentation</a></td></tr><tr><td><strong>IBM watsonx</strong></td><td>IBM's suite of AI tools for enterprise applications, including data analysis and NLP.</td><td>Granite</td><td><a href="https://www.ibm.com/products/watsonx-ai/foundation-models">IBM watsonx Documentation</a></td></tr><tr><td><strong>Azure AI</strong></td><td>Microsoft's cloud-based language models suitable for enterprise and developer-focused applications.</td><td>OpenAI models</td><td><a href="https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models?tabs=python-secure%2Cglobal-standard%2Cstandard-chat-completions">Azure AI Documentation</a></td></tr><tr><td><strong>Replicate</strong></td><td>Models focused on reproducible AI research, useful for scientific and technical applications.</td><td>Open-source models</td><td><a href="https://replicate.com/collections/language-models">Replicate Documentation</a></td></tr><tr><td><strong>SambaNova</strong></td><td>AI models optimized for enterprise-scale NLP and other machine learning applications.</td><td>Llama family</td><td><a href="https://community.sambanova.ai/t/supported-models/193">SambaNova Documentation</a></td></tr><tr><td><strong>Cerebras</strong></td><td>AI models tailored for high-performance NLP and deep learning tasks in large-scale environments.</td><td>Open-source models</td><td><a href="https://docs.cerebras.ai/en/latest/wsc/Model-zoo/MZ-overview.html">Cerebras Documentations</a></td></tr><tr><td><strong>DeepInfra</strong></td><td>Specializes in deploying high-performance AI infrastructure with NLP capabilities.</td><td>Open-source models</td><td><a href="https://deepinfra.com/models">DeepInfra Documentation</a></td></tr><tr><td><strong>Custom LLM</strong></td><td>Allows integration with any OpenAI-compatible or custom-deployed models, ideal for proprietary setups.</td><td>Custom models (OpenRouter compatible, self-hosted)</td><td><a href="#configuring-a-custom-llm-node">Custom LLM</a></td></tr><tr><td><strong>xAI</strong></td><td>Specialized models focusing on efficiency in text generation and comprehension.</td><td>Grok-3</td><td><a href="https://docs.x.ai/docs/overview">xAI</a></td></tr><tr><td><strong>Perplexity</strong></td><td>Specialized models focusing on efficiency in text generation, web-search results</td><td>Sonar</td><td><a href="https://docs.perplexity.ai/home">Perplexity</a></td></tr></tbody></table>

***

### Configuration

#### 1. Setting Up an LLM Node

Each LLM node requires careful configuration to ensure accurate and efficient operation. Follow these steps to set up an LLM node:

**Step 1: Connection Configuration**

* **Connection**: Each LLM node must be linked to its respective service provider.
* **API Keys**: Obtain API keys or tokens for each provider by following the documentation links.

<figure><img src="https://4279757243-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTbBxR0Ob7RUmbvHZkQi2%2Fuploads%2FopbVCKeWStLtPffQaOWa%2FLLM%20Nodes%20-%20Connection%20configuration.gif?alt=media&#x26;token=645a80f9-d066-42a9-ac28-d26e4d97e195" alt=""><figcaption><p>New connection configuration</p></figcaption></figure>

**Step 2: Prompt Configuration**

* **Prompt Library**: Dynamiq allows users to select prompts from a library or create inline prompts.
* **Dynamic Prompting**: Prompts can be customized based on input parameters to generate diverse responses. This is achieved by inserting parameters directly into the prompt text using the format `{{parameter_name}}`. &#x20;

<figure><img src="https://4279757243-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTbBxR0Ob7RUmbvHZkQi2%2Fuploads%2FgAiFNI63f2p9k8x6f58T%2FLow%20Code%20Builder%20-%20LLM%20Nodes%20-%20Prompt%20Config.gif?alt=media&#x26;token=36260ffe-f09a-465e-a30e-addfa1fb0410" alt=""><figcaption></figcaption></figure>

<figure><img src="https://4279757243-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTbBxR0Ob7RUmbvHZkQi2%2Fuploads%2FEv9kDX596WKba1lDxVq8%2FLow%20Code%20Builder%20-%20LLM%20Nodes%20-%20Prompt%20Config%20(2).gif?alt=media&#x26;token=0e3f45ed-e1a6-423f-b486-e4529f9b4d82" alt=""><figcaption></figcaption></figure>

#### 2. Core Parameters

These parameters allow you to control the behavior and performance of the LLM node, optimizing it for various applications:

<table><thead><tr><th width="146">Parameter</th><th width="432">Description</th><th>Example Values</th></tr></thead><tbody><tr><td><strong>Model</strong></td><td>Specifies the LLM model to use. The model field supports free-text input with auto-suggestions, allowing for immediate access to new models. Ensure the model name matches the provider’s offerings.</td><td><code>gpt-4o, claude-3-haiku</code></td></tr><tr><td><strong>Temperature</strong></td><td>Controls the level of randomness in the model’s output. Lower values (close to 0) make responses more deterministic, suitable for tasks requiring precision. Higher values (close to 1) encourage creative responses, ideal for content generation.</td><td><code>0.2</code> for deterministic, <code>0.7</code> for creative</td></tr><tr><td><strong>Max Tokens</strong></td><td>Sets the maximum number of tokens the model can generate in its response. Useful for limiting the output length to control costs or meet specific response size requirements.</td><td><code>500</code>, <code>1000</code></td></tr><tr><td><strong>Streaming</strong></td><td>Enables token-by-token streaming of responses, providing real-time feedback. Streaming is recommended for use cases requiring quick insights, such as interactive applications.</td><td><code>Enabled</code>, <code>Disabled</code></td></tr></tbody></table>

### Input/Output Configuration

#### Input Processing

* **JSONPath Selection**: Use JSONPath to filter and structure input data, allowing for precise extraction of information.
* **Prompt Templates**: Dynamically create prompts by inserting runtime parameters.

#### Output Processing

* **Filtering**: Filter responses to retrieve only relevant data.
* **Structured Outputs**: Dynamiq supports different output formats, including plain text, JSON.

### Best Practices

#### Model Selection

Selecting the right model is crucial for balancing cost, speed, and quality:

* **Complex Tasks**: Use more advanced models like GPT-4 or Claude for complex outputs.
* **Cost-Efficiency**: Opt for smaller models like GPT-4o-mini / claude haiku for simpler tasks to reduce expenses.
* **Provider-Specific Features**: Some providers offer unique features like function calling; refer to provider documentation for details.

#### Prompt Engineering

Effective prompt design can significantly impact model performance:

* **Clear Instructions**: Use specific language to minimize ambiguity.
* **Contextual Information**: Include background details to guide the model's response.
* **Testing**: Test prompts across various inputs to ensure consistency.

#### Error Handling

To ensure seamless operation and improve resilience, configure error handling mechanisms within your workflow:

<table><thead><tr><th width="156">Parameter</th><th width="441">Description</th><th>Example Values</th></tr></thead><tbody><tr><td><strong>Interval</strong></td><td>Sets the delay (in seconds) before the first retry attempt. Must be greater than 0.</td><td><code>2</code> seconds</td></tr><tr><td><strong>Max Attempts</strong></td><td>Specifies the maximum number of retry attempts. Set to <code>0</code> or greater to determine retry limits.</td><td><code>3</code> attempts</td></tr><tr><td><strong>Backoff Rate</strong></td><td>Multiplier that increases the retry interval for each subsequent attempt. Helps to reduce load on the system progressively. Must be <code>1</code> or greater.</td><td><code>2.0</code></td></tr><tr><td><strong>Timeout</strong></td><td>Sets a timeout limit (in seconds) for each attempt. If exceeded, the process fails to prevent excessive delays.</td><td><code>10</code> seconds</td></tr></tbody></table>

{% hint style="info" %}
Adjust these settings based on workflow requirements and provider limitations to avoid unnecessary delays or costs.
{% endhint %}

**Rate Limit Handling**

Consider configuring rate limits to stay compliant with provider-specific quotas. Utilize the backoff rate and interval settings to manage requests dynamically and avoid reaching rate limits, which can lead to throttling or blocked requests.

### Performance Optimization

Optimize your LLM node's performance by following these strategies:

* **Response Caching**: Enable caching to reduce redundant requests and improve speed.
* **Batching Requests**: Group requests to process multiple items simultaneously, improving efficiency.
* **Token Usage Monitoring**: Track token consumption to control costs and manage API quotas.

| Token Type            | Example Input | Cost Calculation                                 |
| --------------------- | ------------- | ------------------------------------------------ |
| **Prompt Tokens**     | `250 tokens`  | (Prompt tokens / 1000) \* Cost per 1K tokens     |
| **Completion Tokens** | `500 tokens`  | (Completion tokens / 1000) \* Cost per 1K tokens |

***

### Advanced Features

#### Inference Modes

Dynamiq LLM nodes offer multiple modes to tailor responses to specific needs:

* **DEFAULT**: Standard text-based response generation.
* **STRUCTURED\_OUTPUT**: Provides structured outputs in JSON format.

#### Streaming Support

Enable streaming for applications requiring real-time feedback, such as customer support or live content generation.

***

### Configuring a Custom LLM Node

Dynamiq's custom LLM node allows users to integrate models deployed on their own servers or models compatible with OpenAI's API syntax through OpenRouter. This flexibility provides seamless integration for both proprietary and third-party LLMs.

1. **Add Custom LLM Node**: Select the Custom LLM node from the panel.
2. **Choose Model**: Enter the model name. Dynamiq supports manual input for models not listed in auto-suggestions.
3. **Prompt Configuration**: Define prompts using the inline prompt editor or select from the library.
4. **Connect & Test**: Connect to your server or OpenRouter and test the configuration.

{% hint style="info" %}
Use Custom LLM for experimental models or those deployed within secure environments.
{% endhint %}
