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

@@ -269,7 +269,7 @@ class ChatOllama(BaseChatModel):
Key init args — completion params:
model: str
Name of Ollama model to use.
reasoning: Optional[bool]
reasoning: bool | None
Controls the reasoning/thinking mode for
`supported models <https://ollama.com/search?c=thinking>`__.
@@ -285,7 +285,7 @@ class ChatOllama(BaseChatModel):
unless you set ``reasoning`` to `True`.
temperature: float
Sampling temperature. Ranges from ``0.0`` to ``1.0``.
num_predict: Optional[int]
num_predict: int | None
Max number of tokens to generate.
See full list of supported init args and their descriptions in the params section.
@@ -1302,7 +1302,7 @@ class ChatOllama(BaseChatModel):
- ``'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.2.2"
Added support for structured output API via ``format`` parameter.
@@ -1324,7 +1324,7 @@ class ChatOllama(BaseChatModel):
'''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.",
)
@@ -1382,7 +1382,7 @@ class ChatOllama(BaseChatModel):
'''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.",
)
@@ -1416,7 +1416,7 @@ class ChatOllama(BaseChatModel):
'''An answer to the user question along with justification for the answer.'''
answer: str
justification: Annotated[Optional[str], None, "A justification for the answer."]
justification: Annotated[str | None, None, "A justification for the answer."]
llm = ChatOllama(model="llama3.1", temperature=0)

View File

@@ -66,7 +66,7 @@ class OllamaEmbeddings(BaseModel, Embeddings):
Key init args — completion params:
model: str
Name of Ollama model to use.
base_url: Optional[str]
base_url: str | None
Base url the model is hosted under.
See full list of supported init args and their descriptions in the params section.

View File

@@ -39,23 +39,23 @@ class OllamaLLM(BaseLLM):
Key init args — generation params:
model: str
Name of the Ollama model to use (e.g. ``'llama4'``).
temperature: Optional[float]
temperature: float | None
Sampling temperature. Higher values make output more creative.
num_predict: Optional[int]
num_predict: int | None
Maximum number of tokens to predict.
top_k: Optional[int]
top_k: int | None
Limits the next token selection to the K most probable tokens.
top_p: Optional[float]
top_p: float | None
Nucleus sampling parameter. Higher values lead to more diverse text.
mirostat: Optional[int]
mirostat: int | None
Enable Mirostat sampling for controlling perplexity.
seed: Optional[int]
seed: int | None
Random number seed for generation reproducibility.
Key init args — client params:
base_url: Optional[str]
base_url: str | None
Base URL where Ollama server is hosted.
keep_alive: Optional[Union[int, str]]
keep_alive: int | str | None
How long the model stays loaded into memory.
format: Literal["", "json"]
Specify the format of the output.