style: remove more Optional syntax (#33371)

This commit is contained in:
Mason Daugherty
2025-10-08 23:28:43 -04:00
committed by GitHub
parent f33b1b3d77
commit b6132fc23e
54 changed files with 360 additions and 422 deletions

View File

@@ -53,9 +53,9 @@ class AzureChatOpenAI(BaseChatOpenAI):
Name of Azure OpenAI deployment to use.
temperature: float
Sampling temperature.
max_tokens: Optional[int]
max_tokens: int | None
Max number of tokens to generate.
logprobs: Optional[bool]
logprobs: bool | None
Whether to return logprobs.
Key init args — client params:
@@ -64,15 +64,15 @@ class AzureChatOpenAI(BaseChatOpenAI):
underlying model). `See more on the different versions. <https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#rest-api-versioning>`__
timeout: Union[float, Tuple[float, float], Any, None]
Timeout for requests.
max_retries: Optional[int]
max_retries: int | None
Max number of retries.
organization: Optional[str]
organization: str | None
OpenAI organization ID. If not passed in will be read from env
var ``OPENAI_ORG_ID``.
model: Optional[str]
model: str | None
The name of the underlying OpenAI model. Used for tracing and token
counting. Does not affect completion. E.g. ``'gpt-4'``, ``'gpt-35-turbo'``, etc.
model_version: Optional[str]
model_version: str | None
The version of the underlying OpenAI model. Used for tracing and token
counting. Does not affect completion. E.g., ``'0125'``, ``'0125-preview'``, etc.
@@ -298,7 +298,7 @@ class AzureChatOpenAI(BaseChatOpenAI):
setup: str = Field(description="The setup of the joke")
punchline: str = Field(description="The punchline to the joke")
rating: Optional[int] = Field(
rating: int | None = Field(
description="How funny the joke is, from 1 to 10"
)
@@ -947,7 +947,7 @@ class AzureChatOpenAI(BaseChatOpenAI):
- ``'raw'``: BaseMessage
- ``'parsed'``: None if there was a parsing error, otherwise the type depends on the ``schema`` as described above.
- ``'parsing_error'``: Optional[BaseException]
- ``'parsing_error'``: BaseException | None
!!! warning "Behavior changed in 0.1.20"
Added support for TypedDict class ``schema``.
@@ -986,7 +986,7 @@ class AzureChatOpenAI(BaseChatOpenAI):
'''An answer to the user question along with justification for the answer.'''
answer: str
justification: Optional[str] = Field(
justification: str | None = Field(
default=..., description="A justification for the answer."
)
@@ -1019,7 +1019,7 @@ class AzureChatOpenAI(BaseChatOpenAI):
'''An answer to the user question along with justification for the answer.'''
answer: str
justification: Optional[str] = Field(
justification: str | None = Field(
default=..., description="A justification for the answer."
)
@@ -1085,7 +1085,7 @@ class AzureChatOpenAI(BaseChatOpenAI):
answer: str
justification: Annotated[
Optional[str], None, "A justification for the answer."
str | None, None, "A justification for the answer."
]

View File

@@ -40,12 +40,12 @@ class AzureOpenAIEmbeddings(OpenAIEmbeddings): # type: ignore[override]
Key init args — completion params:
model: str
Name of AzureOpenAI model to use.
dimensions: Optional[int]
dimensions: int | None
Number of dimensions for the embeddings. Can be specified only
if the underlying model supports it.
Key init args — client params:
api_key: Optional[SecretStr]
api_key: SecretStr | None
See full list of supported init args and their descriptions in the params section.
@@ -56,7 +56,7 @@ class AzureOpenAIEmbeddings(OpenAIEmbeddings): # type: ignore[override]
embeddings = AzureOpenAIEmbeddings(
model="text-embedding-3-large"
# dimensions: Optional[int] = None, # Can specify dimensions with new text-embedding-3 models
# dimensions: int | None = None, # Can specify dimensions with new text-embedding-3 models
# azure_endpoint="https://<your-endpoint>.openai.azure.com/", If not provided, will read env variable AZURE_OPENAI_ENDPOINT
# api_key=... # Can provide an API key directly. If missing read env variable AZURE_OPENAI_API_KEY
# openai_api_version=..., # If not provided, will read env variable AZURE_OPENAI_API_VERSION

View File

@@ -92,19 +92,19 @@ class OpenAIEmbeddings(BaseModel, Embeddings):
Key init args — embedding params:
model: str
Name of OpenAI model to use.
dimensions: Optional[int] = None
dimensions: int | None = None
The number of dimensions the resulting output embeddings should have.
Only supported in ``'text-embedding-3'`` and later models.
Key init args — client params:
api_key: Optional[SecretStr] = None
api_key: SecretStr | None = None
OpenAI API key.
organization: Optional[str] = None
organization: str | None = None
OpenAI organization ID. If not passed in will be read
from env var ``OPENAI_ORG_ID``.
max_retries: int = 2
Maximum number of retries to make when generating.
request_timeout: Optional[Union[float, Tuple[float, float], Any]] = None
request_timeout: float | Tuple[float, float] | Any | None = None
Timeout for requests to OpenAI completion API
See full list of supported init args and their descriptions in the params section.
@@ -472,7 +472,7 @@ class OpenAIEmbeddings(BaseModel, Embeddings):
Args:
texts (List[str]): A list of texts to embed.
engine (str): The engine or model to use for embeddings.
chunk_size (Optional[int]): The size of chunks for processing embeddings.
chunk_size (int | None): The size of chunks for processing embeddings.
Returns:
List[List[float]]: A list of embeddings for each input text.
@@ -524,7 +524,7 @@ class OpenAIEmbeddings(BaseModel, Embeddings):
Args:
texts (List[str]): A list of texts to embed.
engine (str): The engine or model to use for embeddings.
chunk_size (Optional[int]): The size of chunks for processing embeddings.
chunk_size (int | None): The size of chunks for processing embeddings.
Returns:
List[List[float]]: A list of embeddings for each input text.

View File

@@ -78,23 +78,23 @@ class BaseOpenAI(BaseLLM):
How many completions to generate for each prompt.
best_of: int
Generates best_of completions server-side and returns the "best".
logit_bias: Optional[dict[str, float]]
logit_bias: dict[str, float] | None
Adjust the probability of specific tokens being generated.
seed: Optional[int]
seed: int | None
Seed for generation.
logprobs: Optional[int]
logprobs: int | None
Include the log probabilities on the logprobs most likely output tokens.
streaming: bool
Whether to stream the results or not.
Key init args — client params:
openai_api_key: Optional[SecretStr]
openai_api_key: SecretStr | None
OpenAI API key. If not passed in will be read from env var
``OPENAI_API_KEY``.
openai_api_base: Optional[str]
openai_api_base: str | None
Base URL path for API requests, leave blank if not using a proxy or
service emulator.
openai_organization: Optional[str]
openai_organization: str | None
OpenAI organization ID. If not passed in will be read from env
var ``OPENAI_ORG_ID``.
request_timeout: Union[float, tuple[float, float], Any, None]
@@ -716,9 +716,9 @@ class OpenAI(BaseOpenAI):
Name of OpenAI model to use.
temperature: float
Sampling temperature.
max_tokens: Optional[int]
max_tokens: int | None
Max number of tokens to generate.
logprobs: Optional[bool]
logprobs: bool | None
Whether to return logprobs.
stream_options: Dict
Configure streaming outputs, like whether to return token usage when
@@ -729,12 +729,12 @@ class OpenAI(BaseOpenAI):
Timeout for requests.
max_retries: int
Max number of retries.
api_key: Optional[str]
api_key: str | None
OpenAI API key. If not passed in will be read from env var ``OPENAI_API_KEY``.
base_url: Optional[str]
base_url: str | None
Base URL for API requests. Only specify if using a proxy or service
emulator.
organization: Optional[str]
organization: str | None
OpenAI organization ID. If not passed in will be read from env
var ``OPENAI_ORG_ID``.