Skip to content

Commit bea38df

Browse files
committed
Fix parsing bugs for config
1 parent 1ea5c11 commit bea38df

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/utcp/client/utcp_client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,17 @@ async def create(cls, config: Optional[Union[Dict[str, Any], UtcpClientConfig]]
210210

211211
client = cls(config, tool_repository, search_strategy, DefaultVariableSubstitutor())
212212

213-
# If a providers file is used, configure TextTransport to resolve relative paths from its directory
214-
if config.providers_file_path:
215-
providers_dir = os.path.dirname(os.path.abspath(config.providers_file_path))
216-
client.transports["text"] = TextTransport(base_path=providers_dir)
217-
218213
if client.config.variables:
219214
config_without_vars = client.config.model_copy()
220215
config_without_vars.variables = None
221216
client.config.variables = client.variable_substitutor.substitute(client.config.variables, config_without_vars)
222217

223-
await client.load_providers(config.providers_file_path)
218+
# If a providers file is used, configure TextTransport to resolve relative paths from its directory
219+
if config.providers_file_path:
220+
providers_dir = os.path.dirname(os.path.abspath(config.providers_file_path))
221+
client.transports["text"] = TextTransport(base_path=providers_dir)
222+
223+
await client.load_providers(config.providers_file_path)
224224

225225
return client
226226

src/utcp/client/utcp_client_config.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from abc import ABC, abstractmethod
1717
from pydantic import BaseModel, Field
18-
from typing import Optional, List, Dict, Literal, TypedDict
18+
from typing import Optional, List, Dict, Annotated, Union, Literal
1919
from dotenv import dotenv_values
2020

2121
class UtcpVariableNotFound(Exception):
@@ -51,7 +51,7 @@ class UtcpVariablesConfig(BaseModel, ABC):
5151
Attributes:
5252
type: Type identifier for the variable loader.
5353
"""
54-
type: Literal["dotenv"] = "dotenv"
54+
type: str
5555

5656
@abstractmethod
5757
def get(self, key: str) -> Optional[str]:
@@ -81,6 +81,7 @@ class UtcpDotEnv(UtcpVariablesConfig):
8181
api_key = loader.get("API_KEY")
8282
```
8383
"""
84+
type: Literal["dotenv"] = "dotenv"
8485
env_file_path: str
8586

8687
def get(self, key: str) -> Optional[str]:
@@ -94,6 +95,13 @@ def get(self, key: str) -> Optional[str]:
9495
"""
9596
return dotenv_values(self.env_file_path).get(key)
9697

98+
UtcpVariablesConfigUnion = Annotated[
99+
Union[
100+
UtcpDotEnv
101+
],
102+
Field(discriminator="type")
103+
]
104+
97105
class UtcpClientConfig(BaseModel):
98106
"""Configuration model for UTCP client setup.
99107
@@ -128,4 +136,4 @@ class UtcpClientConfig(BaseModel):
128136
"""
129137
variables: Optional[Dict[str, str]] = Field(default_factory=dict)
130138
providers_file_path: Optional[str] = None
131-
load_variables_from: Optional[List[UtcpVariablesConfig]] = None
139+
load_variables_from: Optional[List[UtcpVariablesConfigUnion]] = None

0 commit comments

Comments
 (0)