Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/pydantic #126

Merged
merged 7 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion examples/marketplace_classifier/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tanuki.py
openai~=0.28.1
pydantic==2.4.2
pydantic>1.0.0
requests~=2.31.0
python-dotenv~=1.0.0
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ openai = "0.28.1"
numpy = "1.24.4"
python-dotenv= "1.0.0"
bitarray = "2.8.2"
pydantic = "2.4.2"
pydantic = "^1.0.0"
# Add your project dependencies here, for example:
# requests = "^2.25.1"

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ openai==1.3.5
numpy~=1.26.1
python-dotenv==1.0.0
bitarray==2.8.2
pydantic==2.4.2
pydantic
requests~=2.31.0
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ install_requires =
numpy~=1.24.4
python-dotenv==1.0.0
bitarray==2.8.2
pydantic==2.4.2
pydantic>1.0.0


[options.packages.find]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"numpy~=1.26.1",
"python-dotenv==1.0.0",
"bitarray==2.8.2",
"pydantic==2.4.2",
"pydantic>1.0.0",
"requests~=2.31.0"
],
extras_require={
Expand Down
2 changes: 1 addition & 1 deletion src/tanuki.py.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Requires-Dist: openai==0.28.1
Requires-Dist: numpy~=1.24.4
Requires-Dist: python-dotenv==1.0.0
Requires-Dist: bitarray==2.8.2
Requires-Dist: pydantic==2.4.2
Requires-Dist: pydantic>1.0.0

# 🙈 Tanuki

Expand Down
2 changes: 1 addition & 1 deletion src/tanuki.py.egg-info/requires.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ openai==0.28.1
numpy~=1.24.4
python-dotenv==1.0.0
bitarray==2.8.2
pydantic==2.4.2
pydantic>1.0.0
8 changes: 4 additions & 4 deletions src/tanuki/language_models/llm_configs/abc_base_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import abc
from pydantic import BaseModel, ConfigDict
from pydantic import BaseModel#, ConfigDict
from typing import Optional

class BaseModelConfig(abc.ABC, BaseModel):
Expand All @@ -16,9 +16,9 @@ class BaseModelConfig(abc.ABC, BaseModel):
instructions : Optional[str] -- the instructions for the model
parsing_helper_tokens : Optional[dict] -- the parsing helper tokens for the model
"""
model_config = ConfigDict(
protected_namespaces=()
)
#model_config = ConfigDict(
# protected_namespaces=()
# )
model_name: str
provider: str
context_length: int
Expand Down
8 changes: 6 additions & 2 deletions src/tanuki/models/function_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ def to_dict(self):
Returns:
The dict
"""
return self.model_dump()

try:
config_dictionary = self.model_dump()
except AttributeError as e:
config_dictionary = self.dict()

return config_dictionary
def update_with_finetuned_response(self, response):
"""
Update the function config with the finetuned response
Expand Down
7 changes: 6 additions & 1 deletion src/tanuki/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,12 @@ def instantiate(self, data: Any, target_type: Type) -> Any:
for attr, attr_type in target_type.__annotations__.items():
if attr in data:
data[attr] = self.instantiate(data[attr], attr_type)
return target_type.model_validate(data)
try:
return target_type.model_validate(data)
except AttributeError as e:
# backwards compatibility with pydantic < 2
return target_type.parse_obj(data)


# For general classes, attempt instantiation
try:
Expand Down