Skip to content

Commit f78bc2f

Browse files
committed
fix readme
1 parent 097e724 commit f78bc2f

File tree

6 files changed

+17
-12
lines changed

6 files changed

+17
-12
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,9 @@ class MyAPIClient(RequestsWebClient):
7373
pass
7474

7575
@delete("/users", agno_tool=True, tool_description="this is the function to delete user")
76-
def delete_user(self, user_id: str):
76+
def delete_user(self, user_id: str, request_headers: Dict[str, Any]):
7777
...
7878

79-
session = requests.Session()
80-
8179

8280
# Use the client
8381
client = MyAPIClient(base_url="https://localhost")
@@ -86,6 +84,10 @@ user = client.get_user(user_id=123)
8684
user_body = CreateUser(name="john", email="123@gmail.com")
8785
user = client.create_user(user_body)
8886

87+
# will update the client headers.
88+
client.delete_user("123", {"ba": "your"})
89+
90+
8991
from agno.agent import Agent
9092

9193
agent = Agent(.....)
@@ -170,6 +172,7 @@ You can initialize clients with custom configurations:
170172
client = MyAPIClient(
171173
base_url="https://api.example.com",
172174
headers={"Custom-Header": "value"},
175+
session=requests.Session(), # your own session
173176
timeout=30 # in seconds
174177
)
175178

pydantic_client/async_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Optional, Type, TypeVar
1+
from typing import Any, Dict, Optional, TypeVar
22

33
from pydantic import BaseModel
44

@@ -39,7 +39,7 @@ async def _request(self, request_info: RequestInfo) -> Any:
3939
data = await response.json()
4040

4141
if response_model is not None:
42-
return response_model.model_validate(data)
42+
return response_model.model_validate(data, from_attributes=True)
4343
return data
4444

4545

@@ -71,5 +71,5 @@ async def _request(self, request_info: RequestInfo) -> Any:
7171
response.raise_for_status()
7272
data = response.json()
7373
if response_model is not None:
74-
return response_model.model_validate(data)
74+
return response_model.model_validate(data, from_attributes=True)
7575
return data

pydantic_client/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import statsd
55

66
from abc import ABC, abstractmethod
7-
from typing import Any, Dict, Optional, Type, TypeVar, List
7+
from typing import Any, Dict, Optional, TypeVar, List
88

99
from pydantic import BaseModel
1010
from .schema import RequestInfo

pydantic_client/decorators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import inspect
22
from functools import wraps
3-
from typing import Any, Callable, Dict, Optional
3+
from typing import Callable, Optional
44

55
from pydantic import BaseModel
66

@@ -35,6 +35,7 @@ def _process_request_params(
3535

3636
# Get return type for response model
3737
return_type = sig.return_annotation
38+
3839
response_model = (
3940
return_type
4041
if isinstance(return_type, type) and issubclass(return_type, BaseModel)

pydantic_client/schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict, Optional, Any, Type
1+
from typing import Dict, Optional, Any
22

33
from pydantic import BaseModel
44

@@ -10,4 +10,4 @@ class RequestInfo(BaseModel):
1010
json: Optional[Dict[str, Any]] = None
1111
data: Optional[Dict[str, Any]] = None
1212
headers: Optional[Dict[str, Any]] = {}
13-
response_model: Optional[Type[BaseModel]] = None
13+
response_model: Optional[Any] = None

pydantic_client/sync_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Optional, Type, TypeVar
1+
from typing import Any, Dict, Optional, TypeVar
22

33
import requests
44
from pydantic import BaseModel
@@ -29,7 +29,8 @@ def _request(self, request_info: RequestInfo) -> Any:
2929

3030
response = requests.request(**request_params, timeout=self.timeout)
3131
response.raise_for_status()
32+
3233
data = response.json()
3334
if response_model is not None:
34-
return response_model.model_validate(data)
35+
return response_model.model_validate(data, from_attributes=True)
3536
return data

0 commit comments

Comments
 (0)