Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
yym68686 committed Sep 24, 2024
1 parent 264c5f8 commit c7d7390
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 79 deletions.
68 changes: 0 additions & 68 deletions README-zh.md

This file was deleted.

53 changes: 42 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# modelmerge

[English](./README.md) | [Chinese](./README-zh.md)
[English](./README.md) | [Chinese](./README_CN.md)

modelmerge is a powerful library designed to simplify and unify the usage of different large language models, including GPT-3.5/4/4 Turbo/4o/4o mini, DALL-E 3, Claude2/3/3.5, Gemini1.5 Pro/Flash, Vertex AI (Claude, Gemini), DuckDuckGo, and Groq. The library supports GPT-format function calls and has built-in Google search and URL summarization features, greatly enhancing the practicality and flexibility of the models.
modelmerge is a powerful library designed to simplify and unify the use of different large language models, including GPT-3.5/4/4 Turbo/4o, o1-preview/o1-mini, DALL-E 3, Claude2/3/3.5, Gemini1.5 Pro/Flash, Vertex AI (Claude, Gemini), DuckDuckGo, and Groq. The library supports GPT format function calls and has built-in Google search and URL summarization features, greatly enhancing the practicality and flexibility of the models.

## Characteristics
## ✨ Features

- **Multi-model support**: Integrate various latest large language models.
- **Real-time Interaction**: Supports real-time query streams, real-time model response retrieval.
- **Function Expansion**: With built-in function call support, the model's capabilities can be easily extended, such as performing web searches or content summarization.
- **Simple Interface**: Provides a concise API interface, making it easy to call and manage models.
- **Function Expansion**: With built-in function calling support, the model's functions can be easily expanded, currently supporting plugins such as DuckDuckGo and Google search, content summarization, Dalle-3 drawing, arXiv paper summaries, current time, code interpreter, and more.
- **Simple Interface**: Provides a concise and unified API interface, making it easy to call and manage the model.

## Quick Start

Expand All @@ -30,31 +30,62 @@ The following is a simple example demonstrating how to use modelmerge to request
```python
from ModelMerge import chatgpt

# Initialize the model, set the API key and selected model
# Initialize the model, set the API key and the selected model
bot = chatgpt(api_key="{YOUR_API_KEY}", engine="gpt-4o")

# Get the answer
# Get response
result = bot.ask("python list use")

# Send the request and get the streaming response in real-time
# Send request and get streaming response in real-time
for text in bot.ask_stream("python list use"):
print(text, end="")

# Disable all plugins
bot = chatgpt(api_key="{YOUR_API_KEY}", engine="gpt-4o", use_plugins=False)
```

## Configuration
## 🍃 Environment Variables

The following is a list of environment variables related to plugin settings:

You can adjust the parameters of different models by modifying the configuration file, including API key, model selection, etc.
| Variable Name | Description | Required? |
|---------------|-------------|-----------|
| SEARCH | Enable search plugin. Default value is `True`. | No |
| URL | Enable URL summary plugin. The default value is `True`. | No |
| ARXIV | Whether to enable the arXiv paper abstract plugin. The default value is `False`. | No |
| CODE | Whether to enable the code interpreter plugin. The default value is `False`. | No |
| IMAGE | Whether to enable the image generation plugin. The default value is `False`. | No |
| DATE | Whether to enable the date plugin. The default value is `False`. | No |

## Supported models

- GPT-3.5/4/4 Turbo/4o/4o mini
- GPT-3.5/4/4 Turbo/4o
- o1-preview/o1-mini
- DALL-E 3
- Claude2/3/3.5
- Gemini1.5 Pro/Flash
- Vertex AI (Claude, Gemini)
- Groq
- DuckDuckGo(gpt-4o-mini, claude-3-haiku, Meta-Llama-3.1-70B, Mixtral-8x7B)

## 🧩 Plugin

This project supports multiple plugins, including: DuckDuckGo and Google search, URL summary, ArXiv paper summary, DALLE-3 drawing, and code interpreter, etc. You can enable or disable these plugins by setting environment variables.

- How to develop a plugin?

All the code related to plugins is in the git submodule ModelMerge within this repository. ModelMerge is an independent repository that I developed to handle API requests, conversation history management, and other functions. When you clone this repository using the `--recurse-submodules` parameter with git clone, ModelMerge will be automatically downloaded to your local machine. All the plugin code in this repository is located at the relative path `ModelMerge/src/ModelMerge/plugins`. You can add your own plugin code in this directory. The plugin development process is as follows:

1. Create a new Python file in the `ModelMerge/src/ModelMerge/plugins` directory, for example, `myplugin.py`. Import your plugin in the `ModelMerge/src/ModelMerge/plugins/__init__.py` file, for example, `from .myplugin import MyPlugin`.

2. Add your plugin OpenAI tool formatted request body to the `function_call_list` variable in `ModelMerge/src/ModelMerge/tools/chatgpt.py`. The Claude Gemini tool does not require additional writing, you only need to fill in the tool request body in the OpenAI format, and the program will automatically convert it to the Claude/Gemini tool format when requesting the Gemini or Claude API. `function_call_list` is a dictionary where the key is the name of the plugin and the value is the request body of the plugin. Please ensure the key names in the `function_call_list` dictionary are unique and do not duplicate existing plugin key names.

3. Add key-value pairs to the `PLUGINS` dictionary in `ModelMerge/src/ModelMerge/plugins/config.py`. The key is the name of the plugin, and the value is the environment variable of the plugin and its default value. This default value is the switch for the plugin; if the default value is `True`, then the plugin is enabled by default. If the default value is `False`, then the plugin is disabled by default and needs to be manually enabled by the user in the `/info` command.

4. Finally, in the `ModelMerge/src/ModelMerge/plugins/config.py` functions `get_tools_result_async` and `get_tools_result`, add the code for plugin invocation. When the robot needs to call a plugin, it will call this function. You need to add the plugin invocation code within this function.

After completing the above steps, your plugin will be ready to use. 🎉

## License

This project is licensed under the MIT License.
Expand Down
99 changes: 99 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# modelmerge

[英文](./README.md) | [中文](./README_CN.md)

modelmerge 是一个强大的库,旨在简化和统一不同大型语言模型的使用,包括 GPT-3.5/4/4 Turbo/4o、o1-preview/o1-mini、DALL-E 3、Claude2/3/3.5、Gemini1.5 Pro/Flash、Vertex AI(Claude, Gemini) 、DuckDuckGo 和 Groq。该库支持 GPT 格式的函数调用,并内置了 Google 搜索和 URL 总结功能,极大地增强了模型的实用性和灵活性。

## ✨ 特性

- **多模型支持**:集成多种最新的大语言模型。
- **实时交互**:支持实时查询流,实时获取模型响应。
- **功能扩展**:通过内置的函数调用(function calling)支持,可以轻松扩展模型的功能,目前支持 DuckDuckGo 和 Google 搜索、内容摘要、Dalle-3画图、arXiv 论文总结、当前时间、代码解释器等插件。
- **简易接口**:提供简洁统一的 API 接口,使得调用和管理模型变得轻松。

## 快速上手

以下是如何在您的 Python 项目中快速集成和使用 modelmerge 的指南。

### 安装

首先,您需要安装 modelmerge。可以通过 pip 直接安装:

```bash
pip install modelmerge
```

### 使用示例

以下是一个简单的示例,展示如何使用 modelmerge 来请求 GPT-4 模型并处理返回的流式数据:

```python
from ModelMerge import chatgpt

# 初始化模型,设置 API 密钥和所选模型
bot = chatgpt(api_key="{YOUR_API_KEY}", engine="gpt-4o")

# 获取回答
result = bot.ask("python list use")

# 发送请求并实时获取流式响应
for text in bot.ask_stream("python list use"):
print(text, end="")

# 关闭所有插件
bot = chatgpt(api_key="{YOUR_API_KEY}", engine="gpt-4o", use_plugins=False)
```

## 🍃 环境变量

以下是跟插件设置相关的环境变量列表:

| 变量名称 | 描述 | 必需的? |
|---------------|-------------|-----------|
| SEARCH | 是否启用搜索插件。默认值为 `True`||
| URL | 是否启用URL摘要插件。默认值为 `True`||
| ARXIV | 是否启用arXiv论文摘要插件。默认值为 `False`||
| CODE | 是否启用代码解释器插件。默认值为 `False`||
| IMAGE | 是否启用图像生成插件。默认值为 `False`||
| DATE | 是否启用日期插件。默认值为 `False`||

## 支持的模型

- GPT-3.5/4/4 Turbo/4o
- o1-preview/o1-mini
- DALL-E 3
- Claude2/3/3.5
- Gemini1.5 Pro/Flash
- Vertex AI(Claude, Gemini)
- Groq
- DuckDuckGo(gpt-4o-mini, claude-3-haiku, Meta-Llama-3.1-70B, Mixtral-8x7B)

## 🧩 插件

本项目支持多种插件,包括:DuckDuckGo 和 Google 搜索、URL 摘要、ArXiv 论文摘要、DALLE-3 画图和代码解释器等。您可以通过设置环境变量来启用或禁用这些插件。

- 如何开发插件?

插件相关的代码全部在本仓库git 子模块ModelMerge里面,ModelMerge是我开发的一个独立的仓库,用于处理API请求,对话历史记录管理等功能。当你使用git clone的--recurse-submodules参数克隆本仓库后,ModelMerge会自动下载到本地。插件所有的代码在本仓库中的相对路径为 `ModelMerge/src/ModelMerge/plugins`。你可以在这个目录下添加自己的插件代码。插件开发的流程如下:

1.`ModelMerge/src/ModelMerge/plugins` 目录下创建一个新的 Python 文件,例如 `myplugin.py`。在 `ModelMerge/src/ModelMerge/plugins/__init__.py` 文件中导入你的插件,例如 `from .myplugin import MyPlugin`

2.`ModelMerge/src/ModelMerge/tools/chatgpt.py` 里面的 `function_call_list` 变量中添加你的插件OpenAI tool格式详细的请求体。Claude Gemini tool 不需要额外编写,你仅需要填写OpenAI格式的tool请求体,程序在请求Gemini或者Claude API的时候,会自动转换为Claude/Gemini tool格式。`function_call_list` 是一个字典,键是插件的名称,值是插件的请求体。请保证`function_call_list` 字典的键名保证唯一性,不能和已有的插件键名重复。

3.`ModelMerge/src/ModelMerge/plugins/config.py` 里面的 `PLUGINS` 字典里面添加键值对,键是插件的名称,值是插件的环境变量及其默认值。这个默认值是插件的开关,如果默认值是`True`,那么插件默认是开启的,如果默认值是 `False`,那么插件默认是关闭的,需要在用户在 `/info` 命令里面手动开启。

4. 最后,在 `ModelMerge/src/ModelMerge/plugins/config.py` 里面的函数 `get_tools_result_async``get_tools_result` 添加插件调用的代码,当机器人需要调用插件的时候,会调用这个函数。你需要在这个函数里面添加插件的调用代码。

完成上面的步骤,你的插件就可以使用了。🎉

## 许可证

本项目采用 MIT 许可证授权。

## 贡献

欢迎通过 GitHub 提交问题或拉取请求来贡献改进。

## 联系方式

如有任何疑问或需要帮助,请通过 [yym68686@outlook.com](mailto:yym68686@outlook.com) 联系我们。

0 comments on commit c7d7390

Please sign in to comment.