nat.data_models.api_server#
Attributes#
Classes#
Enum representing chat message roles in API requests and responses. |
|
Request is a data model that represents HTTP request attributes. |
|
ChatContentType is an Enum that represents the type of Chat content. |
|
ChatRequest is a data model that represents a request to the NAT chat API. |
|
|
|
Delta object for streaming responses (OpenAI-compatible) |
|
Base choice model with common fields for both streaming and non-streaming responses |
|
Choice model for non-streaming responses - contains message field |
|
Choice model for streaming responses - contains delta field |
|
ResponseSerializable is an abstract class that defines the interface for serializing output for the NAT |
|
ChatResponse is a data model that represents a response from the NAT chat API. |
|
ChatResponseChunk is a data model that represents a response chunk from the NAT chat streaming API. |
|
ResponseSerializedStep is a data model that represents a serialized step in the NAT chat streaming API. |
|
WebSocketMessageType is an Enum that represents WebSocket Message types. |
|
WorkflowSchemaType is an Enum that represents Workkflow response types. |
|
WebSocketMessageStatus is an Enum that represents the status of a WebSocket message. |
|
str(object='') -> str |
|
For more details, refer to the API documentation: |
|
For more details, refer to the API documentation: |
|
For more details, refer to the API documentation: |
|
For more details, refer to the API documentation: |
|
For more details, refer to the API documentation: |
Functions#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Converts a string to an ChatResponse object |
|
Converts a string to an ChatResponseChunk object |
Module Contents#
- FINISH_REASONS#
- class UserMessageContentRoleType#
-
Enum representing chat message roles in API requests and responses.
Initialize self. See help(type(self)) for accurate signature.
- USER = 'user'#
- ASSISTANT = 'assistant'#
- SYSTEM = 'system'#
- class Request(/, **data: Any)#
Bases:
pydantic.BaseModelRequest is a data model that represents HTTP request attributes.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- class ChatContentType#
-
ChatContentType is an Enum that represents the type of Chat content.
Initialize self. See help(type(self)) for accurate signature.
- TEXT = 'text'#
- IMAGE_URL = 'image_url'#
- INPUT_AUDIO = 'input_audio'#
- class InputAudio(/, **data: Any)#
Bases:
pydantic.BaseModel
- class AudioContent(/, **data: Any)#
Bases:
pydantic.BaseModel- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- type: Literal[ChatContentType]#
- input_audio: InputAudio#
- class ImageContent(/, **data: Any)#
Bases:
pydantic.BaseModel- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- type: Literal[ChatContentType]#
- class TextContent(/, **data: Any)#
Bases:
pydantic.BaseModel- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- type: Literal[ChatContentType]#
- class Security(/, **data: Any)#
Bases:
pydantic.BaseModel- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- UserContent#
- class Message(/, **data: Any)#
Bases:
pydantic.BaseModel
- class ChatRequest(/, **data: Any)#
Bases:
pydantic.BaseModelChatRequest is a data model that represents a request to the NAT chat API. Fully compatible with OpenAI Chat Completions API specification.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- class ChatRequestOrMessage(/, **data: Any)#
Bases:
pydantic.BaseModelChatRequestOrMessageis a data model that represents either a conversation or a string input. This is useful for functions that can handle either type of input.messagesis compatible with the OpenAI Chat Completions API specification.input_messageis a string input that can be used for functions that do not require a conversation.
Note: When
messagesis provided, extra fields are allowed to enable lossless round-trip conversion with ChatRequest. Wheninput_messageis provided, no extra fields are permitted.Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- validate_model()#
- class ChoiceMessage(/, **data: Any)#
Bases:
pydantic.BaseModel- role: UserMessageContentRoleType | None = None#
- class ChoiceDelta(/, **data: Any)#
Bases:
pydantic.BaseModelDelta object for streaming responses (OpenAI-compatible)
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- role: UserMessageContentRoleType | None = None#
- class ChoiceBase(/, **data: Any)#
Bases:
pydantic.BaseModelBase choice model with common fields for both streaming and non-streaming responses
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- class ChatResponseChoice(/, **data: Any)#
Bases:
ChoiceBaseChoice model for non-streaming responses - contains message field
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- message: ChoiceMessage#
- class ChatResponseChunkChoice(/, **data: Any)#
Bases:
ChoiceBaseChoice model for streaming responses - contains delta field
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- delta: ChoiceDelta#
- Choice#
- class Usage(/, **data: Any)#
Bases:
pydantic.BaseModel
- class ResponseSerializable#
Bases:
abc.ABCResponseSerializable is an abstract class that defines the interface for serializing output for the NAT Toolkit chat streaming API.
- class ResponseBaseModelOutput(/, **data: Any)#
Bases:
pydantic.BaseModel,ResponseSerializable
- class ResponseBaseModelIntermediate(/, **data: Any)#
Bases:
pydantic.BaseModel,ResponseSerializable
- class ChatResponse(/, **data: Any)#
Bases:
ResponseBaseModelOutputChatResponse is a data model that represents a response from the NAT chat API. Fully compatible with OpenAI Chat Completions API specification.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- created: datetime.datetime#
- choices: list[ChatResponseChoice]#
- serialize_created(created: datetime.datetime) int#
Serialize datetime to Unix timestamp for OpenAI compatibility
- class ChatResponseChunk(/, **data: Any)#
Bases:
ResponseBaseModelOutputChatResponseChunk is a data model that represents a response chunk from the NAT chat streaming API. Fully compatible with OpenAI Chat Completions API specification.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- choices: list[ChatResponseChunkChoice]#
- created: datetime.datetime#
- serialize_created(created: datetime.datetime) int#
Serialize datetime to Unix timestamp for OpenAI compatibility
- static from_string(
- data: str,
- *,
- id_: str | None = None,
- created: datetime.datetime | None = None,
- model: str | None = None,
- object_: str | None = None,
- static create_streaming_chunk(
- content: str,
- *,
- id_: str | None = None,
- created: datetime.datetime | None = None,
- model: str | None = None,
- role: UserMessageContentRoleType | None = None,
- finish_reason: str | None = None,
- usage: Usage | None = None,
- system_fingerprint: str | None = None,
Create an OpenAI-compatible streaming chunk
- class ResponseIntermediateStep(/, **data: Any)#
Bases:
ResponseBaseModelIntermediateResponseSerializedStep is a data model that represents a serialized step in the NAT chat streaming API.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- class ResponsePayloadOutput(/, **data: Any)#
Bases:
pydantic.BaseModel,ResponseSerializable- payload: Any#
- class GenerateResponse(/, **data: Any)#
Bases:
pydantic.BaseModel- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- class WebSocketMessageType#
-
WebSocketMessageType is an Enum that represents WebSocket Message types.
Initialize self. See help(type(self)) for accurate signature.
- USER_MESSAGE = 'user_message'#
- RESPONSE_MESSAGE = 'system_response_message'#
- INTERMEDIATE_STEP_MESSAGE = 'system_intermediate_message'#
- SYSTEM_INTERACTION_MESSAGE = 'system_interaction_message'#
- USER_INTERACTION_MESSAGE = 'user_interaction_message'#
- ERROR_MESSAGE = 'error_message'#
- class WorkflowSchemaType#
-
WorkflowSchemaType is an Enum that represents Workkflow response types.
Initialize self. See help(type(self)) for accurate signature.
- GENERATE_STREAM = 'generate_stream'#
- CHAT_STREAM = 'chat_stream'#
- GENERATE = 'generate'#
- CHAT = 'chat'#
- class WebSocketMessageStatus#
-
WebSocketMessageStatus is an Enum that represents the status of a WebSocket message.
Initialize self. See help(type(self)) for accurate signature.
- IN_PROGRESS = 'in_progress'#
- COMPLETE = 'complete'#
- class UserMessages(/, **data: Any)#
Bases:
pydantic.BaseModel- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- class UserMessageContent(/, **data: Any)#
Bases:
pydantic.BaseModel- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- messages: list[UserMessages]#
- class User(/, **data: Any)#
Bases:
pydantic.BaseModel- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- class ErrorTypes#
-
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to ‘utf-8’. errors defaults to ‘strict’.
Initialize self. See help(type(self)) for accurate signature.
- UNKNOWN_ERROR = 'unknown_error'#
- INVALID_MESSAGE = 'invalid_message'#
- INVALID_MESSAGE_TYPE = 'invalid_message_type'#
- INVALID_USER_MESSAGE_CONTENT = 'invalid_user_message_content'#
- INVALID_DATA_CONTENT = 'invalid_data_content'#
- class Error(/, **data: Any)#
Bases:
pydantic.BaseModel- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- code: ErrorTypes#
- class WebSocketUserMessage(/, **data: Any)#
Bases:
pydantic.BaseModelFor more details, refer to the API documentation: docs/source/developer_guide/websockets.md
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- type: Literal[WebSocketMessageType]#
- schema_type: WorkflowSchemaType#
- content: UserMessageContent#
- class WebSocketUserInteractionResponseMessage(/, **data: Any)#
Bases:
pydantic.BaseModelFor more details, refer to the API documentation: docs/source/developer_guide/websockets.md
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- type: Literal[WebSocketMessageType]#
- content: UserMessageContent#
- class SystemIntermediateStepContent(/, **data: Any)#
Bases:
pydantic.BaseModel- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- class WebSocketSystemIntermediateStepMessage(/, **data: Any)#
Bases:
pydantic.BaseModelFor more details, refer to the API documentation: docs/source/developer_guide/websockets.md
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- type: Literal[WebSocketMessageType]#
- content: SystemIntermediateStepContent#
- status: WebSocketMessageStatus#
- class SystemResponseContent(/, **data: Any)#
Bases:
pydantic.BaseModel- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- class WebSocketSystemResponseTokenMessage(/, **data: Any)#
Bases:
pydantic.BaseModelFor more details, refer to the API documentation: docs/source/developer_guide/websockets.md
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- type: Literal[WebSocketMessageType, WebSocketMessageType]#
- content: SystemResponseContent | Error | GenerateResponse#
- status: WebSocketMessageStatus#
- classmethod validate_content_by_type(
- value: SystemResponseContent | Error | GenerateResponse,
- info: pydantic_core.core_schema.ValidationInfo,
- class WebSocketSystemInteractionMessage(/, **data: Any)#
Bases:
pydantic.BaseModelFor more details, refer to the API documentation: docs/source/developer_guide/websockets.md
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- type: Literal[WebSocketMessageType]#
- content: nat.data_models.interactive.HumanPrompt#
- status: WebSocketMessageStatus#
- _generate_response_to_str(response: GenerateResponse) str#
- _generate_response_to_chat_response(
- response: GenerateResponse,
- _nat_chat_request_to_string(data: ChatRequest) str#
- _string_to_nat_chat_request(data: str) ChatRequest#
- _chat_request_or_message_to_chat_request(
- data: ChatRequestOrMessage,
- _chat_request_to_chat_request_or_message(
- data: ChatRequest,
- _chat_request_or_message_to_string(data: ChatRequestOrMessage) str#
- _string_to_chat_request_or_message(data: str) ChatRequestOrMessage#
- _nat_chat_response_to_string(data: ChatResponse) str#
- _string_to_nat_chat_response(data: str) ChatResponse#
Converts a string to an ChatResponse object
- _chat_response_chunk_to_string(data: ChatResponseChunk) str#
- _string_to_nat_chat_response_chunk(data: str) ChatResponseChunk#
Converts a string to an ChatResponseChunk object
- AIQChatRequest#
- AIQChoiceMessage#
- AIQChoiceDelta#
- AIQChoice#
- AIQUsage#
- AIQResponseSerializable#
- AIQResponseBaseModelOutput#
- AIQResponseBaseModelIntermediate#
- AIQChatResponse#
- AIQChatResponseChunk#
- AIQResponseIntermediateStep#
- AIQResponsePayloadOutput#
- AIQGenerateResponse#