completions
ChatCompletionsEndpointController
dataclass
Bases: NexosAIAPIEndpointController
Controller for handling chat completions endpoint of NexosAI.
Source code in src/nexosapi/api/controller.py
RequestManager
Bases: _RequestManager
with_model
staticmethod
with_model(model: str) -> RequestManager
Sets the model to be used for the chat completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The model to be used for the chat completion. |
required |
Returns:
| Type | Description |
|---|---|
RequestManager
|
The updated request object with the model set. |
with_search_engine_tool
staticmethod
with_search_engine_tool(
options: WebSearchToolOptions | dict[str, Any],
) -> RequestManager
Sets the search engine to be used for the chat completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
WebSearchToolOptions | dict[str, Any]
|
Optional search options to be used with the search engine. |
required |
Returns:
| Type | Description |
|---|---|
RequestManager
|
The updated request object with the search engine set. |
Source code in src/nexosapi/api/endpoints/chat/completions.py
with_rag_tool
staticmethod
with_rag_tool(
options: RAGToolOptions | dict[str, Any],
) -> RequestManager
Sets the RAG tool to be used for the chat completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
RAGToolOptions | dict[str, Any]
|
Additional options for the RAG tool, if any. |
required |
Returns:
| Type | Description |
|---|---|
RequestManager
|
The updated request object with the RAG tool set. |
Source code in src/nexosapi/api/endpoints/chat/completions.py
with_ocr_tool
staticmethod
with_ocr_tool(
options: OCRToolOptions | dict[str, Any],
) -> RequestManager
Sets the OCR tool to be used for the chat completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
OCRToolOptions | dict[str, Any]
|
Additional options for the OCR tool, if any. |
required |
Returns:
| Type | Description |
|---|---|
RequestManager
|
The updated request object with the OCR tool set. |
with_parallel_tool_calls
staticmethod
with_parallel_tool_calls(
enabled: bool = True,
) -> RequestManager
Enables or disables parallel tool calls for the chat completion request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enabled
|
bool
|
A boolean indicating whether to enable parallel tool calls. |
True
|
Returns:
| Type | Description |
|---|---|
RequestManager
|
The updated request object with the parallel tool calls set. |
Source code in src/nexosapi/api/endpoints/chat/completions.py
with_thinking
staticmethod
with_thinking(
config: ChatThinkingModeConfiguration | None = None,
disabled: bool = False,
) -> RequestManager
Enables or disables thinking for the chat completion request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
ChatThinkingModeConfiguration | None
|
The configuration for the thinking mode, which includes parameters like "enabled", "max_steps", etc. |
None
|
disabled
|
bool
|
A boolean indicating whether to disable thinking mode. |
False
|
Returns:
| Type | Description |
|---|---|
RequestManager
|
The updated request object with the thinking set. |
Source code in src/nexosapi/api/endpoints/chat/completions.py
with_tool_choice
staticmethod
with_tool_choice(tool_choice: str) -> RequestManager
Sets the tool choice for the chat completion request e.g. "auto" or to specific function name using "name:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_choice
|
str
|
The tool choice to be set for the request. |
required |
Returns:
| Type | Description |
|---|---|
RequestManager
|
The updated request object with the tool choice set. |
add_image_to_last_message
staticmethod
add_image_to_last_message(
image_url: str | None = None, image: bytes | None = None
) -> RequestManager
Adds an image to the last message in the chat completion request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_url
|
str | None
|
The URL of the image to be included in the request. |
None
|
image
|
bytes | None
|
The image data to be included in the request. |
None
|
Returns:
| Type | Description |
|---|---|
RequestManager
|
The updated request object with the image included. |
Source code in src/nexosapi/api/endpoints/chat/completions.py
add_text_message
staticmethod
add_text_message(
text: str, role: str = "user"
) -> RequestManager
Adds a text message to the chat completion request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The content of the message, which can include text, images, etc. |
required |
role
|
str
|
The role of the message sender (e.g., "user", "assistant"). Defaults to "user". |
'user'
|
Returns:
| Type | Description |
|---|---|
RequestManager
|
The updated request object with the new message added. |
set_response_structure
staticmethod
set_response_structure(
schema: dict[str, Any] | type[BaseModel],
) -> RequestManager
Sets the response structure for the chat completion request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
dict[str, Any] | type[BaseModel]
|
The desired response schema (e.g., a Pydantic model). |
required |
Returns:
| Type | Description |
|---|---|
RequestManager
|
The updated request object with the response structure set. |
get_verb_from_endpoint
get_path_from_endpoint
prepare
prepare(
data: ChatCompletionsRequest | dict[str, Any],
) -> RequestManager
Prepare the request data by initializing the pending request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ChatCompletionsRequest | dict[str, Any]
|
The data to be included in the request. |
required |
Returns:
| Type | Description |
|---|---|
RequestManager
|
The current instance of the RequestManager for method chaining. |
Source code in src/nexosapi/api/endpoints/chat/completions.py
dump
send
async
send() -> ChatCompletionsResponse
Call the endpoint with the provided request data.
Returns:
| Type | Description |
|---|---|
ChatCompletionsResponse
|
The response data from the endpoint. |
reload_last
reload_last() -> RequestManager
Reload the last request to reuse it for the next operation.
Returns:
| Type | Description |
|---|---|
RequestManager
|
The current instance of the RequestManager for method chaining. |
Source code in src/nexosapi/api/endpoints/chat/completions.py
Operations
with_model
staticmethod
with_model(
request: ChatCompletionsRequest, model: str
) -> ChatCompletionsRequest
Sets the model to be used for the chat completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ChatCompletionsRequest
|
The request object containing the chat completion parameters. |
required |
model
|
str
|
The model to be used for the chat completion. |
required |
Returns:
| Type | Description |
|---|---|
ChatCompletionsRequest
|
The updated request object with the model set. |
Source code in src/nexosapi/api/endpoints/chat/completions.py
with_search_engine_tool
staticmethod
with_search_engine_tool(
request: ChatCompletionsRequest,
options: WebSearchToolOptions | dict[str, Any],
) -> ChatCompletionsRequest
Sets the search engine to be used for the chat completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ChatCompletionsRequest
|
The request object containing the chat completion parameters. |
required |
options
|
WebSearchToolOptions | dict[str, Any]
|
Optional search options to be used with the search engine. |
required |
Returns:
| Type | Description |
|---|---|
ChatCompletionsRequest
|
The updated request object with the search engine set. |
Source code in src/nexosapi/api/endpoints/chat/completions.py
with_rag_tool
staticmethod
with_rag_tool(
request: ChatCompletionsRequest,
options: RAGToolOptions | dict[str, Any],
) -> ChatCompletionsRequest
Sets the RAG tool to be used for the chat completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ChatCompletionsRequest
|
The request object containing the chat completion parameters. |
required |
options
|
RAGToolOptions | dict[str, Any]
|
Additional options for the RAG tool, if any. |
required |
Returns:
| Type | Description |
|---|---|
ChatCompletionsRequest
|
The updated request object with the RAG tool set. |
Source code in src/nexosapi/api/endpoints/chat/completions.py
with_ocr_tool
staticmethod
with_ocr_tool(
request: ChatCompletionsRequest,
options: OCRToolOptions | dict[str, Any],
) -> ChatCompletionsRequest
Sets the OCR tool to be used for the chat completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ChatCompletionsRequest
|
The request object containing the chat completion parameters. |
required |
options
|
OCRToolOptions | dict[str, Any]
|
Additional options for the OCR tool, if any. |
required |
Returns:
| Type | Description |
|---|---|
ChatCompletionsRequest
|
The updated request object with the OCR tool set. |
Source code in src/nexosapi/api/endpoints/chat/completions.py
with_parallel_tool_calls
staticmethod
with_parallel_tool_calls(
request: ChatCompletionsRequest, enabled: bool = True
) -> ChatCompletionsRequest
Enables or disables parallel tool calls for the chat completion request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ChatCompletionsRequest
|
The request object containing the chat completion parameters. |
required |
enabled
|
bool
|
A boolean indicating whether to enable parallel tool calls. |
True
|
Returns:
| Type | Description |
|---|---|
ChatCompletionsRequest
|
The updated request object with the parallel tool calls set. |
Source code in src/nexosapi/api/endpoints/chat/completions.py
with_thinking
staticmethod
with_thinking(
request: ChatCompletionsRequest,
config: ChatThinkingModeConfiguration | None = None,
disabled: bool = False,
) -> ChatCompletionsRequest
Enables or disables thinking for the chat completion request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ChatCompletionsRequest
|
The request object containing the chat completion parameters. |
required |
config
|
ChatThinkingModeConfiguration | None
|
The configuration for the thinking mode, which includes parameters like "enabled", "max_steps", etc. |
None
|
disabled
|
bool
|
A boolean indicating whether to disable thinking mode. |
False
|
Returns:
| Type | Description |
|---|---|
ChatCompletionsRequest
|
The updated request object with the thinking set. |
Source code in src/nexosapi/api/endpoints/chat/completions.py
with_tool_choice
staticmethod
with_tool_choice(
request: ChatCompletionsRequest, tool_choice: str
) -> ChatCompletionsRequest
Sets the tool choice for the chat completion request e.g. "auto" or to specific function name using "name:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ChatCompletionsRequest
|
The request object containing the chat completion parameters. |
required |
tool_choice
|
str
|
The tool choice to be set for the request. |
required |
Returns:
| Type | Description |
|---|---|
ChatCompletionsRequest
|
The updated request object with the tool choice set. |
Source code in src/nexosapi/api/endpoints/chat/completions.py
add_image_to_last_message
staticmethod
add_image_to_last_message(
request: ChatCompletionsRequest,
image_url: str | None = None,
image: bytes | None = None,
) -> ChatCompletionsRequest
Adds an image to the last message in the chat completion request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ChatCompletionsRequest
|
The request object containing the chat completion parameters. |
required |
image_url
|
str | None
|
The URL of the image to be included in the request. |
None
|
image
|
bytes | None
|
The image data to be included in the request. |
None
|
Returns:
| Type | Description |
|---|---|
ChatCompletionsRequest
|
The updated request object with the image included. |
Source code in src/nexosapi/api/endpoints/chat/completions.py
add_text_message
staticmethod
add_text_message(
request: ChatCompletionsRequest,
text: str,
role: str = "user",
) -> ChatCompletionsRequest
Adds a text message to the chat completion request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ChatCompletionsRequest
|
The request object containing the chat completion parameters. |
required |
text
|
str
|
The content of the message, which can include text, images, etc. |
required |
role
|
str
|
The role of the message sender (e.g., "user", "assistant"). Defaults to "user". |
'user'
|
Returns:
| Type | Description |
|---|---|
ChatCompletionsRequest
|
The updated request object with the new message added. |
Source code in src/nexosapi/api/endpoints/chat/completions.py
set_response_structure
staticmethod
set_response_structure(
request: ChatCompletionsRequest,
schema: dict[str, Any] | type[BaseModel],
) -> ChatCompletionsRequest
Sets the response structure for the chat completion request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ChatCompletionsRequest
|
The request object containing the chat completion parameters. |
required |
schema
|
dict[str, Any] | type[BaseModel]
|
The desired response schema (e.g., a Pydantic model). |
required |
Returns:
| Type | Description |
|---|---|
ChatCompletionsRequest
|
The updated request object with the response structure set. |
Source code in src/nexosapi/api/endpoints/chat/completions.py
create_web_search_tool
create_web_search_tool(
options: WebSearchToolOptions | None = None,
) -> dict[str, Any]
Creates a definition for a web search tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
WebSearchToolOptions | None
|
Additional options for the web search tool, if any. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary representing the web search tool definition. |
Source code in src/nexosapi/api/endpoints/chat/completions.py
create_ocr_tool
Creates a definition for an OCR tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
OCRToolOptions
|
Additional options for the OCR tool, if any. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary representing the OCR tool definition. |