Skip to content

Commit

Permalink
Merge pull request #413 from Aggregate-Intellect/fix/pydantic-warning
Browse files Browse the repository at this point in the history
upgrade pydantic from v1 to v2
  • Loading branch information
20001LastOrder authored Sep 14, 2024
2 parents 95e57f8 + 0eb938c commit d4ea413
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 29 deletions.
12 changes: 6 additions & 6 deletions src/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/sherpa_ai/actions/arxiv_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
class ArxivSearch(BaseRetrievalAction):
role_description: str
task: str
llm: Any # The BaseLanguageModel from LangChain is not compatible with Pydantic 2 yet
llm: Any = None # The BaseLanguageModel from LangChain is not compatible with Pydantic 2 yet
description: str = SEARCH_SUMMARY_DESCRIPTION
_search_tool: Any
_search_tool: Any = None

# Override the name and args from BaseAction
name: str = "ArxivSearch"
Expand Down
7 changes: 3 additions & 4 deletions src/sherpa_ai/actions/belief_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

from sherpa_ai.actions.base import BaseAction
from sherpa_ai.memory.belief import Belief
from pydantic import ConfigDict


class UpdateBelief(BaseAction):
class Config:
arbitrary_types_allowed = True
model_config = ConfigDict(arbitrary_types_allowed=True)

name: str = "update_belief"
args: dict = {
Expand Down Expand Up @@ -39,8 +39,7 @@ def execute(self, key: str, value: str) -> str:


class RetrieveBelief(BaseAction):
class Config:
arbitrary_types_allowed = True
model_config = ConfigDict(arbitrary_types_allowed=True)

name: str = "retrieve_belief"
args: dict = {
Expand Down
4 changes: 2 additions & 2 deletions src/sherpa_ai/actions/context_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
class ContextSearch(BaseRetrievalAction):
role_description: str
task: str
llm: Any # The BaseLanguageModel from LangChain is not compatible with Pydantic 2 yet
llm: Any = None # The BaseLanguageModel from LangChain is not compatible with Pydantic 2 yet
description: str = SEARCH_SUMMARY_DESCRIPTION
_context: Any
_context: Any = None

# Override the name and args from BaseAction
name: str = "Context Search"
Expand Down
2 changes: 1 addition & 1 deletion src/sherpa_ai/actions/deliberation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class Deliberation(BaseAction):
# TODO: Make a version of Deliberation action that considers the context
role_description: str
llm: Any # The BaseLanguageModel from LangChain is not compatible with Pydantic 2 yet
llm: Any = None # The BaseLanguageModel from LangChain is not compatible with Pydantic 2 yet
description: str = DELIBERATION_DESCRIPTION

# Override the name and args from BaseAction
Expand Down
4 changes: 2 additions & 2 deletions src/sherpa_ai/actions/google_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
class GoogleSearch(BaseRetrievalAction):
role_description: str
task: str
llm: Any # The BaseLanguageModel from LangChain is not compatible with Pydantic 2 yet
llm: Any = None # The BaseLanguageModel from LangChain is not compatible with Pydantic 2 yet
description: str = SEARCH_SUMMARY_DESCRIPTION
config: AgentConfig = AgentConfig()
_search_tool: Any
_search_tool: Any = None

# Override the name and args from BaseAction
name: str = "Google Search"
Expand Down
2 changes: 1 addition & 1 deletion src/sherpa_ai/actions/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def from_dict(cls, data):


class TaskPlanning(BaseAction):
llm: Any # The BaseLanguageModel from LangChain is not compatible with Pydantic 2 yet
llm: Any = None # The BaseLanguageModel from LangChain is not compatible with Pydantic 2 yet
num_steps: int = 5
prompt: str = PLANNING_PROMPT
revision_prompt: str = REVISION_PROMPT
Expand Down
2 changes: 1 addition & 1 deletion src/sherpa_ai/actions/synthesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class SynthesizeOutput(BaseAction):
role_description: str
llm: Any # The BaseLanguageModel from LangChain is not compatible with Pydantic 2 yet
llm: Any = None # The BaseLanguageModel from LangChain is not compatible with Pydantic 2 yet
description: str = SYNTHESIZE_DESCRIPTION
add_citation: bool = False

Expand Down
4 changes: 2 additions & 2 deletions src/sherpa_ai/actions/utils/refinement.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def refinement(self, documents: list[str], **kwargs) -> str:


class RefinementByQuery(BaseRefinement):
llm: Any # The BaseLanguageModel from LangChain is not compatible with Pydantic 2 yet
llm: Any = None # The BaseLanguageModel from LangChain is not compatible with Pydantic 2 yet
description: str = SEARCH_SUMMARY_DESCRIPTION
k: int = 3

Expand All @@ -51,7 +51,7 @@ def refinement(self, documents: list[str], query: str) -> list[str]:


class RefinementBySentence(BaseRefinement):
llm: Any # The BaseLanguageModel from LangChain is not compatible with Pydantic 2 yet
llm: Any = None # The BaseLanguageModel from LangChain is not compatible with Pydantic 2 yet
description: str = SEARCH_SUMMARY_DESCRIPTION_SENT

def refinement(self, documents: list[str], query: str) -> list[str]:
Expand Down
2 changes: 1 addition & 1 deletion src/sherpa_ai/actions/utils/reranking.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def rerank(self, documents: list[str], **kwargs) -> str:


class RerankingByQuery(BaseReranking):
embeddings: Any # takes an Embedding Object from LangChain, use Any since it is not compatible with Pydantic 2 yet
embeddings: Any = None # takes an Embedding Object from LangChain, use Any since it is not compatible with Pydantic 2 yet
distance_metric: Callable[[ArrayLike, ArrayLike], float] = cosine_similarity

def rerank(self, documents: list[str], query: str) -> str:
Expand Down
5 changes: 3 additions & 2 deletions src/sherpa_ai/config/task_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import List, Optional, Tuple
from urllib.parse import urlparse

from pydantic import BaseModel, computed_field, validator
from pydantic import field_validator, BaseModel, computed_field


class AgentConfig(BaseModel):
Expand All @@ -13,7 +13,8 @@ class AgentConfig(BaseModel):
do_reflect: bool = False
use_task_agent: bool = False

@validator("gsite", pre=True)
@field_validator("gsite", mode="before")
@classmethod
def parse_gsite(cls, value: Optional[str]) -> list[str]:
if value is None:
return []
Expand Down
5 changes: 2 additions & 3 deletions src/sherpa_ai/policies/agent_feedback_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from sherpa_ai.events import Event, EventType
from sherpa_ai.memory import Belief
from sherpa_ai.policies import ReactPolicy
from pydantic import ConfigDict

AGENT_FEEDBACK_DESCRIPTION = """You are an intelligent assistant helping the user to complete their task. You have the following task to complete:
{task}
Expand All @@ -25,9 +26,7 @@ class AgentFeedbackPolicy(ReactPolicy):
"""
Select the best next action based on the feedback from an agent
"""

class Config:
arbitrary_types_allowed = True
model_config = ConfigDict(arbitrary_types_allowed=True)

# Prompt used to generate question to the user
agent_feedback_description: str = AGENT_FEEDBACK_DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion src/sherpa_ai/policies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PolicyOutput(BaseModel):
args (dict): The arguments for the selected action
"""

action: Any # TODO: Currently, we cannot use BaseAction since it does not inherit from Base class.
action: Any = None # TODO: Currently, we cannot use BaseAction since it does not inherit from Base class.
args: dict


Expand Down
2 changes: 1 addition & 1 deletion src/sherpa_ai/policies/react_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ReactPolicy(BasePolicy):

role_description: str
output_instruction: str
llm: Any # Cannot use langchain's BaseLanguageModel due to they are using Pydantic v1
llm: Any = None # Cannot use langchain's BaseLanguageModel due to they are using Pydantic v1
description: str = SELECTION_DESCRIPTION
response_format: dict = {
"command": {
Expand Down

0 comments on commit d4ea413

Please sign in to comment.