View module source on GitHub

GenerationRequestTextMessageContent

class GenerationRequestTextMessageContent(TypedDict)

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

GenerationRequestImageMessageContent

class GenerationRequestImageMessageContent(TypedDict)

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

GenerationRequestMessage

class GenerationRequestMessage(TypedDict)

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

GenerationConfigDict

class GenerationConfigDict(TypedDict)

Generation config dict.

This class represents a generation config dictionary.

get_generation_config_dict

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:

NameTypeDescription
configUnion[GenerationConfig, GenerationConfigDict]The config to get the dict from.

Returns:

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

GenerationToolCallFunction

class GenerationToolCallFunction(TypedDict)

Generation tool call function.

This class represents a tool call function.

GenerationToolCall

class GenerationToolCall(TypedDict)

Generation tool call.

This class represents a tool call.

TextContent

class TextContent(TypedDict)

Text content.

This class represents a text content.

ImageContent

class ImageContent(TypedDict)

Image content.

This class represents an image content.

AudioContent

class AudioContent(TypedDict)

Audio content.

This class represents an audio content.

GenerationResultMessage

class GenerationResultMessage(TypedDict)

Generation result message.

This class represents a generation result message.

GenerationResultChoice

class GenerationResultChoice(TypedDict)

Generation result choice.

This class represents a generation result choice.

TokenDetails

class TokenDetails(TypedDict)

Token details.

This class represents token details.

GenerationUsage

class GenerationUsage(TypedDict)

Generation usage.

This class represents generation usage.

GenerationResult

class GenerationResult(TypedDict)

Generation result.

This class represents a generation result.

get_generation_error_config_dict

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:

NameDescription
configEither a TraceConfig object or a TraceConfigDict dictionary.

Returns:

A TraceConfigDict dictionary representation of the config.

Generation

class Generation(BaseContainer)

__init__

def __init__(config: Union[GenerationConfig, GenerationConfigDict],
             writer: LogWriter)

Initialize a generation.

Arguments:

NameDescription
configThe config to initialize the generation with.
writerThe writer to use.

set_provider_

@staticmethod
def set_provider_(writer: LogWriter, id: str, provider: str)

Static method to set the provider for a trace.

Arguments:

NameDescription
writerThe LogWriter instance to use.
idThe ID of the trace to set the provider for.
providerThe provider to set.

set_provider

def set_provider(provider: str)

Set the provider for this trace.

Arguments:

NameDescription
providerThe provider to set.

set_model_

@staticmethod
def set_model_(writer: LogWriter, id: str, model: str)

Static method to set the model for a trace.

Arguments:

NameDescription
writerThe LogWriter instance to use.
idThe ID of the trace to set the model for.
modelThe model to set.

set_model

def set_model(model: str)

Set the model for this trace.

Arguments:

NameDescription
modelThe model to set.

add_message_

@staticmethod
def add_message_(writer: LogWriter, id: str,
                 message: GenerationRequestMessage)

Static method to add a message to a trace.

Arguments:

NameDescription
writerThe LogWriter instance to use.
idThe ID of the trace to add the message to.
messageThe message to add.

add_message

def add_message(message: GenerationRequestMessage) -> None

Add a message to this trace.

Arguments:

NameDescription
messageThe message to add.

set_model_parameters_

@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:

NameDescription
writerThe LogWriter instance to use.
idThe ID of the trace to set the model parameters for.
model_parametersThe model parameters to set.

set_model_parameters

def set_model_parameters(model_parameters: Dict[str, Any])

Set the model parameters for this trace.

Arguments:

NameDescription
model_parametersThe model parameters to set.

add_attachment

def add_attachment(attachment: Union[FileAttachment, FileDataAttachment,
                                     UrlAttachment])

Add an attachment to this trace.

Arguments:

NameDescription
attachmentThe attachment to add.

add_attachment_

@staticmethod
def add_attachment_(writer: LogWriter, generation_id: str,
                    attachment: Union[FileAttachment, FileDataAttachment,
                                      UrlAttachment])

Static method to add an attachment to a trace.

Arguments:

NameDescription
writerThe LogWriter instance to use.
generation_idThe ID of the generation to add the attachment to.
attachmentThe attachment to add.

result_

@staticmethod
def result_(writer: LogWriter, id: str, result: Union[GenerationResult,
                                                      Dict[str, Any]])

Static method to add a result to a trace.

Arguments:

NameDescription
writerThe LogWriter instance to use.
idThe ID of the trace to add the result to.
resultThe result to add.

end_

@staticmethod
def end_(writer: LogWriter, id: str, data: Optional[Dict[str, Any]] = None)

Static method to end a trace.

Arguments:

NameDescription
writerThe LogWriter instance to use.
idThe ID of the trace to end.
dataThe data to add to the trace.

add_tag_

@staticmethod
def add_tag_(writer: LogWriter, id: str, key: str, value: str)

Static method to add a tag to a trace.

Arguments:

NameDescription
writerThe LogWriter instance to use.
idThe ID of the trace to add the tag to.
keyThe key of the tag to add.
valueThe value of the tag to add.

convert_chat_completion

@staticmethod
def convert_chat_completion(chat_completion: Dict[str, Any])

Convert a chat completion to a generation result.

Arguments:

NameDescription
chat_completionThe chat completion to convert.

Returns:

A generation result.

convert_result

@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:

NameDescription
resultThe result to convert.

Returns:

A generation result.

result

def result(result: Any)

Add a result to this trace.

Arguments:

NameDescription
resultThe result to add.

error

def error(error: Union[GenerationError, GenerationErrorTypedDict])

Add an error to this trace.

Arguments:

NameDescription
errorThe error to add.

error_

@staticmethod
def error_(writer: LogWriter, id: str, error: Union[GenerationError,
                                                    GenerationErrorTypedDict])

Static method to add an error to a trace.

Arguments:

NameDescription
writerThe LogWriter instance to use.
idThe ID of the trace to add the error to.
errorThe error to add.

data

def data() -> Dict[str, Any]

Get the data for this trace.

Returns:

A dictionary containing the data for this trace.