mlflow.types
该mlflow.types模块定义了数据类型和实用工具,供其他 mlflow 组件使用,以描述独立于其他框架或语言的接口。
- class mlflow.types.ColSpec(type: Union[mlflow.types.schema.Array, mlflow.types.schema.DataType, mlflow.types.schema.Map, mlflow.types.schema.Object, mlflow.types.schema.AnyType, str], name: Optional[str] = None, required: bool = True)[source]
基类:
object数据集中单个列的名称和类型的说明。
- classmethod from_json_dict(**kwargs)[source]
从一个通过 json 加载的字典反序列化。该字典应包含 type 以及可选的 name 和 required 键。
- property type: mlflow.types.schema.DataType | mlflow.types.schema.Array | mlflow.types.schema.Object | mlflow.types.schema.Map | mlflow.types.schema.AnyType
该列的数据类型。
- class mlflow.types.DataType(value)[source]
基类:
enum.EnumMLflow 数据类型。
- to_numpy() numpy.dtype[source]
获取等效的 numpy 数据类型。
- to_pandas() numpy.dtype[source]
获取等效的 pandas 数据类型。
- to_python()[source]
获取等效的 Python 数据类型。
- class mlflow.types.ParamSchema(params: list[mlflow.types.schema.ParamSpec])[source]
基类:
object适用于模型的参数规范。ParamSchema 表示为
ParamSpec的列表。- classmethod from_json(json_str: str)[source]
从 JSON 字符串反序列化。
- property params: list[mlflow.types.schema.ParamSpec]
将 ParamSchema 表示为 ParamSpec 的列表。
- to_dict() list[dict[str, typing.Any]][source]
序列化为可 JSON 化的字典。
- to_json() str[source]
序列化为 json 字符串。
- class mlflow.types.ParamSpec(name: str, dtype: mlflow.types.schema.DataType | mlflow.types.schema.Object | str, default: Any, shape: Optional[tuple[int, ...]] = None)[source]
基类:
object用于表示模型参数的规范。
- class ParamSpecTypedDict[source]
基类:
TypedDict
- property dtype: mlflow.types.schema.DataType | mlflow.types.schema.Object
参数数据类型。
- classmethod from_json_dict(**kwargs)[source]
从通过 json 加载的字典反序列化。 该字典应包含 name、type 和 default 键。
- classmethod validate_type_and_shape(spec: str, value: Any, value_type: mlflow.types.schema.DataType | mlflow.types.schema.Object, shape: tuple[int, ...] | None)[source]
验证该值具有预期的类型和形状。
- class mlflow.types.Schema(inputs: list[mlflow.types.schema.ColSpec | mlflow.types.schema.TensorSpec])[source]
基类:
object数据集的规范。
模式表示为由
ColSpec或TensorSpec组成的列表。不允许将 ColSpec 和 TensorSpec 混合使用。由模式表示的数据集可以被命名,每个输入必须具有唯一的非空名称。 在
ColSpec的情况下,数据集列可以未命名,使用由其列表索引定义的隐式整数索引。 不允许命名和未命名数据输入的组合。- as_spark_schema()[source]
转换为 Spark schema。如果该 schema 是单个未命名的列,则直接转换为相应的 Spark 数据类型;否则将其作为 struct 返回(缺失的列名以整数序列填充)。TensorSpec 不支持。
- classmethod from_json(json_str: str)[source]
从 JSON 字符串反序列化。
- has_input_names() bool[source]
如果且仅当此 schema 声明了名称时返回 true,否则返回 false。
- input_dict() dict[str, mlflow.types.schema.ColSpec | mlflow.types.schema.TensorSpec][source]
将列名映射到输入,仅当该模式声明了名称。
- input_names() list[str | int][source]
获取数据名称列表;如果模式没有名称,则返回索引范围。
- input_types() list[mlflow.types.schema.DataType | numpy.dtype | mlflow.types.schema.Array | mlflow.types.schema.Object][source]
获取模式中每列的类型。
- input_types_dict() dict[str, mlflow.types.schema.DataType | numpy.dtype | mlflow.types.schema.Array | mlflow.types.schema.Object][source]
将列名映射到类型,当且仅当该模式声明了名称。
- property inputs: list[mlflow.types.schema.ColSpec | mlflow.types.schema.TensorSpec]
定义此架构的数据集的表示。
- is_tensor_spec() bool[source]
当且仅当此 schema 使用 TensorSpec 指定时返回 true
- numpy_types() list[numpy.dtype][source]
方便地将数据类型作为 numpy 类型获取的快捷方式。
- optional_input_names() list[str | int][source]
获取可选数据名称的列表,或者如果模式没有名称,则获取索引范围。
- pandas_types() list[numpy.dtype][source]
以 pandas 类型获取数据类型的便捷方式。TensorSpec 不支持。
- required_input_names() list[str | int][source]
获取所需数据名称的列表,或在 schema 没有名称时获取索引范围。
- to_dict() list[dict[str, typing.Any]][source]
序列化为一个可转换为 JSON 的字典。
- to_json() str[source]
序列化为 json 字符串。
- class mlflow.types.TensorSpec(type: numpy.dtype, shape: tuple[int, ...] | list[int], name: Optional[str] = None)[source]
基类:
object用于表示作为张量存储的数据集的规范。
- classmethod from_json_dict(**kwargs)[source]
从一个 json 加载的字典反序列化。该字典应包含 type 和 tensor-spec 键。
- property type: numpy.dtype
针对21种不同的 numpy 内置类型的唯一字符代码。详见 https://numpy.org/devdocs/reference/generated/numpy.dtype.html#numpy.dtype 获取详细信息。
- class mlflow.types.responses.ResponsesAgentRequest(*, tool_choice: str | mlflow.types.responses_helpers.ToolChoiceFunction | None = None, truncation: str | None = None, max_output_tokens: int | None = None, metadata: dict[str, str] | None = None, parallel_tool_calls: bool | None = None, tools: list[mlflow.types.responses_helpers.Tool] | None = None, reasoning: mlflow.types.responses_helpers.ReasoningParams | None = None, store: bool | None = None, stream: bool | None = None, temperature: float | None = None, text: Optional[Any] = None, top_p: float | None = None, user: str | None = None, input: list[mlflow.types.responses_helpers.Message | mlflow.types.responses_helpers.OutputItem], custom_inputs: dict[str, typing.Any] | None = None, context: mlflow.types.agent.ChatContext | None = None)[source]
用于 ResponsesAgent 的请求对象。
- Parameters
input – 简单的 role 和 content 消息或输出项的列表。示例请参见 https://mlflow.org/docs/latest/llms/responses-agent-intro/#testing-out-your-agent 和 https://mlflow.org/docs/latest/llms/responses-agent-intro/#creating-agent-output。
custom_inputs (Dict[str, Any]) – 一个可选参数,用于向模型提供任意的额外上下文。字典的值必须是 JSON 可序列化的。可选 默认为
Nonecontext (
mlflow.types.agent.ChatContext) – 在聊天端点使用的上下文。包括 conversation_id 和 user_id。 可选 默认值为None
- class mlflow.types.responses.ResponsesAgentResponse(*, tool_choice: str | mlflow.types.responses_helpers.ToolChoiceFunction | None = None, truncation: str | None = None, id: str | None = None, created_at: float | None = None, error: mlflow.types.responses_helpers.ResponseError | None = None, incomplete_details: mlflow.types.responses_helpers.IncompleteDetails | None = None, instructions: str | None = None, metadata: dict[str, str] | None = None, model: str | None = None, object: str = 'response', output: list[mlflow.types.responses_helpers.OutputItem], parallel_tool_calls: bool | None = None, temperature: float | None = None, tools: list[mlflow.types.responses_helpers.Tool] | None = None, top_p: float | None = None, max_output_tokens: int | None = None, previous_response_id: str | None = None, reasoning: mlflow.types.responses_helpers.ReasoningParams | None = None, status: str | None = None, text: Optional[Any] = None, usage: mlflow.types.responses_helpers.ResponseUsage | None = None, user: str | None = None, custom_outputs: dict[str, typing.Any] | None = None)[source]
用于 ResponsesAgent 的 Response 对象。
- Parameters
output – 输出项列表。示例见 https://mlflow.org/docs/latest/llms/responses-agent-intro/#creating-agent-output。
reasoning – 推理参数
用法 – 使用信息
custom_outputs (Dict[str, Any]) – 可选参数,用于提供来自模型的任意额外上下文。字典的值必须是可 JSON 序列化的。 可选, 默认值为
None
- class mlflow.types.responses.ResponsesAgentStreamEvent(*, type: str, custom_outputs: dict[str, typing.Any] | None = None, **extra_data: Any)[source]
用于 ResponsesAgent 的流事件。示例见 https://mlflow.org/docs/latest/llms/responses-agent-intro/#streaming-agent-output
- Parameters
type (str) – 流事件的类型
custom_outputs (Dict[str, Any]) – 一个可选参数,用于提供来自模型的任意额外上下文。字典的值必须是可 JSON 序列化的。 可选,默认值为
None
- class mlflow.types.agent.ChatAgentChunk(*, delta: mlflow.types.agent.ChatAgentMessage, finish_reason: str | None = None, custom_outputs: dict[str, typing.Any] | None = None, usage: mlflow.types.chat.ChatUsage | None = None)[source]
表示 ChatAgent 流式响应中的单个块。
- Parameters
delta – 一个
ChatAgentMessage,表示在构成智能体输出的消息列表中的单个片段。尤其是,客户端应假定该content字段在此ChatAgentMessage中只包含消息内容的一部分,并应根据 ID 在各个片段间聚合消息内容。更多信息可在ChatAgent.predict_stream的 docstring 中找到。finish_reason (str) – 生成停止的原因。 可选 默认为
Nonecustom_outputs (Dict[str, Any]) – 一个可选参数,用于提供来自模型的任意附加上下文。字典的值必须可被 JSON 序列化。 可选,默认值为
Noneusage (
mlflow.types.chat.ChatUsage) – 请求的令牌使用情况 可选, 默认值为 None
- class mlflow.types.agent.ChatAgentMessage(*, role: str, content: str | None = None, name: str | None = None, id: str | None = None, tool_calls: list[mlflow.types.chat.ToolCall] | None = None, tool_call_id: str | None = None, attachments: dict[str, str] | None = None)[source]
ChatAgent 模型请求或响应中的一条消息。
- Parameters
role (str) – 发送消息的实体的角色(例如
"user","system","assistant","tool")。content (str) – 消息的内容。 可选 如果提供了 tool_calls,则可以为
None。name (str) – 发送该消息的实体的名称。 可选 默认值为
Noneid (str) – 消息的 ID。当它是
ChatAgentResponse或ChatAgentChunk的一部分时是必需的。tool_calls (List[
mlflow.types.chat.ToolCall]) – 模型所发出的工具调用列表。 可选 默认为Nonetool_call_id (str) – 该消息所响应的工具调用的 ID。 可选 默认为
Noneattachments (Dict[str, str]) – 一个 attachments 的字典。 可选 默认为
None
- class mlflow.types.agent.ChatAgentRequest(*, messages: list[mlflow.types.agent.ChatAgentMessage], context: mlflow.types.agent.ChatContext | None = None, custom_inputs: dict[str, typing.Any] | None = None, stream: bool | None = False)[source]
ChatAgent 接口请求的格式。
- Parameters
messages – 一个由
ChatAgentMessage组成的列表,将被传递给模型。context (
ChatContext) – 要在聊天端点中使用的上下文。包括 conversation_id 和 user_id。可选,默认为Nonecustom_inputs (Dict[str, Any]) – 一个可选参数,用于向模型提供任意的附加上下文。字典的值必须可被 JSON 序列化。可选 默认值为
Nonestream (bool) – 是否在生成时流式返回响应。可选,默认值为
False
- class mlflow.types.agent.ChatAgentResponse(*, messages: list[mlflow.types.agent.ChatAgentMessage], finish_reason: str | None = None, custom_outputs: dict[str, typing.Any] | None = None, usage: mlflow.types.chat.ChatUsage | None = None)[source]
表示 ChatAgent 的响应。
- Parameters
messages – 一个由模型返回的
ChatAgentMessage列表。finish_reason (str) – 生成停止的原因。 可选 默认为
Nonecustom_outputs (Dict[str, Any]) – 一个可选参数,用于提供来自模型的任意附加上下文。字典的值必须是可 JSON 序列化的。可选,默认值为
Noneusage (
mlflow.types.chat.ChatUsage) – 请求的 token 使用情况 可选,默认为 None
- class mlflow.types.agent.ChatContext(*, conversation_id: str | None = None, user_id: str | None = None)[source]
在 ChatAgent 端点中使用的上下文。
- Parameters
conversation_id (str) – 会话的 ID。 可选 默认为
Noneuser_id (str) – 用户的 ID。 可选 默认为
None
- class mlflow.types.llm.ChatChoice(message: mlflow.types.llm.ChatMessage, index: int = 0, finish_reason: str = 'stop', logprobs: Optional[mlflow.types.llm.ChatChoiceLogProbs] = None)[source]
由模型生成的单条聊天回复。 参考: https://platform.openai.com/docs/api-reference/chat/object
- Parameters
message (
ChatMessage) – 生成的消息。index (int) – 响应在响应列表中的索引。默认值为
0finish_reason (str) – 生成停止的原因。可选,默认值为
"stop"logprobs (
ChatChoiceLogProbs) – 该选择的对数概率信息。 可选, 默认为None
- class mlflow.types.llm.ChatChoiceDelta(role: str | None = 'assistant', content: Optional[str] = None, refusal: Optional[str] = None, name: Optional[str] = None, tool_calls: Optional[list[mlflow.types.llm.ToolCall]] = None)[source]
聊天响应中的流式消息增量。
- Parameters
role (str) – 发送该消息的实体的角色(例如
"user","system","assistant","tool")。可选,默认值为"assistant"这是可选项,因为 OpenAI 客户端可以显式返回 None 作为角色content (str) – 要流式传输的新令牌的内容 Optional 在最后的增量块或提供了 refusal 或 tool_calls 时可以为
Nonerefusal (str) – 拒绝消息的内容。 可选 在提供拒绝响应时提供。
name (str) – 发送该消息的实体的名称。 可选.
tool_calls (List[
ToolCall]) – 模型发起的工具调用列表。 可选,默认值为None
- class mlflow.types.llm.ChatChoiceLogProbs(content: Optional[list[mlflow.types.llm.TokenLogProb]] = None)[source]
有关该选择的对数概率信息。
- Parameters
content – 一个包含对数概率信息的消息内容标记的列表。
- class mlflow.types.llm.ChatChunkChoice(delta: mlflow.types.llm.ChatChoiceDelta, index: int = 0, finish_reason: Optional[str] = None, logprobs: Optional[mlflow.types.llm.ChatChoiceLogProbs] = None)[source]
模型生成的单个聊天响应块。 参考: https://platform.openai.com/docs/api-reference/chat/streaming
- Parameters
index (int) – 响应在响应列表中的索引。 默认值为
0delta (
ChatChoiceDelta) – 生成的流式块消息。finish_reason (str) – 生成停止的原因。 可选,默认为
Nonelogprobs (
ChatChoiceLogProbs) – 该选项的对数概率信息。 可选,默认为None
- class mlflow.types.llm.ChatCompletionChunk(choices: list[mlflow.types.llm.ChatChunkChoice], usage: Optional[mlflow.types.llm.TokenUsageStats] = None, id: Optional[str] = None, model: Optional[str] = None, object: str = 'chat.completion.chunk', created: int = <factory>, custom_outputs: Optional[dict[str, typing.Any]] = None)[source]
由 chat endpoint 返回的流式分块。 ref: https://platform.openai.com/docs/api-reference/chat/streaming
- Parameters
choices (List[
ChatChunkChoice]) – 一个由ChatChunkChoice对象组成的列表,这些对象包含流式响应生成的片段usage (
TokenUsageStats) – 一个描述请求使用的令牌的对象。 可选,默认为None。id (str) – 响应的 ID。 可选,默认值为
Nonemodel (str) – 使用的模型的名称。 可选,默认值为
Noneobject (str) – 对象类型。默认为 ‘chat.completion.chunk’
created (int) – 响应创建的时间。可选,默认为当前时间。
custom_outputs (Dict[str, Any]) – 一个可以包含任意附加上下文的字段。 字典的值必须是可 JSON 序列化的。 可选,默认值为
None
- class mlflow.types.llm.ChatCompletionRequest(temperature: float = 1.0, max_tokens: Optional[int] = None, stop: Optional[list[str]] = None, n: int = 1, stream: bool = False, top_p: Optional[float] = None, top_k: Optional[int] = None, frequency_penalty: Optional[float] = None, presence_penalty: Optional[float] = None, custom_inputs: Optional[dict[str, typing.Any]] = None, tools: Optional[list[mlflow.types.llm.ToolDefinition]] = None, messages: list[mlflow.types.llm.ChatMessage] = <factory>)[source]
chat 端点所期望的请求对象的格式。
- Parameters
messages (List[
ChatMessage]) – 传递给模型的ChatMessage列表。可选,默认值为空列表 ([])temperature (float) – 用于在推理期间控制随机性和创造性的参数。 可选,默认值为
1.0max_tokens (int) – 要生成的新 tokens 的最大数量。 Optional,默认值为
None(无限制)stop (List[str]) – 一个用于在生成时遇到这些令牌就停止的令牌列表。 可选,默认值为
Nonen (int) – 要生成的响应数量。可选, 默认为
1stream (bool) – 是否在生成时流式返回响应。可选,默认值为
Falsetop_p (float) – 一个可选参数,用于控制带温度的采样,模型只考虑具有 top_p 概率质量的令牌的结果。例如,0.1 表示只考虑构成前 10% 概率质量的令牌。
top_k (int) – 一个可选参数,用于将词汇表大小减少到前 k 个标记(按其概率降序排列)。
frequency_penalty – (float): 一个可选参数,可取正值或负值,正值会根据当前文本中已有的出现频率对新生成的标记进行惩罚,从而降低模型逐字重复同一行的可能性。
presence_penalty – (float):一个可选参数,可取正值或负值。正值会根据新令牌是否已出现在当前文本中对其进行惩罚,从而增加模型谈论新主题的可能性。
custom_inputs (Dict[str, Any]) – 一个可选参数,用于向模型提供任意的附加上下文。该字典的值必须可以被 JSON 序列化。
tools (List[
ToolDefinition]) – 一个可选的工具列表,可由模型调用。
警告
在即将发布的 MLflow 版本中,temperature、n 和 stream 的默认值将被移除。请在代码中显式提供这些值(如有需要)。
- class mlflow.types.llm.ChatCompletionResponse(choices: list[mlflow.types.llm.ChatChoice], usage: Optional[mlflow.types.llm.TokenUsageStats] = None, id: Optional[str] = None, model: Optional[str] = None, object: str = 'chat.completion', created: int = <factory>, custom_outputs: Optional[dict[str, typing.Any]] = None)[source]
由 chat endpoint 返回的完整响应对象。
- Parameters
choices (List[
ChatChoice]) – 一个包含生成的响应的ChatChoice对象列表usage (
TokenUsageStats) – 一个描述请求所使用的令牌的对象。 可选,默认为None。id (str) – 响应的 ID。 可选,默认值为
Nonemodel (str) – 使用的模型的名称。 可选,默认值为
Noneobject (str) – 对象类型。默认值为 ‘chat.completion’
created (int) – 响应创建的时间。可选,默认为当前时间。
custom_outputs (Dict[str, Any]) – 一个可以包含任意附加上下文的字段。 字典的值必须可被 JSON 序列化。 可选,默认为
None
- class mlflow.types.llm.ChatMessage(role: str, content: Optional[str] = None, refusal: Optional[str] = None, name: Optional[str] = None, tool_calls: Optional[list[mlflow.types.llm.ToolCall]] = None, tool_call_id: Optional[str] = None)[source]
聊天请求或响应中的一条消息。
- Parameters
role (str) – 发送该消息的实体的角色(例如
"user","system","assistant","tool")。content (str) – 消息的内容。 可选 如果提供了 refusal 或 tool_calls,则可以是
None。refusal (str) – 拒绝消息的内容。 可选 在提供拒绝响应时提供。
name (str) – 发送消息的实体的名称。 可选.
tool_calls (List[
ToolCall]) – 模型发起的工具调用列表。 可选,默认值为Nonetool_call_id (str) – 该消息所响应的工具调用的 ID。 可选 默认为
None
- class mlflow.types.llm.ChatParams(temperature: float = 1.0, max_tokens: Optional[int] = None, stop: Optional[list[str]] = None, n: int = 1, stream: bool = False, top_p: Optional[float] = None, top_k: Optional[int] = None, frequency_penalty: Optional[float] = None, presence_penalty: Optional[float] = None, custom_inputs: Optional[dict[str, typing.Any]] = None, tools: Optional[list[mlflow.types.llm.ToolDefinition]] = None)[source]
用于聊天推理的常用参数
- Parameters
temperature (float) – 用于在推理过程中控制随机性和创造力的参数。可选,默认值为
1.0max_tokens (int) – 生成的新令牌的最大数量。 可选,默认值为
None(无限制)stop (List[str]) – 一个在遇到这些标记时停止生成的标记列表。 可选,默认值为
Nonen (int) – 要生成的响应数量。 可选,默认为
1stream (bool) – 是否在生成时流式返回响应。可选,默认值为
Falsetop_p (float) – 一个可选参数,用于配合temperature控制采样,模型只会考虑具有 top_p 概率质量的标记的结果。例如,0.1 表示只考虑构成前 10% 概率质量的标记。
top_k (int) – 一个可选参数,用于将词汇表大小减少到前 k 个令牌(按其概率降序排序)。
frequency_penalty – (float): 可选参数,取正值或负值;正值会根据到目前为止文本中已出现的频率对新令牌进行惩罚,从而降低模型逐字重复同一行的可能性。
presence_penalty – (float): 一个可选参数,可为正值或负值。正值会根据新标记是否已出现在当前文本中对其进行惩罚,从而增加模型谈论新主题的可能性。
custom_inputs (Dict[str, Any]) – 一个可选参数,用于向模型提供任意的附加上下文。该字典的值必须可以被 JSON 序列化。
tools (List[
ToolDefinition]) – 一个可选的工具列表,可被模型调用。
警告
在即将发布的 MLflow 版本中,temperature、n 和 stream 的默认值将被移除。请在代码中显式提供这些值(如有需要)。
- classmethod keys() set[str][source]
返回 dataclass 的键
- class mlflow.types.llm.FunctionToolCallArguments(name: str, arguments: str)[source]
模型进行的函数工具调用的参数。
- Parameters
arguments (str) – 应该传递给该工具的参数的 JSON 字符串。
name (str) – 被调用的工具的名称。
- class mlflow.types.llm.FunctionToolDefinition(name: str, description: Optional[str] = None, parameters: Optional[mlflow.types.llm.ToolParamsSchema] = None, strict: bool = False)[source]
函数工具的定义(当前唯一受支持的工具类型)。
- Parameters
name (str) – 工具的名称。
description (str) – 描述该工具的功能,以及应如何使用。 可选, 默认为
Noneparameters – 参数名称到其定义的映射。如果未提供,此项表示一个无参数的函数。可选,默认值为
Nonestrict (bool) – 一个标志,表示模型是否应严格遵循所提供的 schema。
- to_tool_definition()[source]
将此封装到 ToolDefinition 中的便捷函数
- class mlflow.types.llm.ParamProperty(type: Literal['string', 'number', 'integer', 'object', 'array', 'boolean', 'null'], description: Optional[str] = None, enum: Optional[list[str]] = None, items: Optional[mlflow.types.llm.ParamType] = None)[source]
函数定义中的单个参数。
- Parameters
type (str) – 参数的类型。可能的取值为 “string”, “number”, “integer”, “object”, “array”, “boolean”, 或 “null”,符合 JSON Schema 规范。
description (str) – 参数的描述。 可选,默认为
Noneenum (List[str]) – 用于约束该参数的可能取值。 可选,默认值为
Noneitems (
ParamProperty) – 如果该参数是array类型,此字段可用于指定其元素的类型。 可选,默认为None
- class mlflow.types.llm.ParamType(type: Literal['string', 'number', 'integer', 'object', 'array', 'boolean', 'null'])[source]
- class mlflow.types.llm.TokenLogProb(token: str, logprob: float, top_logprobs: list[mlflow.types.llm.TopTokenLogProb], bytes: Optional[list[int]] = None)[source]
带有对数概率信息的消息内容令牌。
- Parameters
token – 该 token。
logprob – 该标记的对数概率,如果它位于最可能的前20个标记之内。否则,使用值 -9999.0 来表示该标记非常不可能。
bytes – 一个整数列表,表示该标记的 UTF-8 字节表示。当字符由多个标记表示且必须将它们的字节表示合并以生成正确的文本表示时非常有用。如果该标记没有字节表示,则可以为 null。
top_logprobs – 在该令牌位置最可能的令牌及其对数概率的列表。在极少数情况下,返回的 top_logprobs 可能少于请求的数量。
- class mlflow.types.llm.TokenUsageStats(prompt_tokens: Optional[int] = None, completion_tokens: Optional[int] = None, total_tokens: Optional[int] = None)[source]
有关推理过程中使用的 tokens 数量的统计。
- Parameters
prompt_tokens (int) – 提示中的令牌数量。 可选,默认值为
Nonecompletion_tokens (int) – 生成的完成中的标记数。 可选,默认为
Nonetotal_tokens (int) – 已使用的令牌总数。 可选,默认值为
None
- class mlflow.types.llm.ToolCall(function: mlflow.types.llm.FunctionToolCallArguments, id: str = <factory>, type: str = 'function')[source]
由模型发起的工具调用。
- Parameters
function (
FunctionToolCallArguments) – 函数工具调用的参数。id (str) – 工具调用的 ID。默认为随机的 UUID。
type (str) – 对象的类型。默认值为 “function”。
- class mlflow.types.llm.ToolDefinition(function: mlflow.types.llm.FunctionToolDefinition, type: Literal['function'] = 'function')[source]
可由模型调用的工具的定义。
- Parameters
function (
FunctionToolDefinition) – 函数工具的定义。type (str) – 该工具的类型。目前仅支持 “function”。
- class mlflow.types.llm.ToolParamsSchema(properties: dict[str, mlflow.types.llm.ParamProperty], type: Literal['object'] = 'object', required: Optional[list[str]] = None, additionalProperties: Optional[bool] = None)[source]
工具参数定义。
- Parameters
properties (Dict[str,
ParamProperty]) – 参数名到其定义的映射。type (str) – 参数的类型。Currently only “object” is supported.
required (List[str]) – 必需参数名称的列表。 可选,默认为
NoneadditionalProperties (bool) – 是否允许对象中存在额外属性。 可选,默认值为
None
- class mlflow.types.llm.TopTokenLogProb(token: str, logprob: float, bytes: Optional[list[int]] = None)[source]
Token及其对数概率。
- Parameters
token – 令牌。
logprob – 该标记的对数概率,如果它位于最可能的前20个标记中。否则,使用值 -9999.0 来表示该标记非常不可能。
bytes – 表示该标记的 UTF-8 字节表示的一组整数。适用于字符由多个标记表示且必须将它们的字节表示合并以生成正确文本表示的情况。如果该标记没有字节表示,则可以为 null。
- class mlflow.types.chat.AudioContentPart(*, type: Literal['input_audio'], input_audio: mlflow.types.chat.InputAudio)[source]
- class mlflow.types.chat.BaseModel[source]
- class mlflow.types.chat.BaseRequestPayload(*, temperature: float = 0.0, n: int = 1, stop: list[str] | None = None, max_tokens: int | None = None, stream: bool | None = None, stream_options: dict[str, typing.Any] | None = None, model: str | None = None)[source]
用于聊天补全和补全端点的常用参数。
- class mlflow.types.chat.ChatChoice(*, index: int, message: mlflow.types.chat.ChatMessage, finish_reason: str | None = None)[source]
- class mlflow.types.chat.ChatChoiceDelta(*, role: str | None = None, content: str | None = None)[source]
- class mlflow.types.chat.ChatChunkChoice(*, index: int, finish_reason: str | None = None, delta: mlflow.types.chat.ChatChoiceDelta)[source]
- class mlflow.types.chat.ChatCompletionChunk(*, id: str | None = None, object: str = 'chat.completion.chunk', created: int, model: str, choices: list[mlflow.types.chat.ChatChunkChoice])[source]
聊天补全流响应的一部分。
- class mlflow.types.chat.ChatCompletionRequest(*, temperature: float = 0.0, n: int = 1, stop: list[str] | None = None, max_tokens: int | None = None, stream: bool | None = None, stream_options: dict[str, typing.Any] | None = None, model: str | None = None, messages: list[mlflow.types.chat.ChatMessage], tools: list[mlflow.types.chat.ChatTool] | None = None)[source]
对 chat completion API 的请求。
必须与 OpenAI’s Chat Completion API 兼容。 https://platform.openai.com/docs/api-reference/chat
- class mlflow.types.chat.ChatCompletionResponse(*, id: str | None = None, object: str = 'chat.completion', created: int, model: str, choices: list[mlflow.types.chat.ChatChoice], usage: mlflow.types.chat.ChatUsage)[source]
来自 chat completion API 的响应。
必须与 OpenAI’s Chat Completion API 兼容。 https://platform.openai.com/docs/api-reference/chat
- class mlflow.types.chat.ChatMessage(*, role: str, content: Optional[str | list[typing.Annotated[mlflow.types.chat.TextContentPart | mlflow.types.chat.ImageContentPart | mlflow.types.chat.AudioContentPart, FieldInfo(annotation=NoneType, required=True, discriminator='type')]]] = None, tool_calls: list[mlflow.types.chat.ToolCall] | None = None, refusal: str | None = None, tool_call_id: str | None = None)[source]
一次聊天请求。
content可以是一个字符串,或一个内容部分的数组。内容部分是下列之一:
- class mlflow.types.chat.ChatTool(*, type: Literal['function'], function: mlflow.types.chat.FunctionToolDefinition | None = None)[source]
传递给 chat completion API 的工具定义。
参考: https://platform.openai.com/docs/guides/function-calling
- class mlflow.types.chat.ChatUsage(*, prompt_tokens: int | None = None, completion_tokens: int | None = None, total_tokens: int | None = None)[source]
- class mlflow.types.chat.Function(*, name: str, arguments: str)[source]
- class mlflow.types.chat.FunctionParams(*, properties: dict[str, mlflow.types.chat.ParamProperty], type: Literal['object'] = 'object', required: list[str] | None = None, additionalProperties: bool | None = None)[source]
- class mlflow.types.chat.FunctionToolDefinition(*, name: str, description: str | None = None, parameters: mlflow.types.chat.FunctionParams | None = None, strict: bool | None = None)[source]
- class mlflow.types.chat.ImageContentPart(*, type: Literal['image_url'], image_url: mlflow.types.chat.ImageUrl)[source]
- class mlflow.types.chat.ImageUrl(*, url: str, detail: Optional[Literal['auto', 'low', 'high']] = None)[source]
表示图片的 URL。
- url
可以是图像的 URL 或 base64 编码的数据。 https://platform.openai.com/docs/guides/vision?lang=curl#uploading-base64-encoded-images
- Type
字符串
- detail
模型接收图像时的分辨率级别。 例如,当设置为“low”时,模型将看到被调整为512x512像素的图像,这会消耗更少的 tokens。在 OpenAI 中,这是可选的,默认值为“auto”。 https://platform.openai.com/docs/guides/vision?lang=curl#low-or-high-fidelity-image-understanding
- Type
Optional[Literal[‘auto’, ‘low’, ‘high’]]
- class mlflow.types.chat.InputAudio(*, data: str, format: Literal['wav', 'mp3'])[source]
- class mlflow.types.chat.ParamProperty(*, type: Optional[Literal['string', 'number', 'integer', 'object', 'array', 'boolean', 'null']] = None, description: str | None = None, enum: list[str | int | float | bool] | None = None, items: mlflow.types.chat.ParamType | None = None)[source]
OpenAI 使用 JSON Schema (https://json-schema.org/) 来定义函数参数。请参阅 OpenAI 函数调用参考:https://platform.openai.com/docs/guides/function-calling?&api-mode=responses#defining-functions
JSON Schema 的 enum 支持任何 JSON 类型(字符串、整数、浮点数、布尔、null、数组、对象),但我们为了实际使用场景和 API 安全,将其限制为基本标量类型。
- class mlflow.types.chat.ParamType(*, type: Optional[Literal['string', 'number', 'integer', 'object', 'array', 'boolean', 'null']] = None)[source]
- class mlflow.types.chat.TextContentPart(*, type: Literal['text'], text: str)[source]
- class mlflow.types.chat.ToolCall(*, id: str, type: str = 'function', function: mlflow.types.chat.Function)[source]
- class mlflow.types.schema.AnyType[source]
- to_dict()[source]
Dictionary representation of the object.
- class mlflow.types.schema.Array(dtype: Union[mlflow.types.schema.Array, mlflow.types.schema.DataType, mlflow.types.schema.Map, mlflow.types.schema.Object, mlflow.types.schema.AnyType, str])[source]
用于表示可转换为 JSON 的数组的规范。
- classmethod from_json_dict(**kwargs)[source]
从一个通过 json 加载的字典反序列化。 该字典应包含 type 和 items 键。 示例: {“type”: “array”, “items”: “string”}
- to_dict()[source]
Dictionary representation of the object.
- class mlflow.types.schema.Map(value_type: Union[mlflow.types.schema.Array, mlflow.types.schema.DataType, mlflow.types.schema.Map, mlflow.types.schema.Object, mlflow.types.schema.AnyType, str])[source]
用于表示键为字符串类型并且可转换为 JSON 的映射的规范。
- classmethod from_json_dict(**kwargs)[source]
从已通过 json 加载的字典反序列化。 该字典应包含 type 和 values 键。 示例: {“type”: “map”, “values”: “string”}
- to_dict()[source]
Dictionary representation of the object.
- class mlflow.types.schema.Object(properties: list[mlflow.types.schema.Property])[source]
用于表示可转换为 json 的对象的规范。
- classmethod from_json_dict(**kwargs)[source]
从 json 加载的字典中反序列化。该字典应包含 type 和 properties 键。示例: {“type”: “object”, “properties”: {“property_name”: {“type”: “string”}}}
- property properties: list[mlflow.types.schema.Property]
对象属性列表
- to_dict()[source]
Dictionary representation of the object.
- class mlflow.types.schema.Property(name: str, dtype: Union[mlflow.types.schema.Array, mlflow.types.schema.DataType, mlflow.types.schema.Map, mlflow.types.schema.Object, mlflow.types.schema.AnyType, str], required: bool = True)[source]
用于表示可转换为 JSON 的对象属性的规范。
- property dtype: DataType | 'Array' | 'Object' | 'Map'
属性的数据类型。
- classmethod from_json_dict(**kwargs)[source]
从一个 json 加载的字典中反序列化。 该字典应当只包含一个键,即name,其值应当是一个包含type和 可选required键的字典。 示例: {“property_name”: {“type”: “string”, “required”: True}}
- to_dict()[source]
Dictionary representation of the object.