Langchain-Chatchat/server/agent/tools/search_internet.py
liunux4odoo 03e55e11c4
支持lite模式:无需安装torch等重依赖,通过在线API实现LLM对话和搜索引擎对话 (#1860)
* move get_default_llm_model from webui to ApiRequest

增加API接口及其测试用例:
- /server/get_prompt_template: 获取服务器配置的 prompt 模板
- 增加知识库多线程访问测试用例

支持lite模式:无需安装torch等重依赖,通过在线API实现LLM对话和搜索引擎对话

* fix bug in server.api

---------

Co-authored-by: imClumsyPanda <littlepanda0716@gmail.com>
2023-10-25 08:30:23 +08:00

35 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import json
from server.chat.search_engine_chat import search_engine_chat
from configs import VECTOR_SEARCH_TOP_K
import asyncio
from server.agent import model_container
async def search_engine_iter(query: str):
response = await search_engine_chat(query=query,
search_engine_name="bing", # 这里切换搜索引擎
model_name=model_container.MODEL.model_name,
temperature=0.01, # Agent 搜索互联网的时候温度设置为0.01
history=[],
top_k = VECTOR_SEARCH_TOP_K,
max_tokens= None, # Agent 搜索互联网的时候max_tokens设置为None
prompt_name = "default",
stream=False)
contents = ""
async for data in response.body_iterator: # 这里的data是一个json字符串
data = json.loads(data)
contents = data["answer"]
docs = data["docs"]
return contents
def search_internet(query: str):
return asyncio.run(search_engine_iter(query))
if __name__ == "__main__":
result = search_internet("今天星期几")
print("答案:",result)