Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
aabe397
Chore: Narrow down ignored errors on dapr_agents.types to union-attr …
CasperGN Apr 26, 2025
bab600b
Ensure requirements.txt contains dotenv
CasperGN Apr 26, 2025
10b6dfd
Fix: Correct arg-type of default_factory list
CasperGN Apr 26, 2025
ee1e15f
Fix: Default assignment of fields to empty str instead of None
CasperGN Apr 26, 2025
5ddd187
Fix: Correct attr-defined for return value of get_message()
CasperGN Apr 26, 2025
ad53cd8
Fix: Ensure lint and build runs on chore/* branches too
CasperGN Apr 26, 2025
676b4d0
Merge branch 'main' into chore/type-checking-types-01
CasperGN Apr 26, 2025
f465bb1
Fix: Add cast post coercion
CasperGN Apr 27, 2025
27d72c0
Fix: union-attr on value.closed
CasperGN Apr 27, 2025
cc06ba7
Fix: type check before setting parameters.name or parameters.azure_de…
CasperGN Apr 27, 2025
c801c2c
Fix: Remove mypy exclusions for dapr_agents.types
CasperGN Apr 27, 2025
d7d5405
Chore: ruff formatting
CasperGN Apr 27, 2025
3db65f8
Merge branch 'main' into chore/type-checking-types-01
CasperGN Apr 30, 2025
5668f2d
Merge branch 'main' into chore/type-checking-types-01
CasperGN Nov 6, 2025
e54ea1c
fix: remove redefinition of Any
CasperGN Nov 6, 2025
1c98d22
fix: return False on uncaught has_tool_calls if condition and None fo…
CasperGN Nov 6, 2025
e3c4c90
fix: remove python 3.9 from tox
CasperGN Nov 6, 2025
6e32706
fix: remove minversion entirely as it's deprecated
CasperGN Nov 6, 2025
31344bb
fix: correct ref to type (not mypy)
CasperGN Nov 6, 2025
0ccb945
fix: revert inclusion of chore/* for triggers
CasperGN Nov 6, 2025
355cb34
Merge branch 'main' into chore/type-checking-types-01
CasperGN Nov 6, 2025
8a60443
Merge branch 'main' into chore/type-checking-types-01
CasperGN Nov 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions dapr_agents/types/llm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Union, Optional, Dict, Any, Literal, IO, Tuple
from typing import List, Union, Optional, Dict, Any, Literal, IO, Tuple, cast
from pydantic import BaseModel, Field, model_validator, field_validator, ConfigDict
from pydantic_core import PydanticUseDefault
from pathlib import Path
Expand Down Expand Up @@ -113,7 +113,7 @@ class OpenAIModelConfig(OpenAIClientConfig):
type: Literal["openai"] = Field(
"openai", description="Type of the model, must always be 'openai'"
)
name: str = Field(default=None, description="Name of the OpenAI model")
name: str = Field(default="", description="Name of the OpenAI model")


class AzureOpenAIModelConfig(AzureOpenAIClientConfig):
Expand All @@ -127,7 +127,7 @@ class HFHubModelConfig(HFInferenceClientConfig):
"huggingface", description="Type of the model, must always be 'huggingface'"
)
name: str = Field(
default=None, description="Name of the model available through Hugging Face"
default="", description="Name of the model available through Hugging Face"
)


Expand All @@ -136,7 +136,7 @@ class NVIDIAModelConfig(NVIDIAClientConfig):
"nvidia", description="Type of the model, must always be 'nvidia'"
)
name: str = Field(
default=None, description="Name of the model available through NVIDIA"
default="", description="Name of the model available through NVIDIA"
)


Expand Down Expand Up @@ -340,6 +340,14 @@ def sync_model_name(cls, values: dict):
elif configuration.get("type") == "nvidia":
configuration = NVIDIAModelConfig(**configuration)

configuration = cast(
OpenAIModelConfig
| AzureOpenAIModelConfig
| HFHubModelConfig
| NVIDIAModelConfig,
configuration,
)

# Ensure 'parameters' is properly validated as a model, not a dict
if isinstance(parameters, dict):
if configuration and isinstance(configuration, OpenAIModelConfig):
Expand All @@ -351,12 +359,27 @@ def sync_model_name(cls, values: dict):
elif configuration and isinstance(configuration, NVIDIAModelConfig):
parameters = NVIDIAChatCompletionParams(**parameters)

parameters = cast(
OpenAIChatCompletionParams
| HFHubChatCompletionParams
| NVIDIAChatCompletionParams,
parameters,
)

if configuration and parameters:
# Check if 'name' or 'azure_deployment' is explicitly set
if "name" in configuration.model_fields_set:
parameters.model = configuration.name
parameters.model = (
configuration.name
if not isinstance(configuration, AzureOpenAIModelConfig)
else None
)
elif "azure_deployment" in configuration.model_fields_set:
parameters.model = configuration.azure_deployment
parameters.model = (
configuration.azure_deployment
if isinstance(configuration, AzureOpenAIModelConfig)
else None
)

values["configuration"] = configuration
values["parameters"] = parameters
Expand Down Expand Up @@ -471,7 +494,7 @@ def validate_file(
elif isinstance(value, BufferedReader) or (
hasattr(value, "read") and callable(value.read)
):
if value.closed:
if hasattr(value, "closed") and value.closed:
raise ValueError("File-like object must remain open during request.")
return value
elif isinstance(value, tuple):
Expand Down Expand Up @@ -535,7 +558,7 @@ def validate_file(
elif isinstance(value, BufferedReader) or (
hasattr(value, "read") and callable(value.read)
):
if value.closed: # Reopen if closed
if hasattr(value, "closed") and value.closed: # Reopen if closed
raise ValueError("File-like object must remain open during request.")
return value
elif isinstance(value, tuple):
Expand Down
5 changes: 4 additions & 1 deletion dapr_agents/types/message.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from typing import Any
from pydantic import (
BaseModel,
field_validator,
ValidationError,
model_validator,
ConfigDict,
)
from typing import List, Optional, Dict, Any
from typing import List, Optional, Dict
import json


Expand Down Expand Up @@ -239,6 +240,7 @@ def get_tool_calls(self) -> Optional[List[ToolCall]]:
return self.tool_calls
if isinstance(self.tool_calls, ToolCall):
return [self.tool_calls]
return None

def has_tool_calls(self) -> bool:
"""
Expand All @@ -250,6 +252,7 @@ def has_tool_calls(self) -> bool:
return True
if isinstance(self.tool_calls, ToolCall):
return True
return False


class ToolMessage(BaseMessage):
Expand Down
3 changes: 0 additions & 3 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ ignore_errors = True
[mypy-dapr_agents.tool.base.*]
ignore_errors = True

[mypy-dapr_agents.types.*]
ignore_errors = True

[mypy-dapr_agents.workflow.*]
ignore_errors = True

Expand Down
5 changes: 2 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
[tox]
skipsdist = False
minversion = 3.9.0
envlist =
py{39,310,311,312,313}
py{310,311,312,313}
flake8,
ruff,
mypy,
type,
pytest

[testenv]
Expand Down