nat.data_models.api_server#
Attributes#
Classes#
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) |
|
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. |
|
str(object='') -> str |
|
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 |
Converts LangChain AINodeMessageChunk to ChatResponseChunk |
Module Contents#
- FINISH_REASONS#
- class Request(/, **data: Any)#
Bases:
pydantic.BaseModel
Request 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.self
is explicitly positional-only to allowself
as 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.BaseModel
ChatRequest 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.self
is explicitly positional-only to allowself
as a field name.- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict
][pydantic.config.ConfigDict].
- class ChoiceMessage(/, **data: Any)#
Bases:
pydantic.BaseModel
- class ChoiceDelta(/, **data: Any)#
Bases:
pydantic.BaseModel
Delta 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.self
is explicitly positional-only to allowself
as a field name.
- class Choice(/, **data: Any)#
Bases:
pydantic.BaseModel
- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict
][pydantic.config.ConfigDict].
- message: ChoiceMessage | None = None#
- delta: ChoiceDelta | None = None#
- class Usage(/, **data: Any)#
Bases:
pydantic.BaseModel
- class ResponseSerializable#
Bases:
abc.ABC
ResponseSerializable 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:
ResponseBaseModelOutput
ChatResponse 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.self
is explicitly positional-only to allowself
as a field name.- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict
][pydantic.config.ConfigDict].
- created: datetime.datetime#
- serialize_created(created: datetime.datetime) int #
Serialize datetime to Unix timestamp for OpenAI compatibility
- class ChatResponseChunk(/, **data: Any)#
Bases:
ResponseBaseModelOutput
ChatResponseChunk 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.self
is explicitly positional-only to allowself
as a field name.- model_config#
Configuration for the model, should be a dictionary conforming to [
ConfigDict
][pydantic.config.ConfigDict].
- 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: str | 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:
ResponseBaseModelIntermediate
ResponseSerializedStep 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.self
is explicitly positional-only to allowself
as 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 UserMessageContentRoleType#
-
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 sys.getdefaultencoding(). errors defaults to ‘strict’.
Initialize self. See help(type(self)) for accurate signature.
- USER = 'user'#
- ASSISTANT = 'assistant'#
- 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 sys.getdefaultencoding(). 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.BaseModel
For 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.self
is explicitly positional-only to allowself
as 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.BaseModel
For 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.self
is explicitly positional-only to allowself
as 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.BaseModel
For 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.self
is explicitly positional-only to allowself
as 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.BaseModel
For 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.self
is explicitly positional-only to allowself
as 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.BaseModel
For 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.self
is explicitly positional-only to allowself
as 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 #
- _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_to_chat_response_chunk(
- data: ChatResponse,
- _chat_response_chunk_to_string(data: ChatResponseChunk) str #
- _string_to_nat_chat_response_chunk(data: str) ChatResponseChunk #
Converts a string to an ChatResponseChunk object
- _ai_message_chunk_to_nat_chat_response_chunk(
- data,
Converts LangChain AINodeMessageChunk to ChatResponseChunk
- AIQChatRequest#
- AIQChoiceMessage#
- AIQChoiceDelta#
- AIQChoice#
- AIQUsage#
- AIQResponseSerializable#
- AIQResponseBaseModelOutput#
- AIQResponseBaseModelIntermediate#
- AIQChatResponse#
- AIQChatResponseChunk#
- AIQResponseIntermediateStep#
- AIQResponsePayloadOutput#
- AIQGenerateResponse#