nndeploy.api_llm.llm_chat¶
Functions
|
Call an OpenAI-compatible Chat Completions endpoint. |
Classes
|
LLM chat node (OpenAI-compatible) Input: str / list[messages] / dict({"messages":[...]}) Output: str (model generated text) |
|
- class nndeploy.api_llm.llm_chat.LLMParams(api_base: str = 'https://api.openai.com', api_key_env: str = 'OPENAI_API_KEY', model: str = 'gpt-4o-mini', temperature: float = 0.2, max_tokens: int = 512, system_prompt: str = 'You are a helpful assistant.', timeout_s: float = 60.0, retry: int = 2, retry_backoff_s: float = 1.2, stream: bool = False, response_json_mode: bool = False, json_schema: Optional[dict] = None)[源代码]¶
基类:
object- __init__(api_base: str = 'https://api.openai.com', api_key_env: str = 'OPENAI_API_KEY', model: str = 'gpt-4o-mini', temperature: float = 0.2, max_tokens: int = 512, system_prompt: str = 'You are a helpful assistant.', timeout_s: float = 60.0, retry: int = 2, retry_backoff_s: float = 1.2, stream: bool = False, response_json_mode: bool = False, json_schema: Optional[dict] = None) None¶
- nndeploy.api_llm.llm_chat.call_llm(params: LLMParams, messages: list, *, api_key_override: str = None, node_for_interrupt: Optional[Node] = None, emit_usage_to_log: bool = True, stream_print: bool = False, proxies: Optional[dict] = None, verify: Optional[Union[bool, str]] = None) str[源代码]¶
Call an OpenAI-compatible Chat Completions endpoint. - Supports non-stream and stream modes. - Respects 429 Retry-After; uses exponential backoff with jitter. - Logs usage if available. Returns the final concatenated content as a string.
- class nndeploy.api_llm.llm_chat.LLMChatNode(name, inputs: list[nndeploy.dag.edge.Edge] = None, outputs: list[nndeploy.dag.edge.Edge] = None)[源代码]¶
基类:
NodeLLM chat node (OpenAI-compatible) Input: str / list[messages] / dict({“messages”:[…]}) Output: str (model generated text)
- __init__(name, inputs: list[nndeploy.dag.edge.Edge] = None, outputs: list[nndeploy.dag.edge.Edge] = None)[源代码]¶
Initialize the node.
- 参数:
name – The name of the node
inputs – List of input edges or None
outputs – List of output edges or None
- clear_dropdown_params()¶
Clear the list of dropdown parameters.
- clear_io_params()¶
Clear the list of IO parameters.
- clear_required_params()¶
Clear the list of required parameters.
- clear_ui_params()¶
Clear the list of UI parameters.
- create_internal_output_edge(self: nndeploy._nndeploy_internal.dag.Node, name: str) nndeploy::dag::Edge¶
- default_param(self: nndeploy._nndeploy_internal.dag.Node) nndeploy._nndeploy_internal.base.Status¶
- deinit()¶
Deinitialize the node and clean up resources.
- forward(*args, **kwargs)¶
Overloaded function.
forward(self: nndeploy._nndeploy_internal.dag.Node, inputs: list[nndeploy::dag::Edge]) -> list[nndeploy::dag::Edge]
forward(self: nndeploy._nndeploy_internal.dag.Node) -> list[nndeploy::dag::Edge]
forward(self: nndeploy._nndeploy_internal.dag.Node, input: nndeploy::dag::Edge) -> list[nndeploy::dag::Edge]
- get_all_input()¶
Get all inputs of the node.
- get_all_output()¶
Get all outputs of the node.
- get_composite_node(self: nndeploy._nndeploy_internal.dag.Node) nndeploy::dag::CompositeNode¶
- get_device_type() DeviceType¶
Get the device type of the node.
- get_graph()¶
Get the parent graph of this node.
- get_input_type_info() EdgeTypeInfo¶
Get the input type information of the node.
- get_io_type()¶
Get the I/O type of the node.
- get_node_type()¶
Get the node type.
- get_output_type_info() EdgeTypeInfo¶
Get the output type information of the node.
- get_parallel_type() ParallelType¶
Get the parallel execution type of the node.
- get_param()¶
Get the parameters of the node.
- get_real_outputs_name()¶
Get the actual output names.
- get_run_status() RunStatus¶
Get the run status of the node.
- get_stream()¶
Get the execution stream of the node.
- init()¶
Initialize the node.
- is_inputs_changed(self: nndeploy._nndeploy_internal.dag.Node, inputs: list[nndeploy::dag::Edge]) bool¶
- set_composite_node(self: nndeploy._nndeploy_internal.dag.Node, composite_node: nndeploy::dag::CompositeNode) nndeploy._nndeploy_internal.base.Status¶
- set_device_type(device_type: DeviceType)¶
Set the device type for node execution.
- set_graph(graph)¶
Set the parent graph for this node.
- set_input_name(self: nndeploy._nndeploy_internal.dag.Node, name: str, index: int = 0) nndeploy._nndeploy_internal.base.Status¶
- set_input_names(self: nndeploy._nndeploy_internal.dag.Node, names: list[str]) nndeploy._nndeploy_internal.base.Status¶
- set_input_type(input_type: type, desc: str = '')¶
Set the input type for the node.
- 参数:
input_type – The input type
- 返回:
Status code
- set_input_type_info(input_type_info: EdgeTypeInfo, desc: str = '')¶
Set the input type information for the node.
- set_inputs(inputs)¶
Set all inputs for the node.
- set_io_type(io_type)¶
Set the I/O type for the node.
- set_node_type(node_type)¶
Set the node type.
- set_output_data(output, index: int = 0, is_external: bool = True)¶
Set output data at the specified index.
- set_output_name(self: nndeploy._nndeploy_internal.dag.Node, name: str, index: int = 0) nndeploy._nndeploy_internal.base.Status¶
- set_output_names(self: nndeploy._nndeploy_internal.dag.Node, names: list[str]) nndeploy._nndeploy_internal.base.Status¶
- set_output_type_info(output_type_info: EdgeTypeInfo, desc: str = '')¶
Set the output type information for the node.
- set_outputs(outputs)¶
Set all outputs for the node.
- set_parallel_type(parallel_type: ParallelType)¶
Set the parallel execution type for the node.
- set_param(param)¶
Set the parameters for the node.
- set_stream(stream)¶
Set the execution stream for the node.
- to_static_graph(self: nndeploy._nndeploy_internal.dag.Node) nndeploy._nndeploy_internal.base.Status¶
- update_input()¶
Update the input data for the node.
- class nndeploy.api_llm.llm_chat.LLMChatNodeCreator[源代码]¶
基类:
NodeCreator- create_node(name: str, inputs: list[nndeploy.dag.edge.Edge], outputs: list[nndeploy.dag.edge.Edge])[源代码]¶
Create a new node instance.
This method must be implemented by subclasses.
- 参数:
name – The name of the node
inputs – List of input edges
outputs – List of output edges
- 返回:
The created node instance