mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-10 03:16:51 +08:00
fix: universal chat when default model invalid (#905)
This commit is contained in:
25
api/core/tool/current_datetime_tool.py
Normal file
25
api/core/tool/current_datetime_tool.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from datetime import datetime
|
||||
from typing import Type
|
||||
|
||||
from langchain.tools import BaseTool
|
||||
from pydantic import Field, BaseModel
|
||||
|
||||
|
||||
class DatetimeToolInput(BaseModel):
|
||||
type: str = Field(..., description="Type for current time, must be: datetime.")
|
||||
|
||||
|
||||
class DatetimeTool(BaseTool):
|
||||
"""Tool for querying current datetime."""
|
||||
name: str = "current_datetime"
|
||||
args_schema: Type[BaseModel] = DatetimeToolInput
|
||||
description: str = "A tool when you want to get the current date, time, week, month or year, " \
|
||||
"and the time zone is UTC. Result is \"<date> <time> <timezone> <week>\"."
|
||||
|
||||
def _run(self, type: str) -> str:
|
||||
# get current time
|
||||
current_time = datetime.utcnow()
|
||||
return current_time.strftime("%Y-%m-%d %H:%M:%S UTC+0000 %A")
|
||||
|
||||
async def _arun(self, tool_input: str) -> str:
|
||||
raise NotImplementedError()
|
||||
@@ -65,7 +65,7 @@ class WebReaderTool(BaseTool):
|
||||
summary_chunk_overlap: int = 0
|
||||
summary_separators: list[str] = ["\n\n", "。", ".", " ", ""]
|
||||
continue_reading: bool = True
|
||||
llm: BaseLanguageModel
|
||||
llm: BaseLanguageModel = None
|
||||
|
||||
def _run(self, url: str, summary: bool = False, cursor: int = 0) -> str:
|
||||
try:
|
||||
@@ -78,7 +78,7 @@ class WebReaderTool(BaseTool):
|
||||
except Exception as e:
|
||||
return f'Read this website failed, caused by: {str(e)}.'
|
||||
|
||||
if summary:
|
||||
if summary and self.llm:
|
||||
character_splitter = RecursiveCharacterTextSplitter.from_tiktoken_encoder(
|
||||
chunk_size=self.summary_chunk_tokens,
|
||||
chunk_overlap=self.summary_chunk_overlap,
|
||||
|
||||
Reference in New Issue
Block a user