> ## Documentation Index
> Fetch the complete documentation index at: https://www.getmaxim.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# components.Generation

> Generation functionality for Components integration.

[View module source on GitHub](https://github.com/maximhq/maxim-py/blob/main/maxim/logger/components/generation.py)

## [GenerationRequestTextMessageContent](/sdk/python/references/logger/components/generation)

```python theme={null}
class GenerationRequestTextMessageContent(TypedDict)
```

This class is used to represent a text message in a generation request.

## [GenerationRequestImageMessageContent](/sdk/python/references/logger/components/generation)

```python theme={null}
class GenerationRequestImageMessageContent(TypedDict)
```

This class is used to represent an image message in a generation request.

## [GenerationRequestMessage](/sdk/python/references/logger/components/generation)

```python theme={null}
class GenerationRequestMessage(TypedDict)
```

This class is used to represent a message in a generation request.

## [GenerationConfigDict](/sdk/python/references/logger/components/generation)

```python theme={null}
class GenerationConfigDict(TypedDict)
```

[Generation](/sdk/python/references/logger/components/generation) config dict.

This class represents a generation config dictionary.

#### get\_generation\_config\_dict

```python theme={null}
def get_generation_config_dict(
        config: Union[GenerationConfig,
                      GenerationConfigDict]) -> dict[str, Any]
```

Convert a generation config to a generation config dict else return the config.

**Arguments**:

| Name     | Type                                                                                                    | Description                      |
| -------- | ------------------------------------------------------------------------------------------------------- | -------------------------------- |
| `config` | *Union\[GenerationConfig, [GenerationConfigDict](/sdk/python/references/logger/components/generation)]* | The config to get the dict from. |

**Returns**:

dict\[str, Any]: The generation config dict.

## [GenerationToolCallFunction](/sdk/python/references/logger/components/generation)

```python theme={null}
class GenerationToolCallFunction(TypedDict)
```

[Generation](/sdk/python/references/logger/components/generation) tool call function.

This class represents a tool call function.

## [GenerationToolCall](/sdk/python/references/logger/components/generation)

```python theme={null}
class GenerationToolCall(TypedDict)
```

[Generation](/sdk/python/references/logger/components/generation) tool call.

This class represents a tool call.

## [TextContent](/sdk/python/references/logger/components/generation)

```python theme={null}
class TextContent(TypedDict)
```

Text content.

This class represents a text content.

## [ImageContent](/sdk/python/references/logger/components/generation)

```python theme={null}
class ImageContent(TypedDict)
```

Image content.

This class represents an image content.

## [AudioContent](/sdk/python/references/logger/components/generation)

```python theme={null}
class AudioContent(TypedDict)
```

Audio content.

This class represents an audio content.

## [GenerationResultMessage](/sdk/python/references/logger/components/generation)

```python theme={null}
class GenerationResultMessage(TypedDict)
```

[Generation](/sdk/python/references/logger/components/generation) result message.

This class represents a generation result message.

## [GenerationResultChoice](/sdk/python/references/logger/components/generation)

```python theme={null}
class GenerationResultChoice(TypedDict)
```

[Generation](/sdk/python/references/logger/components/generation) result choice.

This class represents a generation result choice.

## [TokenDetails](/sdk/python/references/logger/components/generation)

```python theme={null}
class TokenDetails(TypedDict)
```

Token details.

This class represents token details.

## [GenerationUsage](/sdk/python/references/logger/components/generation)

```python theme={null}
class GenerationUsage(TypedDict)
```

[Generation](/sdk/python/references/logger/components/generation) usage.

This class represents generation usage.

## [GenerationResult](/sdk/python/references/logger/components/generation)

```python theme={null}
class GenerationResult(TypedDict)
```

[Generation](/sdk/python/references/logger/components/generation) result.

This class represents a generation result.

#### get\_generation\_error\_config\_dict

```python theme={null}
def get_generation_error_config_dict(
    config: Union[GenerationError, GenerationErrorTypedDict]
) -> GenerationErrorTypedDict
```

Convert a generation error to a generation error dict else return the error.

**Arguments**:

| Name     | Description                                                                                                                                                      |
| -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `config` | Either a [TraceConfig](/sdk/python/references/logger/components/trace) object or a [TraceConfigDict](/sdk/python/references/logger/components/trace) dictionary. |

**Returns**:

A [TraceConfigDict](/sdk/python/references/logger/components/trace) dictionary representation of the config.

## [Generation](/sdk/python/references/logger/components/generation)

```python theme={null}
class Generation(BaseContainer)
```

#### \_\_init\_\_

```python theme={null}
def __init__(config: Union[GenerationConfig, GenerationConfigDict],
             writer: LogWriter)
```

Initialize a generation.

**Arguments**:

| Name     | Description                                   |
| -------- | --------------------------------------------- |
| `config` | The config to initialize the generation with. |
| `writer` | The writer to use.                            |

#### set\_provider\_

```python theme={null}
@staticmethod
def set_provider_(writer: LogWriter, id: str, provider: str)
```

Static method to set the provider for a trace.

**Arguments**:

| Name       | Description                                                            |
| ---------- | ---------------------------------------------------------------------- |
| `writer`   | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `id`       | The ID of the trace to set the provider for.                           |
| `provider` | The provider to set.                                                   |

#### set\_provider

```python theme={null}
def set_provider(provider: str)
```

Set the provider for this trace.

**Arguments**:

| Name       | Description          |
| ---------- | -------------------- |
| `provider` | The provider to set. |

#### set\_model\_

```python theme={null}
@staticmethod
def set_model_(writer: LogWriter, id: str, model: str)
```

Static method to set the model for a trace.

**Arguments**:

| Name     | Description                                                            |
| -------- | ---------------------------------------------------------------------- |
| `writer` | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `id`     | The ID of the trace to set the model for.                              |
| `model`  | The model to set.                                                      |

#### set\_model

```python theme={null}
def set_model(model: str)
```

Set the model for this trace.

**Arguments**:

| Name    | Description       |
| ------- | ----------------- |
| `model` | The model to set. |

#### add\_message\_

```python theme={null}
@staticmethod
def add_message_(writer: LogWriter, id: str,
                 message: GenerationRequestMessage)
```

Static method to add a message to a trace.

**Arguments**:

| Name      | Description                                                            |
| --------- | ---------------------------------------------------------------------- |
| `writer`  | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `id`      | The ID of the trace to add the message to.                             |
| `message` | The message to add.                                                    |

#### add\_message

```python theme={null}
def add_message(message: GenerationRequestMessage) -> None
```

Add a message to this trace.

**Arguments**:

| Name      | Description         |
| --------- | ------------------- |
| `message` | The message to add. |

#### set\_model\_parameters\_

```python theme={null}
@staticmethod
def set_model_parameters_(writer: LogWriter, id: str,
                          model_parameters: Dict[str, Any])
```

Static method to set the model parameters for a trace.

**Arguments**:

| Name               | Description                                                            |
| ------------------ | ---------------------------------------------------------------------- |
| `writer`           | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `id`               | The ID of the trace to set the model parameters for.                   |
| `model_parameters` | The model parameters to set.                                           |

#### set\_model\_parameters

```python theme={null}
def set_model_parameters(model_parameters: Dict[str, Any])
```

Set the model parameters for this trace.

**Arguments**:

| Name               | Description                  |
| ------------------ | ---------------------------- |
| `model_parameters` | The model parameters to set. |

#### add\_attachment

```python theme={null}
def add_attachment(attachment: Union[FileAttachment, FileDataAttachment,
                                     UrlAttachment])
```

Add an attachment to this trace.

**Arguments**:

| Name         | Description            |
| ------------ | ---------------------- |
| `attachment` | The attachment to add. |

#### add\_attachment\_

```python theme={null}
@staticmethod
def add_attachment_(writer: LogWriter, generation_id: str,
                    attachment: Union[FileAttachment, FileDataAttachment,
                                      UrlAttachment])
```

Static method to add an attachment to a trace.

**Arguments**:

| Name            | Description                                                            |
| --------------- | ---------------------------------------------------------------------- |
| `writer`        | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `generation_id` | The ID of the generation to add the attachment to.                     |
| `attachment`    | The attachment to add.                                                 |

#### result\_

```python theme={null}
@staticmethod
def result_(writer: LogWriter, id: str, result: Union[GenerationResult,
                                                      Dict[str, Any]])
```

Static method to add a result to a trace.

**Arguments**:

| Name     | Description                                                            |
| -------- | ---------------------------------------------------------------------- |
| `writer` | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `id`     | The ID of the trace to add the result to.                              |
| `result` | The result to add.                                                     |

#### end\_

```python theme={null}
@staticmethod
def end_(writer: LogWriter, id: str, data: Optional[Dict[str, Any]] = None)
```

Static method to end a trace.

**Arguments**:

| Name     | Description                                                            |
| -------- | ---------------------------------------------------------------------- |
| `writer` | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `id`     | The ID of the trace to end.                                            |
| `data`   | The data to add to the trace.                                          |

#### add\_tag\_

```python theme={null}
@staticmethod
def add_tag_(writer: LogWriter, id: str, key: str, value: str)
```

Static method to add a tag to a trace.

**Arguments**:

| Name     | Description                                                            |
| -------- | ---------------------------------------------------------------------- |
| `writer` | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `id`     | The ID of the trace to add the tag to.                                 |
| `key`    | The key of the tag to add.                                             |
| `value`  | The value of the tag to add.                                           |

#### convert\_chat\_completion

```python theme={null}
@staticmethod
def convert_chat_completion(chat_completion: Dict[str, Any])
```

Convert a chat completion to a generation result.

**Arguments**:

| Name              | Description                     |
| ----------------- | ------------------------------- |
| `chat_completion` | The chat completion to convert. |

**Returns**:

A generation result.

#### convert\_result

```python theme={null}
@staticmethod
def convert_result(
    result: Union[Any, GenerationResult, Dict[str, Any]]
) -> Union[Any, GenerationResult, Dict[str, Any]]
```

Convert a result to a generation result.

**Arguments**:

| Name     | Description            |
| -------- | ---------------------- |
| `result` | The result to convert. |

**Returns**:

A generation result.

#### result

```python theme={null}
def result(result: Any)
```

Add a result to this trace.

**Arguments**:

| Name     | Description        |
| -------- | ------------------ |
| `result` | The result to add. |

#### error

```python theme={null}
def error(error: Union[GenerationError, GenerationErrorTypedDict])
```

Add an error to this trace.

**Arguments**:

| Name    | Description       |
| ------- | ----------------- |
| `error` | The error to add. |

#### error\_

```python theme={null}
@staticmethod
def error_(writer: LogWriter, id: str, error: Union[GenerationError,
                                                    GenerationErrorTypedDict])
```

Static method to add an error to a trace.

**Arguments**:

| Name     | Description                                                            |
| -------- | ---------------------------------------------------------------------- |
| `writer` | The [LogWriter](/sdk/python/references/logger/writer) instance to use. |
| `id`     | The ID of the trace to add the error to.                               |
| `error`  | The error to add.                                                      |

#### data

```python theme={null}
def data() -> Dict[str, Any]
```

Get the data for this trace.

**Returns**:

A dictionary containing the data for this trace.
