{"id":13592866,"url":"https://github.com/ericzhang-cn/ailingbot","last_synced_at":"2025-04-13T05:34:50.797Z","repository":{"id":174909791,"uuid":"652967192","full_name":"ericzhang-cn/ailingbot","owner":"ericzhang-cn","description":"One-stop solution to empower your IM bot with AI.","archived":false,"fork":false,"pushed_at":"2023-07-28T03:12:27.000Z","size":4880,"stargazers_count":54,"open_issues_count":1,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-24T17:27:23.715Z","etag":null,"topics":["ai","bot","chatgpt","langchain"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericzhang-cn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-06-13T06:39:39.000Z","updated_at":"2024-04-03T10:12:51.000Z","dependencies_parsed_at":"2024-01-06T20:55:22.470Z","dependency_job_id":null,"html_url":"https://github.com/ericzhang-cn/ailingbot","commit_stats":null,"previous_names":["ericzhang-cn/ailingbot"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericzhang-cn%2Failingbot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericzhang-cn%2Failingbot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericzhang-cn%2Failingbot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericzhang-cn%2Failingbot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericzhang-cn","download_url":"https://codeload.github.com/ericzhang-cn/ailingbot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219846875,"owners_count":16556422,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","bot","chatgpt","langchain"],"created_at":"2024-08-01T16:01:14.137Z","updated_at":"2024-10-14T19:21:41.382Z","avatar_url":"https://github.com/ericzhang-cn.png","language":"Python","funding_links":[],"categories":["工具","Tools"],"sub_categories":["服务","Services"],"readme":"🇬🇧[English](https://github.com/ericzhang-cn/ailingbot/blob/main/README.md)\n🇨🇳[简体中文](https://github.com/ericzhang-cn/ailingbot/blob/main/README_zh_CN.md)\n\n---\n\n![Python package workflow](https://github.com/ericzhang-cn/ailingbot/actions/workflows/python-package.yml/badge.svg)\n![Pylint workflow](https://github.com/ericzhang-cn/ailingbot/actions/workflows/pylint.yml/badge.svg)\n![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/ericzhang-cn/ailingbot/main/img/logo.png\" alt=\"AilingBot\" width=\"300\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\u003cb\u003eAilingBot - One-stop solution to empower your IM bot with AI.\u003c/b\u003e\u003c/p\u003e\n\n# Table of Contents\n\n* [What is AilingBot](#what-is-ailingbot)\n* [Features](#features)\n* [Quick Start](#-quick-start)\n    * [Start an AI chatbot in 5 minutes](#start-an-ai-chatbot-in-5-minutes)\n        * [Using Docker](#using-docker)\n        * [Using PIP](#using-pip)\n            * [Installation](#installation)\n            * [Generate Configuration File](#generate-configuration-file)\n            * [Start the Chatbot](#start-the-chatbot)\n    * [Start API Service](#start-api-service)\n        * [Using Docker](#using-docker-1)\n        * [Using PIP](#using-pip-1)\n            * [Installation](#installation-1)\n            * [Generate Configuration File](#generate-configuration-file-1)\n            * [Start the Service](#start-the-service)\n    * [Integrating with WeChat Work](#integrating-with-wechat-work)\n        * [Using Docker](#using-docker-2)\n        * [Using PIP](#using-pip-2)\n            * [Installation](#installation-2)\n            * [Generate Configuration File](#generate-configuration-file-2)\n            * [Modify Configuration File](#modify-configuration-file)\n            * [Start the Service](#start-the-service-1)\n    * [Integrating with Feishu](#integrating-with-feishu)\n        * [Using Docker](#using-docker-3)\n        * [Using PIP](#using-pip-3)\n            * [Installation](#installation-3)\n            * [Generate Configuration File](#generate-configuration-file-3)\n            * [Modify Configuration File](#modify-configuration-file-1)\n            * [Start the Service](#start-the-service-2)\n    * [Integrating with DingTalk](#integrating-with-dingtalk)\n        * [Using Docker](#using-docker-4)\n        * [Using PIP](#using-pip-4)\n            * [Installation](#installation-4)\n            * [Generate Configuration File](#generate-configuration-file-4)\n            * [Modify Configuration File](#modify-configuration-file-2)\n            * [Start the Service](#start-the-service-3)\n    * [Integrating with Slack](#integrating-with-slack)\n        * [Using Docker](#using-docker-5)\n        * [Using PIP](#using-pip-5)\n            * [Installation](#installation-5)\n            * [Generate Configuration File](#generate-configuration-file-5)\n            * [Modify Configuration File](#modify-configuration-file-3)\n            * [Start the Service](#start-the-service-4)\n* [\u003cg-emoji class=\"g-emoji\" alias=\"book\" fallback-src=\"https://github.githubassets.com/images/icons/emoji/unicode/1f4d6.png\"\u003e📖\u003c/g-emoji\u003eUser Guide](#user-guide)\n    * [Main Process](#main-process)\n    * [Main Concepts](#main-concepts)\n    * [Configuration](#configuration)\n        * [Configuration Methods](#configuration-methods)\n        * [Configuration Mapping](#configuration-mapping)\n        * [Configuration Items](#configuration-items)\n            * [General](#general)\n            * [Built-in Policy Configuration](#built-in-policy-configuration)\n                * [conversation](#conversation)\n                * [document_qa](#document_qa)\n            * [Model Configuration](#model-configuration)\n                * [OpenAI](#openai)\n    * [Command Line Tools](#command-line-tools)\n        * [Initialize Configuration File (init)](#initialize-configuration-file-init)\n            * [Usage](#usage)\n            * [Options](#options)\n        * [View Current Configuration (config)](#view-current-configuration-config)\n            * [Usage](#usage-1)\n            * [Options](#options-1)\n        * [Start Command Line Bot (chat)](#start-command-line-bot-chat)\n            * [Usage](#usage-2)\n            * [Options](#options-2)\n        * [Start Webhook Service (serve)](#start-webhook-service-serve)\n            * [Usage](#usage-3)\n            * [Options](#options-3)\n        * [Start API Service (api)](#start-api-service-api)\n            * [Usage](#usage-4)\n            * [Options](#options-4)\n    * [\u003cg-emoji class=\"g-emoji\" alias=\"electric_plug\" fallback-src=\"https://github.githubassets.com/images/icons/emoji/unicode/1f50c.png\"\u003e🔌\u003c/g-emoji\u003eAPI](#api)\n* [\u003cg-emoji class=\"g-emoji\" alias=\"computer\" fallback-src=\"https://github.githubassets.com/images/icons/emoji/unicode/1f4bb.png\"\u003e💻\u003c/g-emoji\u003eDevelopment Guide](#development-guide)\n    * [Development Guidelines](#development-guidelines)\n    * [Developing Chat Policy](#developing-chat-policy)\n    * [Developing Channel](#developing-channel)\n* [\u003cg-emoji class=\"g-emoji\" alias=\"thinking\" fallback-src=\"https://github.githubassets.com/images/icons/emoji/unicode/1f914.png\"\u003e🤔\u003c/g-emoji\u003eFrequently Asked Questions](#frequently-asked-questions)\n* [\u003cg-emoji class=\"g-emoji\" alias=\"dart\" fallback-src=\"https://github.githubassets.com/images/icons/emoji/unicode/1f3af.png\"\u003e🎯\u003c/g-emoji\u003eRoadmap](#roadmap)\n\n# What is AilingBot\n\nAilingBot is an open-source engineering development framework and an all-in-one solution for integrating AI models into\nIM chatbots. With AilingBot, you can:\n\n- ☕ **Code-free usage**: Quickly integrate existing AI large-scale models into mainstream IM chatbots (such as WeChat\n  Work, Feishu, DingTalk, Slack etc.) to interact with AI models through IM chatbots and complete business\n  requirements. Currently, AilingBot has built-in capabilities for multi-turn dialogue and document knowledge Q\u0026A, and\n  more capabilities will be added in the future.\n- 🛠️**Secondary development**: AilingBot provides a clear engineering architecture, interface definition, and necessary\n  basic components. You do not need to develop the engineering framework for large-scale model services from scratch.\n  You only need to implement your Chat Policy and complete end-to-end AI model empowerment to IM chatbots through simple\n  configurations. It also supports expanding to your own end (such as your own IM, web application, or mobile\n  application) by developing your own channel.\n\n# Features\n\n- 💯 **Open source \u0026 Free**: Completely open source and free.\n- 📦 **Ready to use**: No need for development, with pre-installed capabilities to integrate with existing mainstream IM\n  and AI models.\n- 🔗 **LangChain Friendly**: Easy to integrate with LangChain.\n- 🧩 **Modular**: The project is organized in a modular way, with modules dependent on each other through abstract\n  protocols. Modules of the same type can be implemented by implementing the protocol, allowing for plug-and-play.\n- 💻 **Extensible**: AilingBot can be extended to new usage scenarios and capabilities. For example, integrating with new\n  IMs, new AI models, or customizing your own chat policy.\n- 🔥 **High performance**: AilingBot uses a coroutine-based asynchronous mode to improve system concurrency performance.\n  At the same time, system concurrency processing capabilities can be further improved through multi-processes.\n- 🔌 **API Integration**: AilingBot provides a set of clear API interfaces for easy integration and collaboration with\n  other systems and processes.\n\n# 🚀 Quick Start\n\n## Start an AI chatbot in 5 minutes\n\nBelow is a guide on how to quickly start an AI chatbot based on the command-line interface using AilingBot. The effect\nis shown in the following figure:\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/ericzhang-cn/ailingbot/main/img/command-line-screenshot.png\" alt=\"Command-line chatbot\"/\u003e\n\u003c/p\u003e\n\n\u003e 💡 First, you need to have an OpenAI API key. If you don't have one, refer to relevant materials on the Internet to\n\u003e obtain it.\n\n### Using Docker\n\n```shell\ngit clone https://github.com/ericzhang-cn/ailingbot.git ailingbot\ncd ailingbot\ndocker build -t ailingbot .\ndocker run -it --rm \\\n  -e  AILINGBOT_POLICY__LLM__OPENAI_API_KEY={your OpenAI API key} \\\n  ailingbot poetry run ailingbot chat\n```\n\n### Using PIP\n\n#### Installation\n\n```shell\npip install ailingbot\n```\n\n#### Generate Configuration File\n\n```shell\nailingbot init --silence --overwrite\n```\n\nThis will create a file called `settings.toml` in the current directory, which is the configuration file for AilingBot.\nNext, modify the necessary configurations. To start the bot, only one configuration is needed. Find the following\nsection in `settings.toml`:\n\n```toml\n[policy.llm]\n_type = \"openai\"\nmodel_name = \"gpt-3.5-turbo\"\nopenai_api_key = \"\"\ntemperature = 0\n```\n\nChange the value of `openai_api_key` to your actual OpenAI API key.\n\n#### Start the Chatbot\n\nStart the chatbot with the following command:\n\n```shell\nailingbot chat\n```\n\n## Start API Service\n\n### Using Docker\n\n```shell\ngit clone https://github.com/ericzhang-cn/ailingbot.git ailingbot\ncd ailingbot\ndocker build -t ailingbot .\ndocker run -it --rm \\\n  -e AILINGBOT_POLICY__LLM__OPENAI_API_KEY={your OpenAI API key} \\\n  -p 8080:8080 \\\n  ailingbot poetry run ailingbot api\n```\n\n### Using PIP\n\n#### Installation\n\n```shell\npip install ailingbot\n```\n\n#### Generate Configuration File\n\nSame as starting the command line bot.\n\n#### Start the Service\n\nStart the bot using the following command:\n\n```shell\nailingbot api\n```\n\nNow, enter `http://localhost:8080/docs` in your browser to see the API documentation. (If it is not a local start,\nplease enter `http://{your public IP}:8080/docs`)\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/ericzhang-cn/ailingbot/main/img/swagger.png\" alt=\"Swagger API Documentation\"/\u003e\n\u003c/p\u003e\n\nHere is an example request:\n\n```shell\ncurl -X 'POST' \\\n  'http://localhost:8080/chat/' \\\n  -H 'accept: application/json' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n  \"text\": \"你好\"\n}'\n```\n\nAnd the response:\n\n```json\n{\n  \"type\": \"text\",\n  \"conversation_id\": \"default_conversation\",\n  \"uuid\": \"afb35218-2978-404a-ab39-72a9db6f303b\",\n  \"ack_uuid\": \"3f09933c-e577-49a5-8f56-fa328daa136f\",\n  \"receiver_id\": \"anonymous\",\n  \"scope\": \"user\",\n  \"meta\": {},\n  \"echo\": {},\n  \"text\": \"你好！很高兴和你聊天。有什么我可以帮助你的吗？\",\n  \"reason\": null,\n  \"suggestion\": null\n}\n```\n\n## Integrating with WeChat Work\n\nHere's a guide on how to quickly integrate the chatbot with WeChat Work.\n\n### Using Docker\n\n```shell\ngit clone https://github.com/ericzhang-cn/ailingbot.git ailingbot\ncd ailingbot\ndocker build -t ailingbot .\ndocker run -d \\\n  -e AILINGBOT_POLICY__NAME=conversation \\\n  -e AILINGBOT_POLICY__HISTORY_SIZE=5 \\\n  -e AILINGBOT_POLICY__LLM__OPENAI_API_KEY={your OpenAI API key} \\\n  -e AILINGBOT_CHANNEL__NAME=wechatwork \\\n  -e AILINGBOT_CHANNEL__CORPID={your WeChat Work corpid} \\\n  -e AILINGBOT_CHANNEL__CORPSECRET={your WeChat Work corpsecret} \\\n  -e AILINGBOT_CHANNEL__AGENTID={your WeChat Work agentid} \\\n  -e AILINGBOT_CHANNEL__TOKEN={your WeChat Work webhook token} \\\n  -e AILINGBOT_CHANNEL__AES_KEY={your WeChat Work webhook aes_key} \\\n  -p 8080:8080 \\\n  ailingbot poetry run ailingbot serve\n```\n\n### Using PIP\n\n#### Installation\n\n```shell\npip install ailingbot\n```\n\n#### Generate Configuration File\n\n```shell\nailingbot init --silence --overwrite\n```\n\n#### Modify Configuration File\n\nOpen `settings.toml`, and fill in the following section with your WeChat Work robot's real information:\n\n```toml\n[channel]\nname = \"wechatwork\"\ncorpid = \"\" # Fill in with real information\ncorpsecret = \"\" # Fill in with real information\nagentid = 0 # Fill in with real information\ntoken = \"\" # Fill in with real information\naes_key = \"\" # Fill in with real information\n```\n\nIn the `llm` section, fill in your OpenAI API Key:\n\n```toml\n[policy.llm]\n_type = \"openai\"\nmodel_name = \"gpt-3.5-turbo\"\nopenai_api_key = \"\" # Fill in with your real OpenAI API Key here\ntemperature = 0\n```\n\n#### Start the Service\n\n```shell\nailingbot serve\n```\n\nFinally, we need to go to the WeChat Work admin console to configure the webhook address so that WeChat Work knows to\nforward the received user messages to our webhook.\nThe webhook URL is: `http(s)://your_public_IP:8080/webhook/wechatwork/event/`\n\nAfter completing the above configuration, you can find the chatbot in WeChat Work and start chatting:\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/ericzhang-cn/ailingbot/main/img/wechatwork-screenshot.png\" alt=\"WeChat Work chatbot\" width=\"300\"/\u003e\n\u003c/p\u003e\n\n## Integrating with Feishu\n\nHere's a guide on how to quickly integrate the chatbot with Feishu and enable a new conversation policy: uploading\ndocuments and performing knowledge-based question answering on them.\n\n### Using Docker\n\n```shell\ngit clone https://github.com/ericzhang-cn/ailingbot.git ailingbot\ncd ailingbot\ndocker build -t ailingbot .\ndocker run -d \\\n  -e AILINGBOT_POLICY__NAME=document_qa \\\n  -e AILINGBOT_POLICY__CHUNK_SIZE=1000 \\\n  -e AILINGBOT_POLICY__CHUNK_OVERLAP=0 \\\n  -e AILINGBOT_POLICY__LLM__OPENAI_API_KEY={your OpenAI API key} \\\n  -e AILINGBOT_POLICY__LLM__MODEL_NAME=gpt-3.5-turbo-16k \\\n  -e AILINGBOT_CHANNEL__NAME=feishu \\\n  -e AILINGBOT_CHANNEL__APP_ID={your Feishu app id} \\\n  -e AILINGBOT_CHANNEL__APP_SECRET={your Feishu app secret} \\\n  -e AILINGBOT_CHANNEL__VERIFICATION_TOKEN={your Feishu webhook verification token} \\\n  -p 8080:8080 \\\n  ailingbot poetry run ailingbot serve\n```\n\n### Using PIP\n\n#### Installation\n\n```shell\npip install ailingbot\n```\n\n#### Generate Configuration File\n\n```shell\nailingbot init --silence --overwrite\n```\n\n#### Modify Configuration File\n\nOpen `settings.toml`, and change the `channel` section to the following, filling in your Feishu robot's real\ninformation:\n\n```toml\n[channel]\nname = \"feishu\"\napp_id = \"\" # Fill in with real information\napp_secret = \"\" # Fill in with real information\nverification_token = \"\" # Fill in with real information\n```\n\nReplace the `policy` section with the following document QA policy:\n\n```toml\n[policy]\nname = \"document_qa\"\nchunk_size = 1000\nchunk_overlap = 5\n```\n\nFinally, it is recommended to use the 16k model when using the document QA policy. Therefore,\nchange `policy.llm.model_name` to the following configuration:\n\n```toml\n[policy.llm]\n_type = \"openai\"\nmodel_name = \"gpt-3.5-turbo-16k\" # Change to gpt-3.5-turbo-16k\nopenai_api_key = \"\" # Fill in with real information\ntemperature = 0\n```\n\n#### Start the Service\n\n```shell\nailingbot serve\n```\n\nFinally, we need to go to the Feishu admin console to configure the webhook address.\nThe webhook URL for Feishu is: `http(s)://your_public_IP:8080/webhook/feishu/event/`\n\nAfter completing the above configuration, you can find the chatbot in Feishu and start chatting:\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/ericzhang-cn/ailingbot/main/img/feishu-screenshot.png\" alt=\"Feishu chatbot\" width=\"1000\"/\u003e\n\u003c/p\u003e\n\n## Integrating with DingTalk\n\nHere's a guide on how to quickly integrate the chatbot with DingTalk.\n\n### Using Docker\n\n```shell\ngit clone https://github.com/ericzhang-cn/ailingbot.git ailingbot\ncd ailingbot\ndocker build -t ailingbot .\ndocker run -d \\\n  -e AILINGBOT_POLICY__NAME=conversation \\\n  -e AILINGBOT_POLICY__HISTORY_SIZE=5 \\\n  -e AILINGBOT_POLICY__LLM__OPENAI_API_KEY={your OpenAI API key} \\\n  -e AILINGBOT_CHANNEL__NAME=dingtalk \\\n  -e AILINGBOT_CHANNEL__APP_KEY={your DingTalk app key} \\\n  -e AILINGBOT_CHANNEL__APP_SECRET={your DingTalk app secret} \\\n  -e AILINGBOT_CHANNEL__ROBOT_CODE={your DingTalk robot code} \\\n  -p 8080:8080 \\\n  ailingbot poetry run ailingbot serve\n```\n\n### Using PIP\n\n#### Installation\n\n```shell\npip install ailingbot\n```\n\n#### Generate Configuration File\n\n```shell\nailingbot init --silence --overwrite\n```\n\n#### Modify Configuration File\n\nOpen `settings.toml`, and change the `channel` section to the following, filling in your DingTalk robot's real\ninformation:\n\n```toml\n[channel]\nname = \"dingtalk\"\napp_key = \"\" # Fill in with real information\napp_secret = \"\" # Fill in with real information\nrobot_code = \"\" # Fill in with real information\n```\n\n#### Start the Service\n\n```shell\nailingbot serve\n```\n\nFinally, we need to go to the DingTalk admin console to configure the webhook address.\nThe webhook URL for DingTalk is: `http(s)://your_public_IP:8080/webhook/dingtalk/event/`\n\nAfter completing the above configuration, you can find the chatbot in DingTalk and start chatting:\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/ericzhang-cn/ailingbot/main/img/dingtalk-screenshot.png\" alt=\"DingTalk chatbot\" /\u003e\n\u003c/p\u003e\n\n## Integrating with Slack\n\nHere's a guide on how to quickly integrate the chatbot with Slack and enable a new conversation policy: uploading\ndocuments and performing knowledge-based question answering on them.\n\n### Using Docker\n\n```shell\ngit clone https://github.com/ericzhang-cn/ailingbot.git ailingbot\ncd ailingbot\ndocker build -t ailingbot .\ndocker run -d \\\n  -e AILINGBOT_POLICY__NAME=document_qa \\\n  -e AILINGBOT_POLICY__CHUNK_SIZE=1000 \\\n  -e AILINGBOT_POLICY__CHUNK_OVERLAP=0 \\\n  -e AILINGBOT_POLICY__LLM__OPENAI_API_KEY={your OpenAI API key} \\\n  -e AILINGBOT_POLICY__LLM__MODEL_NAME=gpt-3.5-turbo-16k \\\n  -e AILINGBOT_CHANNEL__NAME=slack \\\n  -e AILINGBOT_CHANNEL__VERIFICATION_TOKEN={your Slack App webhook verification token} \\\n  -e AILINGBOT_CHANNEL__OAUTH_TOKEN={your Slack App oauth token} \\\n  -p 8080:8080 \\\n  ailingbot poetry run ailingbot serve\n```\n\n### Using PIP\n\n#### Installation\n\n```shell\npip install ailingbot\n```\n\n#### Generate Configuration File\n\n```shell\nailingbot init --silence --overwrite\n```\n\n#### Modify Configuration File\n\nOpen `settings.toml`, and change the `channel` section to the following, filling in your Slack robot's real information:\n\n```toml\n[channel]\nname = \"slack\"\nverification_token = \"\" # Fill in with real information\noauth_token = \"\" # Fill in with real information\n```\n\nReplace the `policy` section with the following document QA policy:\n\n```toml\n[policy]\nname = \"document_qa\"\nchunk_size = 1000\nchunk_overlap = 5\n```\n\nFinally, it is recommended to use the 16k model when using the document QA policy. Therefore,\nchange `policy.llm.model_name` to the following configuration:\n\n```toml\n[policy.llm]\n_type = \"openai\"\nmodel_name = \"gpt-3.5-turbo-16k\" # Change to gpt-3.5-turbo-16k\nopenai_api_key = \"\" # Fill in with real information\ntemperature = 0\n```\n\n#### Start the Service\n\n```shell\nailingbot serve\n```\n\nFinally, we need to go to the Slack admin console to configure the webhook address.\nThe webhook URL for Slack is: `http(s)://your_public_IP:8080/webhook/slack/event/`\n\nAfter completing the above configuration, you can find the chatbot in Slack and start chatting:\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/ericzhang-cn/ailingbot/main/img/slack-screenshot.png\" alt=\"Slack chatbot\" width=\"1000\"/\u003e\n\u003c/p\u003e\n\n# 📖User Guide\n\n## Main Process\n\nThe main processing flow of AilingBot is as follows:\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/ericzhang-cn/ailingbot/main/img/flow.png\" alt=\"Main Process\" width=\"500\"/\u003e\n\u003c/p\u003e\n\n1. First, the user sends a message to the IM bot.\n2. If a webhook is configured, the instant messaging tool will forward the request sent to the bot to the webhook\n   service address.\n3. The webhook service processes the original IM message and converts it into AilingBot's internal message format, which\n   is then sent to ChatBot.\n4. ChatBot processes the request and forms a response message based on the configured chat policy. During this process,\n   ChatBot may perform operations such as requesting a large language model, accessing a vector database, or calling an\n   external API to complete the request processing.\n5. ChatBot sends the response message to the IM Agent. The IM Agent is responsible for converting the AilingBot internal\n   response message format into a specific IM format and calling the IM open capability API to send the response\n   message.\n6. The IM bot displays the message to the user, completing the entire processing process.\n\n## Main Concepts\n\n- **IM bot**: A capability built into most instant messaging tools that allows administrators to create a bot and\n  process user messages through a program.\n- **Channel**: A channel represents different terminals, which can be an IM or a custom terminal (such as the web).\n- **Webhook**: An HTTP(S) service used to receive user messages forwarded by IM bots. Different channels have their own\n  specifications for webhooks, so each channel requires its own webhook implementation.\n- **IM Agent**: Used to call IM open capability APIs. Different IM open capability APIs are different, so each channel\n  requires a corresponding agent implementation.\n- **ChatBot**: The core component used to receive and respond to user messages.\n- **Chat Policy**: Defines how to respond to users and is called by ChatBot. A chat policy specifically defines the\n  robot's abilities, such as chitchat or knowledge Q\u0026A.\n- **LLM**: Large language model, such as OpenAI's ChatGPT and open ChatGLM, are all different large language models. The\n  large language model is a key component for implementing AI capabilities.\n\n## Configuration\n\n### Configuration Methods\n\nAilingBot can be configured in two ways:\n\n- **Using configuration files**: AilingBot reads `settings.toml` in the current directory as the configuration file\n  in [TOML](https://toml.io/en/) format. Please refer to the following section for specific configuration items.\n- **Using environment variables**: AilingBot also reads configuration items in environment variables. Please refer to\n  the following section for a list of environment variables.\n\n\u003e 💡 Both configuration files and environment variables can be used together. If a configuration item exists in both, the\n\u003e environment variable takes precedence.\n\n### Configuration Mapping\n\nAll configurations have the following mappings between TOML keys and environment variables:\n\n- All environment variables start with `AILINGBOT_`.\n- Double underscores `__` are used as separators between levels.\n- Underscores in configuration keys are preserved in environment variables.\n- Case-insensitive.\n\nFor example:\n\n- The corresponding environment variable of `some_conf` is `AILINGBOT_SOME_CONF`.\n- The corresponding environment variable of `some_conf.conf_1` is `AILINGBOT_SOME_CONF__CONF_1`.\n- The corresponding environment variable of `some_conf.conf_1.subconf` is `AILINGBOT_SOME_CONF__CONF_1__SUBCONF`.\n\n### Configuration Items\n\n#### General\n\n| Configuration Item | Description                                                                                                                                   | TOML                 | Environment Variable            |\n|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|----------------------|---------------------------------|\n| Language           | Language code (Reference: http://www.lingoes.net/en/translator/langcode.htm)                                                                  | lang                 | AILINGBOT_LANG                  |\n| Timezone           | Timezone code (Reference: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)                                                       | tz                   | AILINGBOT_TZ                    |\n| Policy Name        | Predefined policy name or complete policy class path                                                                                          | policy.name          | AILINGBOT_POLICY__NAME          |\n| Channel Name       | Predefined channel name                                                                                                                       | channel.name         | AILINGBOT_CHANNEL__NAME         |\n| Webhook Path       | Complete class path of non-predefined channel webhook                                                                                         | channel.webhook_name | AILINGBOT_CHANNEL__WEBHOOK_NAME |\n| Agent Path         | Complete class path of non-predefined channel agent                                                                                           | channel.agent_name   | AILINGBOT_CHANNEL__AGENT_NAME   |\n| Uvicorn Config     | All uvicorn configurations (Reference: [uvicorn settings](https://www.uvicorn.org/settings/)). These configurations will be passed to uvicorn | uvicorn.*            | AILINGBOT_UVICORN__*            |\n\nConfiguration example:\n\n```toml\nlang = \"zh_CN\"\ntz = \"Asia/Shanghai\"\n\n[policy]\nname = \"conversation\"\n# More policy configurations\n\n[channel]\nname = \"wechatwork\"\n# More channel configurations\n\n[uvicorn]\nhost = \"0.0.0.0\"\nport = 8080\n```\n\n#### Built-in Policy Configuration\n\n##### conversation\n\nConversation uses LangChain's Conversation as the policy, which enables direct interaction with LLM and has a\nconversation history context, enabling multi-turn conversations.\n\n| Configuration Item | Description                                                   | TOML                | Environment Variable           |\n|--------------------|---------------------------------------------------------------|---------------------|--------------------------------|\n| History Size       | Indicates how many rounds of historical conversations to keep | policy.history_size | AILINGBOT_POLICY__HISTORY_SIZE |\n\nConfiguration example:\n\n```toml\n# Use the conversation policy and keep 5 rounds of historical conversations\n[policy]\nname = \"conversation\"\nhistory_size = 5\n```\n\n##### document_qa\n\nDocument_qa uses LangChain's [Stuff](https://python.langchain.com/docs/modules/chains/document/stuff) as the policy.\nUsers can upload a document and then ask questions based on the document content.\n\n| Configuration Item | Description                                       | TOML                 | Environment Variable            |\n|--------------------|---------------------------------------------------|----------------------|---------------------------------|\n| Chunk Size         | Corresponds to LangChain Splitter's chunk_size    | policy.chunk_size    | AILINGBOT_POLICY__CHUNK_SIZE    |\n| Chunk Overlap      | Corresponds to LangChain Splitter's chunk_overlap | policy.chunk_overlap | AILINGBOT_POLICY__CHUNK_OVERLAP |\n\nConfiguration example:\n\n```toml\n# Use the document_qa policy, with chunk_size and chunk_overlap set to 1000 and 0, respectively\n[policy]\nname = \"document_qa\"\nchunk_size = 1000\nchunk_overlap = 0\n```\n\n#### Model Configuration\n\nThe model configuration is consistent with LangChain. The following is an example.\n\n##### OpenAI\n\n```toml\n[policy.llm]\n_type = \"openai\" # Corresponding environment variable: AILINGBOT_POLICY__LLM___TYPE\nmodel_name = \"gpt-3.5-turbo\" # Corresponding environment variable: AILINGBOT_POLICY__LLM__MODEL_NAME\nopenai_api_key = \"sk-pd*****************************aAb\" # Corresponding environment variable: AILINGBOT_POLICY__LLM__OPENAI_API_KEY\n```\n\n## Command Line Tools\n\n### Initialize Configuration File (init)\n\n#### Usage\n\nThe `init` command generates a configuration file `settings.toml` in the current directory. By default, the user will be\nprompted interactively. You can use the `--silence` option to generate the configuration file directly using default\nsettings.\n\n```text\nUsage: ailingbot init [OPTIONS]\n\nInitialize the AilingBot environment.\n\nOptions:\n--silence    Without asking the user.\n--overwrite  Overwrite existing file if a file with the same name already\nexists.\n--help       Show this message and exit.\n```\n\n#### Options\n\n| Option      | Description                                                          | Type | Remarks |\n|-------------|----------------------------------------------------------------------|------|---------|\n| --silence   | Generate the default configuration directly without asking the user. | Flag |         |\n| --overwrite | Allow overwriting the `settings.toml` file in the current directory. | Flag |         |\n\n### View Current Configuration (config)\n\nThe `config` command reads the current environment configuration (including the configuration file and environment\nvariables) and merges them.\n\n#### Usage\n\n```text\nUsage: ailingbot config [OPTIONS]\n\n  Show current configuration information.\n\nOptions:\n  -k, --config-key TEXT  Configuration key.\n  --help                 Show this message and exit.\n```\n\n#### Options\n\n| Option           | Description       | Type   | Remarks                                                                  |\n|------------------|-------------------|--------|--------------------------------------------------------------------------|\n| -k, --config-key | Configuration key | String | If not passed, the complete configuration information will be displayed. |\n\n### Start Command Line Bot (chat)\n\nThe `chat` command starts an interactive command-line bot for testing the current chat policy.\n\n#### Usage\n\n```text\nUsage: ailingbot chat [OPTIONS]\n\n  Start an interactive bot conversation environment.\n\nOptions:\n  --debug  Enable debug mode.\n  --help   Show this message and exit.\n```\n\n#### Options\n\n| Option  | Description       | Type | Remarks                                                          |\n|---------|-------------------|------|------------------------------------------------------------------|\n| --debug | Enable debug mode | Flag | The debug mode will output more information, such as the prompt. |\n\n### Start Webhook Service (serve)\n\nThe `serve` command starts a Webhook HTTP server for interacting with specific IM.\n\n#### Usage\n\n```text\nUsage: ailingbot serve [OPTIONS]\n\n  Run webhook server to receive events.\n\nOptions:\n  --log-level [TRACE|DEBUG|INFO|SUCCESS|WARNING|ERROR|CRITICAL]\n                                  The minimum severity level from which logged\n                                  messages should be sent to(read from\n                                  environment variable AILINGBOT_LOG_LEVEL if\n                                  is not passed into).  [default: TRACE]\n  --log-file TEXT                 STDOUT, STDERR, or file path(read from\n                                  environment variable AILINGBOT_LOG_FILE if\n                                  is not passed into).  [default: STDERR]\n  --help                          Show this message and exit.\n```\n\n#### Options\n\n| Option      | Description                                                              | Type   | Remarks                                                     |\n|-------------|--------------------------------------------------------------------------|--------|-------------------------------------------------------------|\n| --log-level | The minimum severity level from which logged messages should be sent to. | String | By default, all log levels will be displayed (TRACE).       |\n| --log-file  | The location where logs are output.                                      | String | By default, logs will be output to standard error (STDERR). |\n\n### Start API Service (api)\n\nThe `api` command starts the API HTTP server.\n\n#### Usage\n\n```text\nUsage: ailingbot api [OPTIONS]\n\nRun endpoint server.\n\nOptions:\n  --log-level [TRACE|DEBUG|INFO|SUCCESS|WARNING|ERROR|CRITICAL]\n                                  The minimum severity level from which logged\n                                  messages should be sent to(read from\n                                  environment variable AILINGBOT_LOG_LEVEL if\n                                  is not passed into).  [default: TRACE]\n  --log-file TEXT                 STDOUT, STDERR, or file path(read from\n                                  environment variable AILINGBOT_LOG_FILE if\n                                  is not passed into).  [default: STDERR]\n  --help                          Show this message and exit.\n```\n\n#### Options\n\n| Option      | Description                                                        | Type   | Remarks                                                 |\n|-------------|--------------------------------------------------------------------|--------|---------------------------------------------------------|\n| --log-level | Display log level, which will display logs at this level and above | String | By default, all levels are displayed (TRACE)            |\n| --log-file  | Log output location                                                | String | By default, logs are printed to standard error (STDERR) |\n\n## 🔌API\n\nTBD\n\n# 💻Development Guide\n\n## Development Guidelines\n\nTBD\n\n## Developing Chat Policy\n\nTBD\n\n## Developing Channel\n\nTBD\n\n# 🤔Frequently Asked Questions\n\n- Due to the fact that WeChat Work does not support uploading file event callbacks, the built-in `document_qa`\n  policy cannot be used for WeChat Work.\n- The webhook of each IM requires a public IP. If you do not have one, you can consider testing locally through the \"\n  intranet penetration\" solution. Please refer to online resources for specific methods.\n- We expect the chat policy to be stateless, and the state should be stored externally. However, in specific\n  implementations, the policy may still have local states (such as storing conversation history in local variables).\n  Therefore, when uvicorn has multiple worker processes, these local states cannot be shared because each process has a\n  separate chat policy instance, and a request from the same user may be responded to by different workers, leading to\n  unexpected behavior. To avoid this, please ensure that at least one of the following two conditions is met:\n    - Chat policy does not use local states.\n    - Only one uvicorn worker is started.\n\n# 🎯Roadmap\n\n- [ ] Provide complete usage and developer documentation.\n- [ ] Support more channels.\n    - [x] WeChat Work\n    - [x] Feishu\n    - [x] DingTalk\n    - [x] Slack\n- [ ] Support more request message types.\n    - [x] Text request\n    - [ ] Image request\n    - [x] File request\n- [ ] Support more response message types.\n    - [x] Text response\n    - [ ] Image response\n    - [ ] File response\n    - [ ] Markdown response\n    - [ ] Table response\n- [ ] Develop more out-of-the-box chat policies.\n    - [x] Multi-round conversation policy\n    - [x] Document question and answer policy\n    - [ ] Database question and answer policy\n    - [ ] Online search question and answer policy\n- [ ] Support calling standalone chat policy services through HTTP.\n- [ ] Abstract basic components\n    - [ ] Large language model\n    - [ ] Knowledge base\n    - [ ] Tools\n- [ ] Support local model deployment.\n    - [ ] ChatGLM-6B\n- [x] Support API.\n- [ ] Web management dashboard.\n- [x] Provide deployment capability based on Docker containers.\n- [ ] Enhance the observability and controllability of the system.\n- [ ] Complete test cases.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericzhang-cn%2Failingbot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericzhang-cn%2Failingbot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericzhang-cn%2Failingbot/lists"}