Browse Source

feat:增加获取工具API

main
gjl 1 year ago
parent
commit
993f8d0b70
10 changed files with 22 additions and 40 deletions
  1. +2
    -3
      src/mindpilot/app/api/api_schemas.py
  2. +3
    -14
      src/mindpilot/app/api/api_server.py
  3. +11
    -0
      src/mindpilot/app/api/tool_routes.py
  4. +2
    -1
      src/mindpilot/app/chat/chat.py
  5. +0
    -18
      src/mindpilot/app/configs/tool_config.py
  6. +1
    -1
      src/mindpilot/app/tools/search_internet.py
  7. +1
    -1
      src/mindpilot/app/tools/weather_check.py
  8. +1
    -1
      src/mindpilot/app/tools/wolfram.py
  9. +0
    -0
      src/mindpilot/app/utils/system_utils.py
  10. +1
    -1
      src/mindpilot/main.py

+ 2
- 3
src/mindpilot/app/api/api_schemas.py View File

@@ -12,15 +12,14 @@ from openai.types.chat import (
completion_create_params,
)

from ..utils.openai_utils import MsgType
from ..utils.system_utils import MsgType

# from chatchat.configs import DEFAULT_LLM_MODEL, TEMPERATURE
DEFAULT_LLM_MODEL = None # TODO 配置文件
DEFAULT_LLM_MODEL = None # TODO 配置文件
TEMPERATURE = 0.8
from ..pydantic_v2 import AnyUrl, BaseModel, Field



class OpenAIBaseInput(BaseModel):
user: Optional[str] = None
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.


+ 3
- 14
src/mindpilot/app/api/api_server.py View File

@@ -1,18 +1,9 @@
import argparse
import os
from typing import Literal

import uvicorn
from fastapi import Body, FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from starlette.responses import RedirectResponse

from .chat_routes import chat_router
# from .openai_routes import openai_router
# from .server_routes import server_router
# from .tool_routes import tool_router
# from chatchat.server.chat.completion import completion
from .tool_routes import tool_router


def create_app(run_mode: str = None):
@@ -30,8 +21,6 @@ def create_app(run_mode: str = None):
return RedirectResponse(url="/docs")

app.include_router(chat_router)
# app.include_router(tool_router)
# app.include_router(openai_router)
# app.include_router(server_router)
app.include_router(tool_router)

return app
return app

+ 11
- 0
src/mindpilot/app/api/tool_routes.py View File

@@ -0,0 +1,11 @@
from fastapi import APIRouter
from ..utils.system_utils import get_tool

tool_router = APIRouter(prefix="/tools", tags=["MindPilot对话"])


@tool_router.get("/available_tools", summary="获取可用工具")
async def get_available_tools():
all_tools = get_tool().values()
tool_names = [tool.name for tool in all_tools]
return {"tools": tool_names}

+ 2
- 1
src/mindpilot/app/chat/chat.py View File

@@ -17,7 +17,7 @@ from ..callback_handler.agent_callback_handler import (
)
from ..chat.utils import History
from ..configs import MODEL_CONFIG, TOOL_CONFIG
from ..utils.openai_utils import get_ChatOpenAI, get_prompt_template, get_tool, wrap_done, MsgType
from ..utils.system_utils import get_ChatOpenAI, get_prompt_template, get_tool, wrap_done, MsgType


def create_models_from_config(configs, callbacks, stream):
@@ -102,6 +102,7 @@ async def chat(
callbacks=callbacks, configs=chat_model_config, stream=stream
)
all_tools = get_tool().values()
print(all_tools)
tool_configs = tool_config or TOOL_CONFIG
tools = [tool for tool in all_tools if tool.name in tool_configs]
tools = [t.copy(update={"callbacks": callbacks}) for t in tools]


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

@@ -49,9 +49,6 @@ TOOL_CONFIG = {
"use": False,
"api_key": "SE7CGiRD5dvls08Ub",
},
# "search_youtube": {
# "use": False,
# },
"wolfram": {
"use": False,
"appid": "PWKVLW-6ETR93QX6Q",
@@ -59,19 +56,4 @@ TOOL_CONFIG = {
"calculate": {
"use": False,
},
# "vqa_processor": {
# "use": False,
# "model_path": "your model path",
# "tokenizer_path": "your tokenizer path",
# "device": "cuda:1",
# },
# "aqa_processor": {
# "use": False,
# "model_path": "your model path",
# "tokenizer_path": "yout tokenizer path",
# "device": "cuda:2",
# },
# "text2images": {
# "use": False,
# },
}

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

@@ -12,7 +12,7 @@ from ..pydantic_v1 import Field
# from chatchat.server.utils import get_tool_config

from .tools_registry import BaseToolOutput, regist_tool
from ..utils.openai_utils import get_tool_config
from ..utils.system_utils import get_tool_config


def bing_search(text, config):


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

@@ -6,7 +6,7 @@ import requests
from ..pydantic_v1 import Field

from .tools_registry import BaseToolOutput, regist_tool
from ..utils.openai_utils import get_tool_config
from ..utils.system_utils import get_tool_config


@regist_tool(title="天气查询")


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

@@ -3,7 +3,7 @@
from ..pydantic_v1 import Field

from .tools_registry import BaseToolOutput, regist_tool
from ..utils.openai_utils import get_tool_config
from ..utils.system_utils import get_tool_config


@regist_tool


src/mindpilot/app/utils/openai_utils.py → src/mindpilot/app/utils/system_utils.py View File


+ 1
- 1
src/mindpilot/main.py View File

@@ -39,7 +39,7 @@ def run_api_server(
):
import uvicorn
from app.api.api_server import create_app
from src.mindpilot.app.utils.openai_utils import set_httpx_config
from src.mindpilot.app.utils.system_utils import set_httpx_config

set_httpx_config()
app = create_app(run_mode=run_mode)


Loading…
Cancel
Save