Browse Source

V0.1.0

pull/1/head
gjl 1 year ago
parent
commit
0b496b0285
5 changed files with 10 additions and 40 deletions
  1. +1
    -4
      src/mindpilot/app/api/chat_routes.py
  2. +1
    -1
      src/mindpilot/app/configs/tool_config.py
  3. +2
    -27
      src/mindpilot/app/tools/search_internet.py
  4. +3
    -5
      src/mindpilot/app/tools/weather_check.py
  5. +3
    -3
      src/mindpilot/app/tools/wolfram.py

+ 1
- 4
src/mindpilot/app/api/chat_routes.py View File

@@ -19,13 +19,10 @@ from .openai_routes import openai_request
chat_router = APIRouter(prefix="/chat", tags=["MindPilot对话"])

chat_router.post(
"/chat",
"/chat/online",
summary="与llm模型对话",
)(chat)

# 定义全局model信息,用于给Text2Sql中的get_ChatOpenAI提供model_name
global_model_name = None


# @chat_router.post("/chat/completions", summary="兼容 openai 的统一 chat 接口")
# async def chat_completions(


+ 1
- 1
src/mindpilot/app/configs/tool_config.py View File

@@ -26,7 +26,7 @@ TOOL_CONFIG = {
"result_len": 3,
"metaphor_api_key": "",
"split_result": False,
"chunk_size": 500,
"chunk_size": 1000,
"chunk_overlap": 0,
},
"duckduckgo": {"result_len": 3},


+ 2
- 27
src/mindpilot/app/tools/search_internet.py View File

@@ -6,6 +6,7 @@ from langchain_community.utilities import BingSearchAPIWrapper
from langchain_community.utilities import DuckDuckGoSearchAPIWrapper
from markdownify import markdownify
from strsimpy.normalized_levenshtein import NormalizedLevenshtein
from app.utils import get_tool_config

from ..pydantic_v1 import Field
# from chatchat.server.utils import get_tool_config
@@ -112,31 +113,5 @@ def search_engine(query: str, config: dict):
@regist_tool(title="互联网搜索")
def search_internet(query: str = Field(description="query for Internet search")):
"""Use this tool to use bing search engine to search the internet and get information."""
# TODO 设计配置文件
tool_config = {
"use": False,
"search_engine_name": "bing",
"search_engine_config": {
"bing": {
"result_len": 3,
"bing_search_url": "https://api.bing.microsoft.com/v7.0/search",
"bing_key": "0f42b09dce16474a81c01562ded071dc",
},
"metaphor": {
"result_len": 3,
"metaphor_api_key": "",
"split_result": False,
"chunk_size": 5000,
"chunk_overlap": 0,
},
"duckduckgo": {"result_len": 3},
},
"top_k": 10,
"verbose": "Origin",
"conclude_prompt": "<指令>这是搜索到的互联网信息,请你根据这些信息进行提取并有调理,简洁的回答问题。如果无法从中得到答案,请说 “无法搜索到能回答问题的内容”。 "
"</指令>\n<已知信息>{{ context }}</已知信息>\n"
"<问题>\n"
"{{ question }}\n"
"</问题>\n",
}
tool_config = get_tool_config("search_internet")
return BaseToolOutput(search_engine(query=query, config=tool_config))

+ 3
- 5
src/mindpilot/app/tools/weather_check.py View File

@@ -4,10 +4,11 @@
import requests

from ..pydantic_v1 import Field
# from chatchat.server.utils import get_tool_config

from .tools_registry import BaseToolOutput, regist_tool

from app.utils import get_tool_config


@regist_tool(title="天气查询")
def weather_check(
@@ -15,10 +16,7 @@ def weather_check(
):
"""Use this tool to check the weather at a specific city"""

tool_config = {
"use": False,
"api_key": "SE7CGiRD5dvls08Ub",
}
tool_config = get_tool_config("weather_check")
api_key = tool_config.get("api_key")
url = f"https://api.seniverse.com/v3/weather/now.json?key={api_key}&location={city}&language=zh-Hans&unit=c"
response = requests.get(url)


+ 3
- 3
src/mindpilot/app/tools/wolfram.py View File

@@ -1,8 +1,7 @@
# Langchain 自带的 Wolfram Alpha API 封装

from ..pydantic_v1 import Field
# from chatchat.server.utils import get_tool_config

from app.utils import get_tool_config
from .tools_registry import BaseToolOutput, regist_tool


@@ -12,8 +11,9 @@ def wolfram(query: str = Field(description="The formula to be calculated")):

from langchain.utilities.wolfram_alpha import WolframAlphaAPIWrapper

appid = get_tool_config("appid")
wolfram = WolframAlphaAPIWrapper(
wolfram_alpha_appid="PWKVLW-6ETR93QX6Q"
wolfram_alpha_appid=appid
)
ans = wolfram.run(query)
return BaseToolOutput(ans)

Loading…
Cancel
Save