Giter Site home page Giter Site logo

zhiwo's Introduction

一.基本情况

项目采用agentuniverse框架搭建agent服务。

建议使用conda新增环境,并安装依赖:

conda create -n agent python=3.11
pip install -r requirements.txt

1.服务

每个服务对应一个agent,配置文件位于app/core/service/,搭建了以下服务:

  • get_sparql_service: 无参考信息,直接大模型推理得到查询语句;
  • get_sparql_by_rag_service: 带入参考信息,通过rag推理得到查询语句;
  • ccks2024_get_name_service:获取实体名称;
  • ccks2024_replace_name_service:替换实体名称;
  • ccks2024_get_answer_service:获取答案;
  • ccks2024_get_answer_repeater_service:循环推理获取答案;

2.agent

agent配置文件位于app/core/agent/,可以设置prompt、模型、工具等参数,结合具体情况进行修改与优化。如以下配置文件:

  • app/core/agent/get_sparql_agent/get_sparql_agent.yaml
  • app/core/agent/get_sparql_agent/get_sparql_by_rag_agent.yaml

其中通过设置knowledge_similarity_top_k,控制传入的知识库数量

action:
  knowledge:
    - 'sparql_train_knowledge'
  knowledge_similarity_top_k:
    6

3.rag

rag使用的是Infinity部署的Dmeta-embedding-zh模型API,按需使用与部署; 或根据需要配置其他模型;

目前get_sparql_by_rag_service中的rag根据题目与知识库中的题目进行相似度计算,返回相似度top_k个题目与查询语句作为 背景信息;如果需要修改返回的格式修改app/core/knowledge/sparql_knowledge/sparql_knowledge.py第69行。

doc.text = "问题:{}\tSPARQL查询语句:{}".format(doc.metadata.pop('question'),doc.metadata.pop('sparql'))

4.llm

大模型使用的是由vllm部署的glm9b模型,采用openAI风格接口,需要设置环境变量,在以下文件进行修改: config/custom_key.toml

二.需要修改的配置

config/custom_key.toml (设置自定义的环境变量,包括api_key、api_base等)

可选:

app/core/llm/qwen2_llm.yaml

app/core/agent/get_sparql_agent/get_sparql_agent.yaml

app/core/agent/get_sparql_agent/get_sparql_by_rag_agent.yaml

app/core/knowledge/sparql_knowledge/sparql_knowledge.py

(端口默认8080,可进行配置修改)config/gunicorn_config.toml

三.运行

pip install -r requirements.txt

cd app/bootstrap
python server_application.py

注:修改配置文件后需要重启服务

四.测试

app/test/test.ipynb中有API调用的基本示例

import json
import requests

def run_llm_service(question, service_id="get_sparql_service"):
    body = {
        "service_id": service_id,
        "params": {"input": question}
    }
    server_url = "http://127.0.0.1:8080/service_run"
    headers = { "Content-Type": "application/json" }
    response = requests.post(server_url, json=body, headers=headers)

    print(response.json())

zhiwo's People

Contributors

qi-hua avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.