mirror of
https://github.com/Shubhamsaboo/awesome-llm-apps.git
synced 2026-09-21 05:10:55 +08:00
[Beifong] [ApiPatch] Migrate deprecated pydantic API calls (6 files) (#1118)
This commit is contained in:
+2
-2
@@ -97,9 +97,9 @@ def search_agent_run(agent: Agent, query: str) -> str:
|
||||
session_id=session_id,
|
||||
)
|
||||
response = search_agent.run(query, session_id=session_id)
|
||||
response_dict = response.to_dict()
|
||||
response_dict = response.model_dump()
|
||||
current_state["stage"] = "search"
|
||||
current_state["search_results"] = response_dict["content"]["items"]
|
||||
SessionService.save_session(session_id, current_state)
|
||||
has_results = "search_results" in current_state and current_state["search_results"]
|
||||
return f"Found {len(response_dict['content']['items'])} sources about {query} {'and added to the search_results' if has_results else ''}"
|
||||
return f"Found {len(response_dict['content']['items'])} sources about {query} {'and added to the search_results' if has_results else ''}"
|
||||
|
||||
+2
-3
@@ -1,4 +1,4 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel, Field, ConfigDict
|
||||
from typing import Optional
|
||||
|
||||
|
||||
@@ -20,8 +20,7 @@ class PodcastConfig(PodcastConfigBase):
|
||||
created_at: Optional[str] = None
|
||||
updated_at: Optional[str] = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class PodcastConfigCreate(PodcastConfigBase):
|
||||
|
||||
+6
-10
@@ -1,4 +1,4 @@
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, ConfigDict, model_validator
|
||||
from typing import Optional, List, Dict, Any, Union
|
||||
|
||||
|
||||
@@ -17,8 +17,7 @@ class Podcast(PodcastBase):
|
||||
created_at: Optional[str] = None
|
||||
audio_path: Optional[str] = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class PodcastContent(BaseModel):
|
||||
@@ -31,16 +30,13 @@ class PodcastSource(BaseModel):
|
||||
url: Optional[str] = None
|
||||
source: Optional[str] = None
|
||||
|
||||
@model_validator(mode='before')
|
||||
@classmethod
|
||||
def __get_validators__(cls):
|
||||
yield cls.validate
|
||||
|
||||
@classmethod
|
||||
def validate(cls, v):
|
||||
def validate_source_input(cls, v):
|
||||
if isinstance(v, str):
|
||||
return cls(url=v)
|
||||
return {'url': v}
|
||||
if isinstance(v, dict):
|
||||
return cls(**v)
|
||||
return v
|
||||
raise ValueError("Source must be a string or a dict")
|
||||
|
||||
|
||||
|
||||
+2
-3
@@ -1,4 +1,4 @@
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
from typing import Optional, List
|
||||
|
||||
|
||||
@@ -32,8 +32,7 @@ class Source(SourceBase):
|
||||
created_at: Optional[str] = None
|
||||
last_crawled: Optional[str] = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class SourceCreate(SourceBase):
|
||||
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
from pydantic import BaseModel, validator
|
||||
from pydantic import BaseModel, field_validator, ConfigDict
|
||||
from typing import Optional, List, Dict, Any
|
||||
from enum import Enum
|
||||
|
||||
@@ -62,7 +62,8 @@ class TaskBase(BaseModel):
|
||||
description: Optional[str] = None
|
||||
enabled: bool = True
|
||||
|
||||
@validator("task_type")
|
||||
@field_validator("task_type")
|
||||
@classmethod
|
||||
def set_command_from_type(cls, v):
|
||||
if v not in TASK_TYPES:
|
||||
raise ValueError(f"Invalid task type: {v}")
|
||||
@@ -75,8 +76,7 @@ class Task(TaskBase):
|
||||
last_run: Optional[str] = None
|
||||
created_at: Optional[str] = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class TaskCreate(TaskBase):
|
||||
|
||||
+1
-1
@@ -136,7 +136,7 @@ async def update_podcast(podcast_id: int = Path(..., description="The ID of the
|
||||
|
||||
Returns the updated podcast metadata.
|
||||
"""
|
||||
update_data = {k: v for k, v in podcast_data.dict().items() if v is not None}
|
||||
update_data = {k: v for k, v in podcast_data.model_dump().items() if v is not None}
|
||||
return await podcast_service.update_podcast(podcast_id, update_data)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user