mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-15 14:25:53 +08:00
fix: summary of duckduckgo_search (#5488)
This commit is contained in:
parent
48757e581e
commit
57063095c1
@ -2,9 +2,20 @@ from typing import Any
|
|||||||
|
|
||||||
from duckduckgo_search import DDGS
|
from duckduckgo_search import DDGS
|
||||||
|
|
||||||
|
from core.model_runtime.entities.message_entities import SystemPromptMessage
|
||||||
from core.tools.entities.tool_entities import ToolInvokeMessage
|
from core.tools.entities.tool_entities import ToolInvokeMessage
|
||||||
from core.tools.tool.builtin_tool import BuiltinTool
|
from core.tools.tool.builtin_tool import BuiltinTool
|
||||||
|
|
||||||
|
SUMMARY_PROMPT = """
|
||||||
|
User's query:
|
||||||
|
{query}
|
||||||
|
|
||||||
|
Here is the search engine result:
|
||||||
|
{content}
|
||||||
|
|
||||||
|
Please summarize the result in a few sentences.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class DuckDuckGoSearchTool(BuiltinTool):
|
class DuckDuckGoSearchTool(BuiltinTool):
|
||||||
"""
|
"""
|
||||||
@ -25,5 +36,12 @@ class DuckDuckGoSearchTool(BuiltinTool):
|
|||||||
results = [res.get("body") for res in response]
|
results = [res.get("body") for res in response]
|
||||||
results = "\n".join(results)
|
results = "\n".join(results)
|
||||||
if require_summary:
|
if require_summary:
|
||||||
results = self.summary(user_id=user_id, content=results)
|
results = self.summary_results(user_id=user_id, content=results, query=query)
|
||||||
return self.create_text_message(text=results)
|
return self.create_text_message(text=results)
|
||||||
|
|
||||||
|
def summary_results(self, user_id: str, content: str, query: str) -> str:
|
||||||
|
prompt = SUMMARY_PROMPT.format(query=query, content=content)
|
||||||
|
summary = self.invoke_model(user_id=user_id, prompt_messages=[
|
||||||
|
SystemPromptMessage(content=prompt),
|
||||||
|
], stop=[])
|
||||||
|
return summary.message.content
|
||||||
|
Loading…
x
Reference in New Issue
Block a user