"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" from __future__ import annotations from .chatcompletionmessageparam import ( ChatCompletionMessageParam, ChatCompletionMessageParamTypedDict, ) from .chatcompletiontool import ChatCompletionTool, ChatCompletionToolTypedDict from .chatcompletiontoolchoiceoption import ( ChatCompletionToolChoiceOption, ChatCompletionToolChoiceOptionTypedDict, ) from .responseformatjsonschemaschema import ( ResponseFormatJSONSchemaSchema, ResponseFormatJSONSchemaSchemaTypedDict, ) from openrouter.types import ( BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL, ) import pydantic from pydantic import model_serializer from typing import Any, Dict, List, Literal, Optional, Union from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict Effort = Literal["high", "medium", "low", "minimal"] r"""OpenAI-style reasoning effort setting""" class ReasoningTypedDict(TypedDict): r"""Reasoning configuration""" enabled: NotRequired[bool] r"""Enables reasoning with default settings. Only work for some models.""" effort: NotRequired[Nullable[Effort]] r"""OpenAI-style reasoning effort setting""" max_tokens: NotRequired[Nullable[float]] r"""non-OpenAI-style reasoning effort setting""" exclude: NotRequired[bool] class Reasoning(BaseModel): r"""Reasoning configuration""" enabled: Optional[bool] = None r"""Enables reasoning with default settings. Only work for some models.""" effort: OptionalNullable[Effort] = UNSET r"""OpenAI-style reasoning effort setting""" max_tokens: OptionalNullable[float] = UNSET r"""non-OpenAI-style reasoning effort setting""" exclude: Optional[bool] = False @model_serializer(mode="wrap") def serialize_model(self, handler): optional_fields = ["enabled", "effort", "max_tokens", "exclude"] nullable_fields = ["effort", "max_tokens"] null_default_fields = [] serialized = handler(self) m = {} for n, f in type(self).model_fields.items(): k = f.alias or n val = serialized.get(k) serialized.pop(k, None) optional_nullable = k in optional_fields and k in nullable_fields is_set = ( self.__pydantic_fields_set__.intersection({n}) or k in null_default_fields ) # pylint: disable=no-member if val is not None and val != UNSET_SENTINEL: m[k] = val elif val != UNSET_SENTINEL and ( not k in optional_fields or (optional_nullable and is_set) ): m[k] = val return m TypePython = Literal["python"] class ResponseFormatPythonTypedDict(TypedDict): r"""Python code response format""" type: TypePython class ResponseFormatPython(BaseModel): r"""Python code response format""" type: TypePython TypeGrammar = Literal["grammar"] class ResponseFormatGrammarTypedDict(TypedDict): r"""Custom grammar response format""" type: TypeGrammar grammar: str r"""Custom grammar for text generation""" class ResponseFormatGrammar(BaseModel): r"""Custom grammar response format""" type: TypeGrammar grammar: str r"""Custom grammar for text generation""" TypeJSONSchema = Literal["json_schema"] class JSONSchemaTypedDict(TypedDict): name: str r"""Schema name (a-z, A-Z, 0-9, underscores, dashes, max 64 chars)""" description: NotRequired[str] r"""Schema description for the model""" schema_: NotRequired[ResponseFormatJSONSchemaSchemaTypedDict] r"""The schema for the response format, described as a JSON Schema object""" strict: NotRequired[Nullable[bool]] r"""Enable strict schema adherence""" class JSONSchema(BaseModel): name: str r"""Schema name (a-z, A-Z, 0-9, underscores, dashes, max 64 chars)""" description: Optional[str] = None r"""Schema description for the model""" schema_: Annotated[ Optional[ResponseFormatJSONSchemaSchema], pydantic.Field(alias="schema") ] = None r"""The schema for the response format, described as a JSON Schema object""" strict: OptionalNullable[bool] = UNSET r"""Enable strict schema adherence""" @model_serializer(mode="wrap") def serialize_model(self, handler): optional_fields = ["description", "schema", "strict"] nullable_fields = ["strict"] null_default_fields = [] serialized = handler(self) m = {} for n, f in type(self).model_fields.items(): k = f.alias or n val = serialized.get(k) serialized.pop(k, None) optional_nullable = k in optional_fields and k in nullable_fields is_set = ( self.__pydantic_fields_set__.intersection({n}) or k in null_default_fields ) # pylint: disable=no-member if val is not None and val != UNSET_SENTINEL: m[k] = val elif val != UNSET_SENTINEL and ( not k in optional_fields or (optional_nullable and is_set) ): m[k] = val return m class ResponseFormatJSONSchemaTypedDict(TypedDict): r"""JSON Schema response format for structured outputs""" type: TypeJSONSchema json_schema: JSONSchemaTypedDict class ResponseFormatJSONSchema(BaseModel): r"""JSON Schema response format for structured outputs""" type: TypeJSONSchema json_schema: JSONSchema TypeJSONObject = Literal["json_object"] class ResponseFormatJSONObjectTypedDict(TypedDict): r"""JSON object response format""" type: TypeJSONObject class ResponseFormatJSONObject(BaseModel): r"""JSON object response format""" type: TypeJSONObject ChatCompletionCreateParamsTypeText = Literal["text"] class ResponseFormatTextTypedDict(TypedDict): r"""Default text response format""" type: ChatCompletionCreateParamsTypeText class ResponseFormatText(BaseModel): r"""Default text response format""" type: ChatCompletionCreateParamsTypeText ResponseFormatTypedDict = TypeAliasType( "ResponseFormatTypedDict", Union[ ResponseFormatTextTypedDict, ResponseFormatJSONObjectTypedDict, ResponseFormatPythonTypedDict, ResponseFormatJSONSchemaTypedDict, ResponseFormatGrammarTypedDict, ], ) r"""Response format configuration""" ResponseFormat = TypeAliasType( "ResponseFormat", Union[ ResponseFormatText, ResponseFormatJSONObject, ResponseFormatPython, ResponseFormatJSONSchema, ResponseFormatGrammar, ], ) r"""Response format configuration""" StopTypedDict = TypeAliasType("StopTypedDict", Union[str, List[str], Any]) r"""Stop sequences (up to 4)""" Stop = TypeAliasType("Stop", Union[str, List[str], Any]) r"""Stop sequences (up to 4)""" class StreamOptionsTypedDict(TypedDict): r"""Streaming configuration options""" include_usage: NotRequired[bool] r"""Include usage information in streaming response""" class StreamOptions(BaseModel): r"""Streaming configuration options""" include_usage: Optional[bool] = None r"""Include usage information in streaming response""" ReasoningEffort = Literal["high", "medium", "low", "minimal"] r"""Reasoning effort""" DataCollection = Literal["deny", "allow"] r"""Data collection setting. If no available model provider meets the requirement, your request will return an error. - allow: (default) allow providers which store user data non-transiently and may train on it - deny: use only providers which do not collect user data. """ OrderEnum = Literal[ "AnyScale", "Cent-ML", "HuggingFace", "Hyperbolic 2", "Lepton", "Lynn 2", "Lynn", "Mancer", "Modal", "OctoAI", "Recursal", "Reflection", "Replicate", "SambaNova 2", "SF Compute", "Together 2", "01.AI", "AI21", "AionLabs", "Alibaba", "Amazon Bedrock", "Anthropic", "AtlasCloud", "Atoma", "Avian", "Azure", "BaseTen", "Cerebras", "Chutes", "Cloudflare", "Cohere", "CrofAI", "Crusoe", "DeepInfra", "DeepSeek", "Enfer", "Featherless", "Fireworks", "Friendli", "GMICloud", "Google", "Google AI Studio", "Groq", "Hyperbolic", "Inception", "InferenceNet", "Infermatic", "Inflection", "InoCloud", "Kluster", "Lambda", "Liquid", "Mancer 2", "Meta", "Minimax", "Mistral", "Moonshot AI", "Morph", "NCompass", "Nebius", "NextBit", "Nineteen", "Novita", "OpenAI", "OpenInference", "Parasail", "Perplexity", "Phala", "SambaNova", "Stealth", "Switchpoint", "Targon", "Together", "Ubicloud", "Venice", "WandB", "xAI", "Z.AI", ] OrderTypedDict = TypeAliasType("OrderTypedDict", Union[OrderEnum, str]) Order = TypeAliasType("Order", Union[OrderEnum, str]) OnlyEnum = Literal[ "AnyScale", "Cent-ML", "HuggingFace", "Hyperbolic 2", "Lepton", "Lynn 2", "Lynn", "Mancer", "Modal", "OctoAI", "Recursal", "Reflection", "Replicate", "SambaNova 2", "SF Compute", "Together 2", "01.AI", "AI21", "AionLabs", "Alibaba", "Amazon Bedrock", "Anthropic", "AtlasCloud", "Atoma", "Avian", "Azure", "BaseTen", "Cerebras", "Chutes", "Cloudflare", "Cohere", "CrofAI", "Crusoe", "DeepInfra", "DeepSeek", "Enfer", "Featherless", "Fireworks", "Friendli", "GMICloud", "Google", "Google AI Studio", "Groq", "Hyperbolic", "Inception", "InferenceNet", "Infermatic", "Inflection", "InoCloud", "Kluster", "Lambda", "Liquid", "Mancer 2", "Meta", "Minimax", "Mistral", "Moonshot AI", "Morph", "NCompass", "Nebius", "NextBit", "Nineteen", "Novita", "OpenAI", "OpenInference", "Parasail", "Perplexity", "Phala", "SambaNova", "Stealth", "Switchpoint", "Targon", "Together", "Ubicloud", "Venice", "WandB", "xAI", "Z.AI", ] OnlyTypedDict = TypeAliasType("OnlyTypedDict", Union[OnlyEnum, str]) Only = TypeAliasType("Only", Union[OnlyEnum, str]) IgnoreEnum = Literal[ "AnyScale", "Cent-ML", "HuggingFace", "Hyperbolic 2", "Lepton", "Lynn 2", "Lynn", "Mancer", "Modal", "OctoAI", "Recursal", "Reflection", "Replicate", "SambaNova 2", "SF Compute", "Together 2", "01.AI", "AI21", "AionLabs", "Alibaba", "Amazon Bedrock", "Anthropic", "AtlasCloud", "Atoma", "Avian", "Azure", "BaseTen", "Cerebras", "Chutes", "Cloudflare", "Cohere", "CrofAI", "Crusoe", "DeepInfra", "DeepSeek", "Enfer", "Featherless", "Fireworks", "Friendli", "GMICloud", "Google", "Google AI Studio", "Groq", "Hyperbolic", "Inception", "InferenceNet", "Infermatic", "Inflection", "InoCloud", "Kluster", "Lambda", "Liquid", "Mancer 2", "Meta", "Minimax", "Mistral", "Moonshot AI", "Morph", "NCompass", "Nebius", "NextBit", "Nineteen", "Novita", "OpenAI", "OpenInference", "Parasail", "Perplexity", "Phala", "SambaNova", "Stealth", "Switchpoint", "Targon", "Together", "Ubicloud", "Venice", "WandB", "xAI", "Z.AI", ] IgnoreTypedDict = TypeAliasType("IgnoreTypedDict", Union[IgnoreEnum, str]) Ignore = TypeAliasType("Ignore", Union[IgnoreEnum, str]) Quantization = Literal[ "int4", "int8", "fp4", "fp6", "fp8", "fp16", "bf16", "fp32", "unknown" ] Sort = Literal["price", "throughput", "latency"] r"""The sorting strategy to use for this request, if \"order\" is not specified. When set, no load balancing is performed.""" PromptTypedDict = TypeAliasType("PromptTypedDict", Union[float, str, Any]) Prompt = TypeAliasType("Prompt", Union[float, str, Any]) CompletionTypedDict = TypeAliasType("CompletionTypedDict", Union[float, str, Any]) Completion = TypeAliasType("Completion", Union[float, str, Any]) ImageTypedDict = TypeAliasType("ImageTypedDict", Union[float, str, Any]) Image = TypeAliasType("Image", Union[float, str, Any]) AudioTypedDict = TypeAliasType("AudioTypedDict", Union[float, str, Any]) Audio = TypeAliasType("Audio", Union[float, str, Any]) RequestTypedDict = TypeAliasType("RequestTypedDict", Union[float, str, Any]) Request = TypeAliasType("Request", Union[float, str, Any]) class MaxPriceTypedDict(TypedDict): r"""The object specifying the maximum price you want to pay for this request. USD price per million tokens, for prompt and completion.""" prompt: NotRequired[PromptTypedDict] completion: NotRequired[CompletionTypedDict] image: NotRequired[ImageTypedDict] audio: NotRequired[AudioTypedDict] request: NotRequired[RequestTypedDict] class MaxPrice(BaseModel): r"""The object specifying the maximum price you want to pay for this request. USD price per million tokens, for prompt and completion.""" prompt: Optional[Prompt] = None completion: Optional[Completion] = None image: Optional[Image] = None audio: Optional[Audio] = None request: Optional[Request] = None class ProviderTypedDict(TypedDict): r"""When multiple model providers are available, optionally indicate your routing preference.""" allow_fallbacks: NotRequired[Nullable[bool]] r"""Whether to allow backup providers to serve requests - true: (default) when the primary provider (or your custom providers in \"order\") is unavailable, use the next best provider. - false: use only the primary/custom provider, and return the upstream error if it's unavailable. """ require_parameters: NotRequired[Nullable[bool]] r"""Whether to filter providers to only those that support the parameters you've provided. If this setting is omitted or set to false, then providers will receive only the parameters they support, and ignore the rest.""" data_collection: NotRequired[Nullable[DataCollection]] r"""Data collection setting. If no available model provider meets the requirement, your request will return an error. - allow: (default) allow providers which store user data non-transiently and may train on it - deny: use only providers which do not collect user data. """ order: NotRequired[Nullable[List[OrderTypedDict]]] r"""An ordered list of provider slugs. The router will attempt to use the first provider in the subset of this list that supports your requested model, and fall back to the next if it is unavailable. If no providers are available, the request will fail with an error message.""" only: NotRequired[Nullable[List[OnlyTypedDict]]] r"""List of provider slugs to allow. If provided, this list is merged with your account-wide allowed provider settings for this request.""" ignore: NotRequired[Nullable[List[IgnoreTypedDict]]] r"""List of provider slugs to ignore. If provided, this list is merged with your account-wide ignored provider settings for this request.""" quantizations: NotRequired[Nullable[List[Quantization]]] r"""A list of quantization levels to filter the provider by.""" sort: NotRequired[Nullable[Sort]] r"""The sorting strategy to use for this request, if \"order\" is not specified. When set, no load balancing is performed.""" max_price: NotRequired[MaxPriceTypedDict] r"""The object specifying the maximum price you want to pay for this request. USD price per million tokens, for prompt and completion.""" class Provider(BaseModel): r"""When multiple model providers are available, optionally indicate your routing preference.""" allow_fallbacks: OptionalNullable[bool] = UNSET r"""Whether to allow backup providers to serve requests - true: (default) when the primary provider (or your custom providers in \"order\") is unavailable, use the next best provider. - false: use only the primary/custom provider, and return the upstream error if it's unavailable. """ require_parameters: OptionalNullable[bool] = UNSET r"""Whether to filter providers to only those that support the parameters you've provided. If this setting is omitted or set to false, then providers will receive only the parameters they support, and ignore the rest.""" data_collection: OptionalNullable[DataCollection] = UNSET r"""Data collection setting. If no available model provider meets the requirement, your request will return an error. - allow: (default) allow providers which store user data non-transiently and may train on it - deny: use only providers which do not collect user data. """ order: OptionalNullable[List[Order]] = UNSET r"""An ordered list of provider slugs. The router will attempt to use the first provider in the subset of this list that supports your requested model, and fall back to the next if it is unavailable. If no providers are available, the request will fail with an error message.""" only: OptionalNullable[List[Only]] = UNSET r"""List of provider slugs to allow. If provided, this list is merged with your account-wide allowed provider settings for this request.""" ignore: OptionalNullable[List[Ignore]] = UNSET r"""List of provider slugs to ignore. If provided, this list is merged with your account-wide ignored provider settings for this request.""" quantizations: OptionalNullable[List[Quantization]] = UNSET r"""A list of quantization levels to filter the provider by.""" sort: OptionalNullable[Sort] = UNSET r"""The sorting strategy to use for this request, if \"order\" is not specified. When set, no load balancing is performed.""" max_price: Optional[MaxPrice] = None r"""The object specifying the maximum price you want to pay for this request. USD price per million tokens, for prompt and completion.""" @model_serializer(mode="wrap") def serialize_model(self, handler): optional_fields = [ "allow_fallbacks", "require_parameters", "data_collection", "order", "only", "ignore", "quantizations", "sort", "max_price", ] nullable_fields = [ "allow_fallbacks", "require_parameters", "data_collection", "order", "only", "ignore", "quantizations", "sort", ] null_default_fields = [] serialized = handler(self) m = {} for n, f in type(self).model_fields.items(): k = f.alias or n val = serialized.get(k) serialized.pop(k, None) optional_nullable = k in optional_fields and k in nullable_fields is_set = ( self.__pydantic_fields_set__.intersection({n}) or k in null_default_fields ) # pylint: disable=no-member if val is not None and val != UNSET_SENTINEL: m[k] = val elif val != UNSET_SENTINEL and ( not k in optional_fields or (optional_nullable and is_set) ): m[k] = val return m IDFileParser = Literal["file-parser"] PdfEngine = Literal["mistral-ocr", "pdf-text", "native"] class PdfTypedDict(TypedDict): engine: NotRequired[PdfEngine] class Pdf(BaseModel): engine: Optional[PdfEngine] = None class PluginFileParserTypedDict(TypedDict): id: IDFileParser max_files: NotRequired[float] pdf: NotRequired[PdfTypedDict] class PluginFileParser(BaseModel): id: IDFileParser max_files: Optional[float] = None pdf: Optional[Pdf] = None IDChainOfThought = Literal["chain-of-thought"] class PluginChainOfThoughtTypedDict(TypedDict): id: IDChainOfThought class PluginChainOfThought(BaseModel): id: IDChainOfThought IDWeb = Literal["web"] Engine = Literal["native", "exa"] class PluginWebTypedDict(TypedDict): id: IDWeb max_results: NotRequired[float] search_prompt: NotRequired[str] engine: NotRequired[Engine] class PluginWeb(BaseModel): id: IDWeb max_results: Optional[float] = None search_prompt: Optional[str] = None engine: Optional[Engine] = None IDModeration = Literal["moderation"] class PluginModerationTypedDict(TypedDict): id: IDModeration class PluginModeration(BaseModel): id: IDModeration PluginTypedDict = TypeAliasType( "PluginTypedDict", Union[ PluginModerationTypedDict, PluginChainOfThoughtTypedDict, PluginFileParserTypedDict, PluginWebTypedDict, ], ) Plugin = TypeAliasType( "Plugin", Union[PluginModeration, PluginChainOfThought, PluginFileParser, PluginWeb] ) class ChatCompletionCreateParamsTypedDict(TypedDict): r"""Chat completion request parameters""" messages: List[ChatCompletionMessageParamTypedDict] r"""List of messages for the conversation""" model: NotRequired[str] r"""Model to use for completion""" frequency_penalty: NotRequired[Nullable[float]] r"""Frequency penalty (-2.0 to 2.0)""" logit_bias: NotRequired[Nullable[Dict[str, float]]] r"""Token logit bias adjustments""" logprobs: NotRequired[Nullable[bool]] r"""Return log probabilities""" top_logprobs: NotRequired[Nullable[float]] r"""Number of top log probabilities to return (0-20)""" max_completion_tokens: NotRequired[Nullable[float]] r"""Maximum tokens in completion""" max_tokens: NotRequired[Nullable[float]] r"""Maximum tokens (deprecated, use max_completion_tokens)""" metadata: NotRequired[Dict[str, str]] r"""Key-value pairs for additional object information (max 16 pairs, 64 char keys, 512 char values)""" presence_penalty: NotRequired[Nullable[float]] r"""Presence penalty (-2.0 to 2.0)""" reasoning: NotRequired[Nullable[ReasoningTypedDict]] r"""Reasoning configuration""" response_format: NotRequired[ResponseFormatTypedDict] r"""Response format configuration""" seed: NotRequired[Nullable[int]] r"""Random seed for deterministic outputs""" stop: NotRequired[Nullable[StopTypedDict]] r"""Stop sequences (up to 4)""" stream: NotRequired[Nullable[bool]] r"""Enable streaming response""" stream_options: NotRequired[Nullable[StreamOptionsTypedDict]] temperature: NotRequired[Nullable[float]] r"""Sampling temperature (0-2)""" tool_choice: NotRequired[ChatCompletionToolChoiceOptionTypedDict] r"""Tool choice configuration""" tools: NotRequired[List[ChatCompletionToolTypedDict]] r"""Available tools for function calling""" top_p: NotRequired[Nullable[float]] r"""Nucleus sampling parameter (0-1)""" user: NotRequired[str] r"""Unique user identifier""" fallback_models: NotRequired[Nullable[List[str]]] r"""Order of models to fallback to for this request""" reasoning_effort: NotRequired[Nullable[ReasoningEffort]] r"""Reasoning effort""" provider: NotRequired[Nullable[ProviderTypedDict]] r"""When multiple model providers are available, optionally indicate your routing preference.""" plugins: NotRequired[List[PluginTypedDict]] r"""Plugins you want to enable for this request, including their settings.""" class ChatCompletionCreateParams(BaseModel): r"""Chat completion request parameters""" messages: List[ChatCompletionMessageParam] r"""List of messages for the conversation""" model: Optional[str] = None r"""Model to use for completion""" frequency_penalty: OptionalNullable[float] = UNSET r"""Frequency penalty (-2.0 to 2.0)""" logit_bias: OptionalNullable[Dict[str, float]] = UNSET r"""Token logit bias adjustments""" logprobs: OptionalNullable[bool] = UNSET r"""Return log probabilities""" top_logprobs: OptionalNullable[float] = UNSET r"""Number of top log probabilities to return (0-20)""" max_completion_tokens: OptionalNullable[float] = UNSET r"""Maximum tokens in completion""" max_tokens: OptionalNullable[float] = UNSET r"""Maximum tokens (deprecated, use max_completion_tokens)""" metadata: Optional[Dict[str, str]] = None r"""Key-value pairs for additional object information (max 16 pairs, 64 char keys, 512 char values)""" presence_penalty: OptionalNullable[float] = UNSET r"""Presence penalty (-2.0 to 2.0)""" reasoning: OptionalNullable[Reasoning] = UNSET r"""Reasoning configuration""" response_format: Optional[ResponseFormat] = None r"""Response format configuration""" seed: OptionalNullable[int] = UNSET r"""Random seed for deterministic outputs""" stop: OptionalNullable[Stop] = UNSET r"""Stop sequences (up to 4)""" stream: OptionalNullable[bool] = False r"""Enable streaming response""" stream_options: OptionalNullable[StreamOptions] = UNSET temperature: OptionalNullable[float] = 1 r"""Sampling temperature (0-2)""" tool_choice: Optional[ChatCompletionToolChoiceOption] = None r"""Tool choice configuration""" tools: Optional[List[ChatCompletionTool]] = None r"""Available tools for function calling""" top_p: OptionalNullable[float] = 1 r"""Nucleus sampling parameter (0-1)""" user: Optional[str] = None r"""Unique user identifier""" fallback_models: Annotated[ OptionalNullable[List[str]], pydantic.Field(alias="models") ] = UNSET r"""Order of models to fallback to for this request""" reasoning_effort: OptionalNullable[ReasoningEffort] = UNSET r"""Reasoning effort""" provider: OptionalNullable[Provider] = UNSET r"""When multiple model providers are available, optionally indicate your routing preference.""" plugins: Optional[List[Plugin]] = None r"""Plugins you want to enable for this request, including their settings.""" @model_serializer(mode="wrap") def serialize_model(self, handler): optional_fields = [ "model", "frequency_penalty", "logit_bias", "logprobs", "top_logprobs", "max_completion_tokens", "max_tokens", "metadata", "presence_penalty", "reasoning", "response_format", "seed", "stop", "stream", "stream_options", "temperature", "tool_choice", "tools", "top_p", "user", "fallback_models", "reasoning_effort", "provider", "plugins", ] nullable_fields = [ "frequency_penalty", "logit_bias", "logprobs", "top_logprobs", "max_completion_tokens", "max_tokens", "presence_penalty", "reasoning", "seed", "stop", "stream", "stream_options", "temperature", "top_p", "fallback_models", "reasoning_effort", "provider", ] null_default_fields = [] serialized = handler(self) m = {} for n, f in type(self).model_fields.items(): k = f.alias or n val = serialized.get(k) serialized.pop(k, None) optional_nullable = k in optional_fields and k in nullable_fields is_set = ( self.__pydantic_fields_set__.intersection({n}) or k in null_default_fields ) # pylint: disable=no-member if val is not None and val != UNSET_SENTINEL: m[k] = val elif val != UNSET_SENTINEL and ( not k in optional_fields or (optional_nullable and is_set) ): m[k] = val return m