style: format

This commit is contained in:
Henry Li
2026-01-14 09:21:19 +08:00
parent 421488a991
commit 2aeaf7c965
5 changed files with 9 additions and 28 deletions

View File

@@ -7,7 +7,6 @@ logger = logging.getLogger(__name__)
class JinaClient: class JinaClient:
def crawl(self, url: str, return_format: str = "html", timeout: int = 10) -> str: def crawl(self, url: str, return_format: str = "html", timeout: int = 10) -> str:
headers = { headers = {
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -17,17 +16,13 @@ class JinaClient:
if os.getenv("JINA_API_KEY"): if os.getenv("JINA_API_KEY"):
headers["Authorization"] = f"Bearer {os.getenv('JINA_API_KEY')}" headers["Authorization"] = f"Bearer {os.getenv('JINA_API_KEY')}"
else: else:
logger.warning( logger.warning("Jina API key is not set. Provide your own key to access a higher rate limit. See https://jina.ai/reader for more information.")
"Jina API key is not set. Provide your own key to access a higher rate limit. See https://jina.ai/reader for more information."
)
data = {"url": url} data = {"url": url}
try: try:
response = requests.post("https://r.jina.ai/", headers=headers, json=data) response = requests.post("https://r.jina.ai/", headers=headers, json=data)
if response.status_code != 200: if response.status_code != 200:
error_message = ( error_message = f"Jina API returned status {response.status_code}: {response.text}"
f"Jina API returned status {response.status_code}: {response.text}"
)
logger.error(error_message) logger.error(error_message)
return f"Error: {error_message}" return f"Error: {error_message}"

View File

@@ -45,7 +45,7 @@ def web_fetch_tool(url: str) -> str:
""" """
res = tavily_client.extract([url]) res = tavily_client.extract([url])
if "failed_results" in res and len(res["failed_results"]) > 0: if "failed_results" in res and len(res["failed_results"]) > 0:
return f"Error: {res["failed_results"][0]["error"]}" return f"Error: {res['failed_results'][0]['error']}"
elif "results" in res and len(res["results"]) > 0: elif "results" in res and len(res["results"]) > 0:
result = res["results"][0] result = res["results"][0]
return f"# {result['title']}\n\n{result['raw_content']}" return f"# {result['title']}\n\n{result['raw_content']}"

View File

@@ -5,21 +5,15 @@ class ModelConfig(BaseModel):
"""Config section for a model""" """Config section for a model"""
name: str = Field(..., description="Unique name for the model") name: str = Field(..., description="Unique name for the model")
display_name: str | None = Field( display_name: str | None = Field(..., default_factory=lambda: None, description="Display name for the model")
..., default_factory=lambda: None, description="Display name for the model" description: str | None = Field(..., default_factory=lambda: None, description="Description for the model")
)
description: str | None = Field(
..., default_factory=lambda: None, description="Description for the model"
)
use: str = Field( use: str = Field(
..., ...,
description="Class path of the model provider(e.g. langchain_openai.ChatOpenAI)", description="Class path of the model provider(e.g. langchain_openai.ChatOpenAI)",
) )
model: str = Field(..., description="Model name") model: str = Field(..., description="Model name")
model_config = ConfigDict(extra="allow") model_config = ConfigDict(extra="allow")
supports_thinking: bool = Field( supports_thinking: bool = Field(default_factory=lambda: False, description="Whether the model supports thinking")
default_factory=lambda: False, description="Whether the model supports thinking"
)
when_thinking_enabled: dict | None = Field( when_thinking_enabled: dict | None = Field(
default_factory=lambda: None, default_factory=lambda: None,
description="Extra settings to be passed to the model when thinking is enabled", description="Extra settings to be passed to the model when thinking is enabled",

View File

@@ -4,9 +4,7 @@ from src.config import get_app_config
from src.reflection import resolve_class from src.reflection import resolve_class
def create_chat_model( def create_chat_model(name: str | None = None, thinking_enabled: bool = False, **kwargs) -> BaseChatModel:
name: str | None = None, thinking_enabled: bool = False, **kwargs
) -> BaseChatModel:
"""Create a chat model instance from the config. """Create a chat model instance from the config.
Args: Args:
@@ -35,9 +33,7 @@ def create_chat_model(
) )
if thinking_enabled and model_config.when_thinking_enabled is not None: if thinking_enabled and model_config.when_thinking_enabled is not None:
if not model_config.supports_thinking: if not model_config.supports_thinking:
raise ValueError( raise ValueError(f"Model {name} does not support thinking. Set `supports_thinking` to true in the `config.yaml` to enable thinking.") from None
f"Model {name} does not support thinking. Set `supports_thinking` to true in the `config.yaml` to enable thinking."
) from None
model_settings_from_config.update(model_config.when_thinking_enabled) model_settings_from_config.update(model_config.when_thinking_enabled)
model_instance = model_class(**kwargs, **model_settings_from_config) model_instance = model_class(**kwargs, **model_settings_from_config)
return model_instance return model_instance

View File

@@ -7,8 +7,4 @@ from src.reflection import resolve_variable
def get_available_tools(groups: list[str] | None = None) -> list[BaseTool]: def get_available_tools(groups: list[str] | None = None) -> list[BaseTool]:
"""Get all available tools from config""" """Get all available tools from config"""
config = get_app_config() config = get_app_config()
return [ return [resolve_variable(tool.use, BaseTool) for tool in config.tools if groups is None or tool.group in groups]
resolve_variable(tool.use, BaseTool)
for tool in config.tools
if groups is None or tool.group in groups
]