Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ TONGYI_API_KEY = ''
# 通义千问使用的模型
TONGYI_MODEL='qwen-plus'

# fastGPT
FASTGPT_API_KEY = ''
FASTGPT_API_URL = ''
FASTGPT_MODEL = 'Qwen-turbo'

# 白名单配置
#定义机器人的名称,这里是为了防止群聊消息太多,所以只有艾特机器人才会回复,
#这里不要把@去掉,在@后面加上你启动机器人账号的微信名称
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@

由于openai充值需要国外信用卡,流程比较繁琐,大多需要搞国外虚拟卡,手续费也都不少,该平台可以直接支付宝,算是比较省事的,注册填问卷可领1刀额度,后续充值也有手续费,用户可自行酌情选择。

- fastGPT

地址:[fastGPT](https://cloud.fastgpt.cn/app/list), 创建你的应用之后, 获取到你的 api key 之后, 填写到 .env 文件中即可, 也支持私有化部署fastGPT版本

```sh
# 执行下面命令,拷贝一份 .env.example 文件为 .env
cp .env.example .env
# 填写完善 .env 文件中的内容
FASTGPT_API_KEY='你的key'
# 如果需要私有化部署,请修改.env中下面的配置
FASTGPT_API_KEY='https://[你的私有化部署地址]'
```

- 其他
(待实践)理论上使用 openAI 格式的 api,都可以使用,在 env 文件中修改对应的 api_key、model、proxy_url 即可。

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"test-xunfei": "node ./src/xunfei/__test__.js",
"test-kimi": "node ./src/kimi/__test__.js",
"test-dify": "node ./src/dify/__test__.js",
"test-fastgpt": "node ./src/fastgpt/__test__.js",
"prepare": "husky"
},
"lint-staged": {
Expand Down
9 changes: 9 additions & 0 deletions src/fastgpt/__test__.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getFastGPTReply } from './index.js'

// 测试 fastgpt api
async function testMessage() {
const message = await getFastGPTReply('hello')
console.log('🌸🌸🌸 / message: ', message)
}

testMessage()
68 changes: 68 additions & 0 deletions src/fastgpt/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 参考:https://github.com/labring/fastgpt
import axios from 'axios'
import dotenv from 'dotenv'
const env = dotenv.config().parsed // 环境参数

const domain = env.FASTGPT_API_URL || 'https://cloud.fastgpt.cn'
const server = {
chat: `${domain}/api/v1/chat/completions`,
}

const configuration = {
model: env.FASTGPT_MODEL || 'Qwen-turbo',
temperature: 0.3,
max_tokens: 5000,
stream: false,
}

// sample request: curl --location --request POST 'http://localhost:3000/api/v1/chat/completions' \
// --header 'Authorization: Bearer fastgpt-xxxxxx' \
// --header 'Content-Type: application/json' \
// --data-raw '{
// "chatId": "my_chatId",
// "stream": false,
// "detail": false,
// "responseChatItemId": "my_responseChatItemId",
// "variables": {
// "uid": "asdfadsfasfd2323",
// "name": "张三"
// },
// "messages": [
// {
// "role": "user",
// "content": "导演是谁"
// }
// ]
// }'
export async function getFastGPTReply(prompt) {
try {
console.log('🚀🚀🚀 / prompt', prompt)
const res = await axios.post(
server.chat,
{
chatId: 'default_chat_id',
stream: configuration.stream,
detail: false,
messages: [
{
role: 'user',
content: prompt,
},
],
},
{
headers: {
Authorization: `Bearer ${env.FASTGPT_API_KEY}`,
'Content-Type': 'application/json',
},
},
)

const { choices } = res.data
return `${choices[0].message.content}`
} catch (error) {
console.log('FastGPT Error:', error.message)
console.log('请检查你的 API_KEY 和 API_URL 配置是否正确')
throw error
}
}
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ function handleStart(type) {
return botStart()
}
break
case 'fastgpt':
if (env.FASTGPT_API_KEY && env.FASTGPT_API_URL) {
return botStart()
}
console.log('❌ 请先配置.env文件中的 FASTGPT_API_KEY 和 FASTGPT_API_URL')
break
default:
console.log('❌ 服务类型错误, 目前支持: ChatGPT | Kimi | Xunfei | DIFY | OLLAMA | TONGYI')
}
Expand All @@ -179,6 +185,7 @@ export const serveList = [
// ... 欢迎大家接入更多的服务
{ name: 'ollama', value: 'ollama' },
{ name: 'tongyi', value: 'tongyi' },
{ name: 'fastgpt', value: 'fastgpt' },
]
const questions = [
{
Expand Down
3 changes: 3 additions & 0 deletions src/wechaty/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { get302AiReply } from '../302ai/index.js'
import { getDifyReply } from '../dify/index.js'
import { getOllamaReply } from '../ollama/index.js'
import { getTongyiReply } from '../tongyi/index.js'
import { getFastGPTReply } from '../fastgpt/index.js'

/**
* 获取ai服务
Expand All @@ -30,6 +31,8 @@ export function getServe(serviceType) {
return getOllamaReply
case 'tongyi':
return getTongyiReply
case 'fastgpt':
return getFastGPTReply
default:
return getGptReply
}
Expand Down
10 changes: 10 additions & 0 deletions src/wechaty/testMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getDeepSeekFreeReply } from '../deepseek-free/index.js'
import { get302AiReply } from '../302ai/index.js'
import { getDifyReply } from '../dify/index.js'
import { getOllamaReply } from '../ollama/index.js'
import { getFastGPTReply } from '../fastgpt/index.js'
const env = dotenv.config().parsed // 环境参数

// 控制启动
Expand Down Expand Up @@ -69,6 +70,14 @@ async function handleRequest(type) {
}
console.log('❌ 请先配置.env文件中的 OLLAMA_URL')
break
case 'fastgpt':
if (env.FASTGPT_API_KEY && env.FASTGPT_API_URL) {
const message = await getFastGPTReply('你好')
console.log('🌸🌸🌸 / reply: ', message)
return
}
console.log('❌ 请先配置.env文件中的 FASTGPT_API_KEY 和 FASTGPT_API_URL')
break
default:
console.log('🚀服务类型错误')
}
Expand All @@ -83,6 +92,7 @@ const serveList = [
{ name: 'dify', value: 'dify' },
// ... 欢迎大家接入更多的服务
{ name: 'ollama', value: 'ollama' },
{ name: 'fastgpt', value: 'fastgpt' },
]
const questions = [
{
Expand Down