pydantic_ai.profiles
描述了如何构建和处理对特定模型或模型家族的请求和响应,以获得最佳结果,这与所使用的模型和提供商类无关。
源代码位于 pydantic_ai_slim/pydantic_ai/profiles/__init__.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
default_structured_output_mode 类属性
实例属性
default_structured_output_mode: StructuredOutputMode = (
"tool"
)
用于模型的默认结构化输出模式。
prompted_output_template 类属性
实例属性
prompted_output_template: str = dedent(
"\n Always respond with a JSON object that's compatible with this schema:\n\n {schema}\n\n Don't include any text or Markdown fencing before or after.\n "
)
用于提示结构化输出的指令模板。'{schema}' 占位符将被替换为输出的JSON模式。
json_schema_transformer 类属性
实例属性
json_schema_transformer: (
type[JsonSchemaTransformer] | None
) = None
用于使工具和结构化输出的JSON模式与模型兼容的转换器。
thinking_tags 类属性
实例属性
用于指示模型输出中思考部分的标签。默认为 ('
ignore_streamed_leading_whitespace 类属性
实例属性
ignore_streamed_leading_whitespace: bool = False
在流式传输响应时是否忽略前导空白。
This is a workaround for models that emit `<think>
或在工具调用之前有一个空的文本部分(例如 Ollama + Qwen3),我们不希望在使用
run_stream且
output_type为有效的
str`时将其视为最终结果。
This is currently only used by `OpenAIChatModel`, `HuggingFaceModel`, and `GroqModel`.
from_profile 类方法
from_profile(profile: ModelProfile | None) -> Self
从一个ModelProfile实例构建一个ModelProfile子类的实例。
源代码位于 pydantic_ai_slim/pydantic_ai/profiles/__init__.py
58 59 60 61 62 63 |
|
更新 (update)
update(profile: ModelProfile | None) -> Self
使用另一个ModelProfile实例中的非默认值来更新此ModelProfile(子类)实例。
源代码位于 pydantic_ai_slim/pydantic_ai/profiles/__init__.py
65 66 67 68 69 70 71 72 73 74 75 |
|
OpenAIModelProfile 数据类
基类:ModelProfile
用于与 OpenAIChatModel
一起使用的模型的配置文件。
所有字段必须以 openai_
为前缀,以便您可以将它们与其他模型合并。
源代码位于 pydantic_ai_slim/pydantic_ai/profiles/openai.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
openai_supports_strict_tool_definition 类属性
实例属性
openai_supports_strict_tool_definition: bool = True
如果与OpenAI“兼容”的API不支持严格的工具定义,提供商或用户可以设置此项。
openai_supports_sampling_settings 类属性
实例属性
openai_supports_sampling_settings: bool = True
关闭此项,以避免向不支持采样设置(如 temperature
和 top_p
)的模型发送这些设置,例如OpenAI的o系列推理模型。
openai_unsupported_model_settings 类属性
实例属性
模型不支持的模型设置列表。
openai_supports_tool_choice_required 类属性
实例属性
openai_supports_tool_choice_required: bool = True
提供商是否在请求负载中接受 tool_choice='required'
的值。
openai_system_prompt_role 类属性
实例属性
openai_system_prompt_role: OpenAISystemPromptRole | None = (
None
)
用于系统提示消息的角色。如果未提供,默认为 'system'
。
openai_model_profile
openai_model_profile(model_name: str) -> ModelProfile
获取OpenAI模型的模型配置文件。
源代码位于 pydantic_ai_slim/pydantic_ai/profiles/openai.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
OpenAIJsonSchemaTransformer 数据类
基类:JsonSchemaTransformer
递归处理模式,使其与OpenAI的严格模式兼容。
更多细节请参阅 https://platform.openai.com/docs/guides/function-calling?api-mode=responses#strict-mode,但这基本上只需要:* 参数中每个对象的 additionalProperties
必须设置为 false * properties 中的所有字段必须标记为 required
源代码位于 pydantic_ai_slim/pydantic_ai/profiles/openai.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
|
anthropic_model_profile
anthropic_model_profile(
model_name: str,
) -> ModelProfile | None
获取Anthropic模型的模型配置文件。
源代码位于 pydantic_ai_slim/pydantic_ai/profiles/anthropic.py
6 7 8 |
|
google_model_profile
google_model_profile(
model_name: str,
) -> ModelProfile | None
获取Google模型的模型配置文件。
源代码位于 pydantic_ai_slim/pydantic_ai/profiles/google.py
11 12 13 14 15 16 17 |
|
GoogleJsonSchemaTransformer
基类:JsonSchemaTransformer
将Pydantic的JSON模式转换为适用于Gemini的格式。
Gemini 支持 OpenAPI v3.0.3 的一个子集。
具体来说: * gemini不允许设置 title
关键字 * gemini不允许 $defs
— 我们需要尽可能地内联定义
源代码位于 pydantic_ai_slim/pydantic_ai/profiles/google.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
meta_model_profile
meta_model_profile(model_name: str) -> ModelProfile | None
获取Meta模型的模型配置文件。
源代码位于 pydantic_ai_slim/pydantic_ai/profiles/meta.py
6 7 8 |
|
amazon_model_profile
amazon_model_profile(
model_name: str,
) -> ModelProfile | None
获取Amazon模型的模型配置文件。
源代码位于 pydantic_ai_slim/pydantic_ai/profiles/amazon.py
6 7 8 |
|
deepseek_model_profile
deepseek_model_profile(
model_name: str,
) -> ModelProfile | None
获取DeepSeek模型的模型配置文件。
源代码位于 pydantic_ai_slim/pydantic_ai/profiles/deepseek.py
6 7 8 |
|
grok_model_profile
grok_model_profile(model_name: str) -> ModelProfile | None
获取Grok模型的模型配置文件。
源代码位于 pydantic_ai_slim/pydantic_ai/profiles/grok.py
6 7 8 |
|
mistral_model_profile
mistral_model_profile(
model_name: str,
) -> ModelProfile | None
获取Mistral模型的模型配置文件。
源代码位于 pydantic_ai_slim/pydantic_ai/profiles/mistral.py
6 7 8 |
|
qwen_model_profile
qwen_model_profile(model_name: str) -> ModelProfile | None
获取Qwen模型的模型配置文件。
源代码位于 pydantic_ai_slim/pydantic_ai/profiles/qwen.py
7 8 9 10 11 12 13 14 15 16 17 18 19 |
|