ChatMessageRequest 類別
請求傳送聊天紀錄到 MCP 平台的有效載荷。
此模型代表發送至MCP平台聊天歷史端點以進行威脅防護分析的完整請求體。 內容包括當前的對話、背景和歷史訊息。
該模型使用欄位別名來序列化為 camelCase JSON 格式,符合 MCP 平台 API 的要求。
建構函式
pydantic model ChatMessageRequest
僅限關鍵字的參數
| 名稱 | Description |
|---|---|
|
conversationId
必要
|
|
|
messageId
必要
|
|
|
userMessage
必要
|
|
|
chatHistory
必要
|
|
範例
>>> from microsoft_agents_a365.tooling.models import ChatHistoryMessage
>>> request = ChatMessageRequest(
... conversation_id="conv-123",
... message_id="msg-456",
... user_message="What is the weather today?",
... chat_history=[
... ChatHistoryMessage(role="user", content="Hello"),
... ChatHistoryMessage(role="assistant", content="Hi there!"),
... ]
... )
>>> # Serialize to camelCase JSON
>>> json_dict = request.model_dump(by_alias=True)
>>> print(json_dict["conversationId"])
'conv-123'
方法
| __init__ |
透過解析並驗證關鍵字參數的輸入資料來建立新模型。 Raise [ValidationError][pydantic_core。ValidationError] 表示輸入資料無法被驗證以形成有效的模型。 Self 明確地表示位置性,僅允許 Self 作為場名。 |
| __new__ | |
| construct | |
| copy |
回傳模型副本。 !!! 警告:「已棄用」此方法現已棄用;用 model_copy 吧。 如果需要 包含 或 排除,請使用:
|
| dict | |
| from_orm | |
| json | |
| model_construct |
建立一個新的 Model 類別實例,並取得經過驗證的資料。 建立新的 模型設定指令 ,並 pydantic_fields_set 由受信任或預先驗證的資料。 預設值會被尊重,但不會進行其他驗證。 !!! 注意 model_construct() 通常會遵守所提供模型的 model_config.extra 設定。 也就是說,如果 model_config.extra == '允許」,則所有額外的傳遞值都會加入模型實例的 dict 和 pydantic_extra 欄位。 如果 model_config.extra == 'ignore'( 預設值),則所有額外傳遞的值都會被忽略。 由於呼叫 model_construct()不會進行驗證,因此有 model_config.extra == 「forbid」 不會因傳遞額外值而出錯,但這些值會被忽略。 |
| model_copy |
!!! 摘要「使用文件」 model_copy 回傳模型副本。 !!! 注意底層實例的 [dict][object.DICT] 屬性被複製。 如果你把東西放在模型欄位上方,可能會有意想不到的副作用(例如 [cached properties][functools.cached_property])。 |
| model_dump |
!!! 摘要「使用文件」 model_dump 產生模型的字典表示,並可選擇指定要包含或排除哪些欄位。 |
| model_dump_json |
!!! 摘要「使用文件」 model_dump_json 使用 Pydantic 的 to_json 方法產生模型的 JSON 表示。 |
| model_json_schema |
為模型類別產生 JSON 架構。 |
| model_parametrized_name |
計算泛類參數化時的類別名稱。 此方法可被覆寫,以實現通用基底模型的自訂命名方案。 |
| model_post_init |
在 init 和 model_construct 後,會覆寫此方法以進行額外的初始化。 如果你想做需要整個模型初始化的驗證,這很有用。 |
| model_rebuild |
試著重建模型的 pydantic-core 架構。 當其中一個註解是 ForwardRef,且在初次建立結構時無法解決,且自動重建失敗時,這可能是必要的。 |
| model_validate |
驗證一個讀心模型實例。 |
| model_validate_json |
!!! abstract “Usage Documentation” JSON 解析 將給定的 JSON 資料與 Pydantic 模型進行驗證。 |
| model_validate_strings |
用字串資料與 Pydantic 模型驗證給定物件。 |
| not_empty |
驗證字串欄位不是空的或只有空白。 |
| parse_file | |
| parse_obj | |
| parse_raw | |
| schema | |
| schema_json | |
| update_forward_refs | |
| validate |
__init__
__new__
__new__(**kwargs)
construct
copy
回傳模型副本。
!!! 警告:「已棄用」此方法現已棄用;用 model_copy 吧。
如果需要 包含 或 排除,請使用:
python {test="skip" lint="skip"} data = self.model_dump(include=include, exclude=exclude, round_trip=True) data = {**data, **(update or {})} copied = self.model_validate(data)
copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: Dict[str, Any] | None = None, deep: bool = False) -> Self
參數
| 名稱 | Description |
|---|---|
|
include
必要
|
<xref:AbstractSetIntStr> | <xref:MappingIntStrAny> | None
可選的集合或映射,指定複製模型中應包含哪些欄位。 |
|
exclude
必要
|
<xref:AbstractSetIntStr> | <xref:MappingIntStrAny> | None
可選的集合或映射,指定複製模型中應排除哪些欄位。 |
|
update
必要
|
可選的場值對字典,以覆寫複製模型中的場值。 |
|
deep
必要
|
若為真,則為 Pydantic 模型的場值將被深度複製。 |
僅限關鍵字的參數
| 名稱 | Description |
|---|---|
|
include
|
預設值: None
|
|
exclude
|
預設值: None
|
|
update
|
預設值: None
|
|
deep
|
預設值: False
|
傳回
| 類型 | Description |
|---|---|
|
模型副本,包含包含、排除及依規定更新的欄位。 |
dict
dict(*, include: set[int] | set[str] | Mapping[int, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None = None, exclude: set[int] | set[str] | Mapping[int, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) -> Dict[str, Any]
參數
| 名稱 | Description |
|---|---|
|
include
必要
|
set[int] | set[str] | Mapping[int, set[int] | set[str] | Mapping[int, <xref:IncEx> | bool] | Mapping[str, <xref:IncEx> | bool] | bool] | Mapping[str, set[int] | set[str] | Mapping[int, <xref:IncEx> | bool] | Mapping[str, <xref:IncEx> | bool] | bool] | None
|
|
exclude
必要
|
set[int] | set[str] | Mapping[int, set[int] | set[str] | Mapping[int, <xref:IncEx> | bool] | Mapping[str, <xref:IncEx> | bool] | bool] | Mapping[str, set[int] | set[str] | Mapping[int, <xref:IncEx> | bool] | Mapping[str, <xref:IncEx> | bool] | bool] | None
|
|
by_alias
必要
|
|
|
exclude_unset
必要
|
|
|
exclude_defaults
必要
|
|
|
exclude_none
必要
|
|
僅限關鍵字的參數
| 名稱 | Description |
|---|---|
|
include
|
預設值: None
|
|
exclude
|
預設值: None
|
|
by_alias
|
預設值: False
|
|
exclude_unset
|
預設值: False
|
|
exclude_defaults
|
預設值: False
|
|
exclude_none
|
預設值: False
|
傳回
| 類型 | Description |
|---|---|
json
json(*, include: set[int] | set[str] | Mapping[int, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None = None, exclude: set[int] | set[str] | Mapping[int, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = PydanticUndefined, models_as_dict: bool = PydanticUndefined, **dumps_kwargs: Any) -> str
參數
| 名稱 | Description |
|---|---|
|
include
必要
|
set[int] | set[str] | Mapping[int, set[int] | set[str] | Mapping[int, <xref:IncEx> | bool] | Mapping[str, <xref:IncEx> | bool] | bool] | Mapping[str, set[int] | set[str] | Mapping[int, <xref:IncEx> | bool] | Mapping[str, <xref:IncEx> | bool] | bool] | None
|
|
exclude
必要
|
set[int] | set[str] | Mapping[int, set[int] | set[str] | Mapping[int, <xref:IncEx> | bool] | Mapping[str, <xref:IncEx> | bool] | bool] | Mapping[str, set[int] | set[str] | Mapping[int, <xref:IncEx> | bool] | Mapping[str, <xref:IncEx> | bool] | bool] | None
|
|
by_alias
必要
|
|
|
exclude_unset
必要
|
|
|
exclude_defaults
必要
|
|
|
exclude_none
必要
|
|
|
encoder
必要
|
|
|
models_as_dict
必要
|
|
|
dumps_kwargs
必要
|
|
僅限關鍵字的參數
| 名稱 | Description |
|---|---|
|
include
|
預設值: None
|
|
exclude
|
預設值: None
|
|
by_alias
|
預設值: False
|
|
exclude_unset
|
預設值: False
|
|
exclude_defaults
|
預設值: False
|
|
exclude_none
|
預設值: False
|
|
encoder
|
預設值: PydanticUndefined
|
|
models_as_dict
|
預設值: PydanticUndefined
|
傳回
| 類型 | Description |
|---|---|
model_construct
建立一個新的 Model 類別實例,並取得經過驗證的資料。
建立新的 模型設定指令 ,並 pydantic_fields_set 由受信任或預先驗證的資料。 預設值會被尊重,但不會進行其他驗證。
!!! 注意 model_construct() 通常會遵守所提供模型的 model_config.extra 設定。 也就是說,如果 model_config.extra == '允許」,則所有額外的傳遞值都會加入模型實例的 dict 和 pydantic_extra 欄位。 如果 model_config.extra == 'ignore'( 預設值),則所有額外傳遞的值都會被忽略。 由於呼叫 model_construct()不會進行驗證,因此有 model_config.extra == 「forbid」 不會因傳遞額外值而出錯,但這些值會被忽略。
model_construct(_fields_set: set[str] | None = None, **values: Any) -> Self
參數
| 名稱 | Description |
|---|---|
|
_fields_set
|
一組欄位名稱,最初在實例化時明確設定。 若提供,則直接用於[model_fields_set][意想音。BaseModel.model_fields_set] 屬性。 否則,將使用 值 參數中的欄位名稱。 預設值: None
|
|
values
必要
|
受信任或預先驗證的資料字典。 |
傳回
| 類型 | Description |
|---|---|
|
一個新的 Model 類別實例,並帶有經過驗證的資料。 |
model_copy
!!! 摘要「使用文件」 model_copy
回傳模型副本。
!!! 注意底層實例的 [dict][object.DICT] 屬性被複製。 如果你把東西放在模型欄位上方,可能會有意想不到的副作用(例如 [cached properties][functools.cached_property])。
model_copy(*, update: Mapping[str, Any] | None = None, deep: bool = False) -> Self
參數
| 名稱 | Description |
|---|---|
|
update
必要
|
新模型中要更改或新增的數值。 注意:在建立新模型前,資料並未進行驗證。 你應該相信這些數據。 |
|
deep
必要
|
設 為 True ,以建立模型的深度複製。 |
僅限關鍵字的參數
| 名稱 | Description |
|---|---|
|
update
|
預設值: None
|
|
deep
|
預設值: False
|
傳回
| 類型 | Description |
|---|---|
|
新模型實例。 |
model_dump
!!! 摘要「使用文件」 model_dump
產生模型的字典表示,並可選擇指定要包含或排除哪些欄位。
model_dump(*, mode: Literal['json', 'python'] | str = 'python', include: set[int] | set[str] | Mapping[int, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None = None, exclude: set[int] | set[str] | Mapping[int, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False, polymorphic_serialization: bool | None = None) -> dict[str, Any]
參數
| 名稱 | Description |
|---|---|
|
mode
必要
|
Literal['json', 'python'] | str
to_python應該以什麼模式運行。 若模式為 'json',輸出只會包含可序列化的 JSON 型別。 若模式為「python」,輸出可能包含不可 JSON 序列化的 Python 物件。 |
|
include
必要
|
set[int] | set[str] | Mapping[int, set[int] | set[str] | Mapping[int, <xref:IncEx> | bool] | Mapping[str, <xref:IncEx> | bool] | bool] | Mapping[str, set[int] | set[str] | Mapping[int, <xref:IncEx> | bool] | Mapping[str, <xref:IncEx> | bool] | bool] | None
一組欄位要包含在輸出中。 |
|
exclude
必要
|
set[int] | set[str] | Mapping[int, set[int] | set[str] | Mapping[int, <xref:IncEx> | bool] | Mapping[str, <xref:IncEx> | bool] | bool] | Mapping[str, set[int] | set[str] | Mapping[int, <xref:IncEx> | bool] | Mapping[str, <xref:IncEx> | bool] | bool] | None
一組欄位用來排除輸出。 |
|
context
必要
|
補充說明給序列器。 |
|
by_alias
必要
|
如果定義了,是否要在字典鍵中使用欄位的別名。 |
|
exclude_unset
必要
|
是否要排除尚未明確設定的欄位。 |
|
exclude_defaults
必要
|
是否要排除設定為預設值的欄位。 |
|
exclude_none
必要
|
是否要排除值為 None 的欄位。 |
|
exclude_computed_fields
必要
|
是否要排除計算欄位。 雖然這對往返很有用,但通常建議改用專用 的 round_trip 參數。 |
|
round_trip
必要
|
若為真,傾出的值應作為非冪等元型別(如 Json[T])的有效輸入。 |
|
warnings
必要
|
如何處理序列化錯誤。 False/“none” 會忽略這些錯誤,True/“warn” 會記錄錯誤,“error” 會產生 [PydanticSerializationError][pydantic_core。PydanticSerializationError。 |
|
fallback
必要
|
一個在遇到未知值時呼叫的函式。 若未提供,則會顯示 [PydanticSerializationError][pydantic_core。PydanticSerializationError] 錯誤會被觸發。 |
|
serialize_as_any
必要
|
是否要序列化欄位,並採用鴨式序列化行為。 |
|
polymorphic_serialization
必要
|
是否要使用此呼叫使用模型與資料類別多態序列化。 |
僅限關鍵字的參數
| 名稱 | Description |
|---|---|
|
mode
|
預設值: 'python'
|
|
include
|
預設值: None
|
|
exclude
|
預設值: None
|
|
context
|
預設值: None
|
|
by_alias
|
預設值: None
|
|
exclude_unset
|
預設值: False
|
|
exclude_defaults
|
預設值: False
|
|
exclude_none
|
預設值: False
|
|
exclude_computed_fields
|
預設值: False
|
|
round_trip
|
預設值: False
|
|
warnings
|
預設值: True
|
|
fallback
|
預設值: None
|
|
serialize_as_any
|
預設值: False
|
|
polymorphic_serialization
|
預設值: None
|
傳回
| 類型 | Description |
|---|---|
|
模型的字典表示。 |
model_dump_json
!!! 摘要「使用文件」 model_dump_json
使用 Pydantic 的 to_json 方法產生模型的 JSON 表示。
model_dump_json(*, indent: int | None = None, ensure_ascii: bool = False, include: set[int] | set[str] | Mapping[int, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None = None, exclude: set[int] | set[str] | Mapping[int, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False, polymorphic_serialization: bool | None = None) -> str
參數
| 名稱 | Description |
|---|---|
|
indent
必要
|
在 JSON 輸出中使用縮排。 若通過 N,輸出將趨於緊湊。 |
|
ensure_ascii
必要
|
若 為 True,則輸出必定包含所有非 ASCII 字元逃逸。 若 為 False (預設值),這些字元輸出為 as-is。 |
|
include
必要
|
set[int] | set[str] | Mapping[int, set[int] | set[str] | Mapping[int, <xref:IncEx> | bool] | Mapping[str, <xref:IncEx> | bool] | bool] | Mapping[str, set[int] | set[str] | Mapping[int, <xref:IncEx> | bool] | Mapping[str, <xref:IncEx> | bool] | bool] | None
欄位要包含在 JSON 輸出中。 |
|
exclude
必要
|
set[int] | set[str] | Mapping[int, set[int] | set[str] | Mapping[int, <xref:IncEx> | bool] | Mapping[str, <xref:IncEx> | bool] | bool] | Mapping[str, set[int] | set[str] | Mapping[int, <xref:IncEx> | bool] | Mapping[str, <xref:IncEx> | bool] | bool] | None
欄位要從 JSON 輸出中排除。 |
|
context
必要
|
補充說明給序列器。 |
|
by_alias
必要
|
是否要用欄位別名序列化。 |
|
exclude_unset
必要
|
是否要排除尚未明確設定的欄位。 |
|
exclude_defaults
必要
|
是否要排除設定為預設值的欄位。 |
|
exclude_none
必要
|
是否要排除值為 None 的欄位。 |
|
exclude_computed_fields
必要
|
是否要排除計算欄位。 雖然這對往返很有用,但通常建議改用專用 的 round_trip 參數。 |
|
round_trip
必要
|
若為真,傾出的值應作為非冪等元型別(如 Json[T])的有效輸入。 |
|
warnings
必要
|
如何處理序列化錯誤。 False/“none” 會忽略這些錯誤,True/“warn” 會記錄錯誤,“error” 會產生 [PydanticSerializationError][pydantic_core。PydanticSerializationError。 |
|
fallback
必要
|
一個在遇到未知值時呼叫的函式。 若未提供,則會顯示 [PydanticSerializationError][pydantic_core。PydanticSerializationError] 錯誤會被觸發。 |
|
serialize_as_any
必要
|
是否要序列化欄位,並採用鴨式序列化行為。 |
|
polymorphic_serialization
必要
|
是否要使用此呼叫使用模型與資料類別多態序列化。 |
僅限關鍵字的參數
| 名稱 | Description |
|---|---|
|
indent
|
預設值: None
|
|
ensure_ascii
|
預設值: False
|
|
include
|
預設值: None
|
|
exclude
|
預設值: None
|
|
context
|
預設值: None
|
|
by_alias
|
預設值: None
|
|
exclude_unset
|
預設值: False
|
|
exclude_defaults
|
預設值: False
|
|
exclude_none
|
預設值: False
|
|
exclude_computed_fields
|
預設值: False
|
|
round_trip
|
預設值: False
|
|
warnings
|
預設值: True
|
|
fallback
|
預設值: None
|
|
serialize_as_any
|
預設值: False
|
|
polymorphic_serialization
|
預設值: None
|
傳回
| 類型 | Description |
|---|---|
|
模型的 JSON 字串表示法。 |
model_json_schema
為模型類別產生 JSON 架構。
model_json_schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema, mode: Literal['validation', 'serialization'] = 'validation', *, union_format: Literal['any_of', 'primitive_type_array'] = 'any_of') -> dict[str, Any]
參數
| 名稱 | Description |
|---|---|
|
by_alias
|
是否使用屬性別名。 預設值: True
|
|
ref_template
|
參考範本。 預設值: DEFAULT_REF_TEMPLATE
|
|
union_format
必要
|
Literal['any_of', 'primitive_type_array']
|
|
schema_generator
|
type[<xref:pydantic.json_schema.GenerateJsonSchema>]
若要覆寫用來生成 JSON 結構的邏輯,作為 GenerateJsonSchema 的子類別,並加以修改 預設值: GenerateJsonSchema
|
|
mode
|
Literal['validation', 'serialization']
產生模式的模式。 預設值: 'validation'
|
僅限關鍵字的參數
| 名稱 | Description |
|---|---|
|
union_format
|
預設值: 'any_of'
|
傳回
| 類型 | Description |
|---|---|
|
給定模型類別的 JSON 架構。 |
model_parametrized_name
計算泛類參數化時的類別名稱。
此方法可被覆寫,以實現通用基底模型的自訂命名方案。
model_parametrized_name(params: tuple[type[Any], ...]) -> str
參數
| 名稱 | Description |
|---|---|
|
params
必要
|
類別的類型元組。 給定一個具有兩個型別變數的通用類別 Model ,以及一個具體模型 Model[str, int],值 (str, int) 會傳遞給 參數。 |
傳回
| 類型 | Description |
|---|---|
|
字串代表新的類別,將 參數 作為型別變數傳遞給 cls 。 |
例外狀況
| 類型 | Description |
|---|---|
|
在嘗試為非通用模型產生具體名稱時提出。 |
model_post_init
model_rebuild
試著重建模型的 pydantic-core 架構。
當其中一個註解是 ForwardRef,且在初次建立結構時無法解決,且自動重建失敗時,這可能是必要的。
model_rebuild(*, force: bool = False, raise_errors: bool = True, _parent_namespace_depth: int = 2, _types_namespace: MappingNamespace | None = None) -> bool | None
參數
| 名稱 | Description |
|---|---|
|
force
必要
|
是否強制重建模型結構,預設為 False。 |
|
raise_errors
必要
|
是否要提出錯誤,預設為 True。 |
|
_parent_namespace_depth
必要
|
父命名空間的深度層級預設為 2。 |
|
_types_namespace
必要
|
<xref:MappingNamespace> | None
類型命名空間預設為 None。 |
僅限關鍵字的參數
| 名稱 | Description |
|---|---|
|
force
|
預設值: False
|
|
raise_errors
|
預設值: True
|
|
_parent_namespace_depth
|
預設值: 2
|
|
_types_namespace
|
預設值: None
|
傳回
| 類型 | Description |
|---|---|
|
回傳:若結構已經「完成」且不需要重建,則無。 若 需 重建,則返回 True (重建成功),否則 False。 |
model_validate
驗證一個讀心模型實例。
model_validate(obj: Any, *, strict: bool | None = None, extra: Literal['allow', 'ignore', 'forbid'] | None = None, from_attributes: bool | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
參數
| 名稱 | Description |
|---|---|
|
obj
必要
|
要驗證的對象。 |
|
strict
必要
|
是否要嚴格執行類型。 |
|
extra
必要
|
Literal['allow', 'ignore', 'forbid'] | None
在模型驗證過程中,是否應該忽略、允許或禁止額外資料。 參見[額外 配置值][pydantic。詳情請參考 ConfigDict.extra]。 |
|
from_attributes
必要
|
是否要從物件屬性中擷取資料。 |
|
context
必要
|
補充說明,供驗證者參考。 |
|
by_alias
必要
|
在驗證輸入資料時是否使用欄位的別名。 |
|
by_name
必要
|
是否在驗證輸入資料時使用欄位名稱。 |
僅限關鍵字的參數
| 名稱 | Description |
|---|---|
|
strict
|
預設值: None
|
|
extra
|
預設值: None
|
|
from_attributes
|
預設值: None
|
|
context
|
預設值: None
|
|
by_alias
|
預設值: None
|
|
by_name
|
預設值: None
|
傳回
| 類型 | Description |
|---|---|
|
驗證過的模型實例。 |
例外狀況
| 類型 | Description |
|---|---|
|
ValidationError
|
如果物件無法被驗證。 |
model_validate_json
!!! abstract “Usage Documentation” JSON 解析
將給定的 JSON 資料與 Pydantic 模型進行驗證。
model_validate_json(json_data: str | bytes | bytearray, *, strict: bool | None = None, extra: Literal['allow', 'ignore', 'forbid'] | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
參數
| 名稱 | Description |
|---|---|
|
json_data
必要
|
用來驗證 JSON 資料。 |
|
strict
必要
|
是否要嚴格執行類型。 |
|
extra
必要
|
Literal['allow', 'ignore', 'forbid'] | None
在模型驗證過程中,是否應該忽略、允許或禁止額外資料。 參見[額外 配置值][pydantic。詳情請參考 ConfigDict.extra]。 |
|
context
必要
|
額外的變數要傳給驗證者。 |
|
by_alias
必要
|
在驗證輸入資料時是否使用欄位的別名。 |
|
by_name
必要
|
是否在驗證輸入資料時使用欄位名稱。 |
僅限關鍵字的參數
| 名稱 | Description |
|---|---|
|
strict
|
預設值: None
|
|
extra
|
預設值: None
|
|
context
|
預設值: None
|
|
by_alias
|
預設值: None
|
|
by_name
|
預設值: None
|
傳回
| 類型 | Description |
|---|---|
|
經過驗證的皮丹提模型。 |
例外狀況
| 類型 | Description |
|---|---|
|
ValidationError
|
如果 json_data 不是 JSON 字串,或物件無法被驗證。 |
model_validate_strings
用字串資料與 Pydantic 模型驗證給定物件。
model_validate_strings(obj: Any, *, strict: bool | None = None, extra: Literal['allow', 'ignore', 'forbid'] | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
參數
| 名稱 | Description |
|---|---|
|
obj
必要
|
包含字串資料的物件進行驗證。 |
|
strict
必要
|
是否要嚴格執行類型。 |
|
extra
必要
|
Literal['allow', 'ignore', 'forbid'] | None
在模型驗證過程中,是否應該忽略、允許或禁止額外資料。 參見[額外 配置值][pydantic。詳情請參考 ConfigDict.extra]。 |
|
context
必要
|
額外的變數要傳給驗證者。 |
|
by_alias
必要
|
在驗證輸入資料時是否使用欄位的別名。 |
|
by_name
必要
|
是否在驗證輸入資料時使用欄位名稱。 |
僅限關鍵字的參數
| 名稱 | Description |
|---|---|
|
strict
|
預設值: None
|
|
extra
|
預設值: None
|
|
context
|
預設值: None
|
|
by_alias
|
預設值: None
|
|
by_name
|
預設值: None
|
傳回
| 類型 | Description |
|---|---|
|
經過驗證的皮丹提模型。 |
not_empty
parse_file
parse_file(path: str | Path, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
參數
| 名稱 | Description |
|---|---|
|
path
必要
|
str | <xref:Path>
|
|
content_type
必要
|
|
|
encoding
必要
|
|
|
proto
必要
|
<xref:DeprecatedParseProtocol> | None
|
|
allow_pickle
必要
|
|
僅限關鍵字的參數
| 名稱 | Description |
|---|---|
|
content_type
|
預設值: None
|
|
encoding
|
預設值: 'utf8'
|
|
proto
|
預設值: None
|
|
allow_pickle
|
預設值: False
|
傳回
| 類型 | Description |
|---|---|
parse_raw
parse_raw(b: str | bytes, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
參數
| 名稱 | Description |
|---|---|
|
b
必要
|
|
|
content_type
必要
|
|
|
encoding
必要
|
|
|
proto
必要
|
<xref:DeprecatedParseProtocol> | None
|
|
allow_pickle
必要
|
|
僅限關鍵字的參數
| 名稱 | Description |
|---|---|
|
content_type
|
預設值: None
|
|
encoding
|
預設值: 'utf8'
|
|
proto
|
預設值: None
|
|
allow_pickle
|
預設值: False
|
傳回
| 類型 | Description |
|---|---|
schema
schema_json
update_forward_refs
屬性
model_extra
驗證時多設欄位。
傳回
| 類型 | Description |
|---|---|
|
額外欄位的字典,或若 config.extra 未設定為「允許」則為 None。 |
model_fields_set
回傳已明確設定在此模型實例上的欄位集合。
傳回
| 類型 | Description |
|---|---|
|
一組字串代表已設定的欄位,即未從預設值填入的欄位。 |
conversation_id
交談的唯一識別碼。
field conversation_id: str [Required] (alias 'conversationId')
message_id
目前訊息的唯一識別碼。
field message_id: str [Required] (alias 'messageId')
user_message
目前正在處理的使用者訊息。
field user_message: str [Required] (alias 'userMessage')
chat_history
對話中之前的訊息列表。
field chat_history: List[ChatHistoryMessage] [Required] (alias 'chatHistory')