Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature plugin (GPTs like action based on function call) #5331

Merged
merged 41 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c99cd31
add openapi-client-axios
lloydzhou Aug 24, 2024
f5209fc
stash code
lloydzhou Aug 28, 2024
29b5cd9
ts error
lloydzhou Aug 28, 2024
f3f6dc5
stash code
lloydzhou Aug 28, 2024
d212df8
stash code
lloydzhou Aug 28, 2024
f7a5f83
stash code
lloydzhou Aug 28, 2024
d58b99d
stash code
lloydzhou Aug 28, 2024
341a52a
stash code
lloydzhou Aug 28, 2024
7fc0d11
create common function stream for fetchEventSource
lloydzhou Aug 29, 2024
d2cb984
add processToolMessage callback
lloydzhou Aug 29, 2024
571ce11
stash code
lloydzhou Aug 29, 2024
cac99e3
add Plugin page
lloydzhou Aug 30, 2024
271f58d
stash code
lloydzhou Aug 30, 2024
9326ff9
ts error
lloydzhou Aug 30, 2024
2214689
add gapier proxy
lloydzhou Aug 30, 2024
b2965e1
update
lloydzhou Aug 30, 2024
f652f73
plugin add auth config
lloydzhou Sep 2, 2024
877668b
hotfix
lloydzhou Sep 2, 2024
801b625
claude support function call
lloydzhou Sep 2, 2024
078305f
kimi support function call
lloydzhou Sep 2, 2024
6435e7a
update readme
lloydzhou Sep 2, 2024
3ec67f9
add load from url
lloydzhou Sep 2, 2024
2b317f6
add config auth location
lloydzhou Sep 3, 2024
236736d
remove no need code
lloydzhou Sep 3, 2024
4fdd997
hotfix
lloydzhou Sep 3, 2024
d30351e
update readme
lloydzhou Sep 3, 2024
c7bc93b
Merge remote-tracking branch 'connectai/main' into feature/plugin
lloydzhou Sep 3, 2024
0a5522d
update
lloydzhou Sep 3, 2024
7180ed9
hotfix
lloydzhou Sep 3, 2024
6ab6b3d
remove no need code
lloydzhou Sep 3, 2024
04e1ab6
update readme
lloydzhou Sep 4, 2024
f9a047a
using tauri http api run plugin to fixed cors in App
lloydzhou Sep 4, 2024
09aec7b
using tauri http api run plugin to fixed cors in App
lloydzhou Sep 4, 2024
9820193
Merge pull request #6 from ConnectAI-E/feature/plugin-app-cors
lloydzhou Sep 4, 2024
b590d08
disable nextjs proxy, then can using dalle as plugin
lloydzhou Sep 5, 2024
caf50b6
move artifacts into mask settings
lloydzhou Sep 5, 2024
80b8f95
move artifacts into mask settings
lloydzhou Sep 5, 2024
f32dd69
Merge pull request #7 from ConnectAI-E/feature/plugin-artifact
lloydzhou Sep 5, 2024
7c0acc7
hotfix tools empty array
lloydzhou Sep 5, 2024
7455978
default enable artifact
lloydzhou Sep 6, 2024
9275f2d
add awesome plugin repo url
lloydzhou Sep 6, 2024
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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ For enterprise inquiries, please contact: **[email protected]**
- [x] Desktop App with tauri
- [x] Self-host Model: Fully compatible with [RWKV-Runner](https://github.com/josStorer/RWKV-Runner), as well as server deployment of [LocalAI](https://github.com/go-skynet/LocalAI): llama/gpt4all/rwkv/vicuna/koala/gpt4all-j/cerebras/falcon/dolly etc.
- [x] Artifacts: Easily preview, copy and share generated content/webpages through a separate window [#5092](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/pull/5092)
- [x] Plugins: support artifacts, network search, calculator, any other apis etc. [#165](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/165)
- [x] artifacts
- [ ] network search, calculator, any other apis etc. [#165](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/165)
- [x] Plugins: support network search, calculator, any other apis etc. [#165](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/165) [#5353](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/issues/5353)
- [x] network search, calculator, any other apis etc. [#165](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/165) [#5353](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/issues/5353)
- [ ] local knowledge base

## What's New

- 🚀 v2.15.0 Now supports Plugins! Read this: [NextChat-Awesome-Plugins](https://github.com/ChatGPTNextWeb/NextChat-Awesome-Plugins)
- 🚀 v2.14.0 Now supports Artifacts & SD
- 🚀 v2.10.1 support Google Gemini Pro model.
- 🚀 v2.9.11 you can use azure endpoint now.
Expand Down Expand Up @@ -128,13 +128,13 @@ For enterprise inquiries, please contact: **[email protected]**
- [x] 使用 tauri 打包桌面应用
- [x] 支持自部署的大语言模型:开箱即用 [RWKV-Runner](https://github.com/josStorer/RWKV-Runner) ,服务端部署 [LocalAI 项目](https://github.com/go-skynet/LocalAI) llama / gpt4all / rwkv / vicuna / koala / gpt4all-j / cerebras / falcon / dolly 等等,或者使用 [api-for-open-llm](https://github.com/xusenlinzy/api-for-open-llm)
- [x] Artifacts: 通过独立窗口,轻松预览、复制和分享生成的内容/可交互网页 [#5092](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/pull/5092)
- [x] 插件机制,支持 artifacts,联网搜索、计算器、调用其他平台 api [#165](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/165)
- [x] artifacts
- [ ] 支持联网搜索、计算器、调用其他平台 api [#165](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/165)
- [x] 插件机制,支持`联网搜索`、`计算器`、调用其他平台 api [#165](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/165) [#5353](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/issues/5353)
- [x] 支持联网搜索、计算器、调用其他平台 api [#165](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/165) [#5353](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/issues/5353)
lloydzhou marked this conversation as resolved.
Show resolved Hide resolved
- [ ] 本地知识库
lloydzhou marked this conversation as resolved.
Show resolved Hide resolved

## 最新动态

- 🚀 v2.15.0 现在支持插件功能了!了解更多:[NextChat-Awesome-Plugins](https://github.com/ChatGPTNextWeb/NextChat-Awesome-Plugins)
- 🚀 v2.14.0 现在支持 Artifacts & SD 了。
- 🚀 v2.10.1 现在支持 Gemini Pro 模型。
- 🚀 v2.9.11 现在可以使用自定义 Azure 服务了。
Expand Down
6 changes: 5 additions & 1 deletion app/api/[provider]/[...path]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { handle as alibabaHandler } from "../../alibaba";
import { handle as moonshotHandler } from "../../moonshot";
import { handle as stabilityHandler } from "../../stability";
import { handle as iflytekHandler } from "../../iflytek";
import { handle as proxyHandler } from "../../proxy";

async function handle(
req: NextRequest,
{ params }: { params: { provider: string; path: string[] } },
Expand All @@ -36,8 +38,10 @@ async function handle(
return stabilityHandler(req, { params });
case ApiPath.Iflytek:
return iflytekHandler(req, { params });
default:
case ApiPath.OpenAI:
return openaiHandler(req, { params });
default:
return proxyHandler(req, { params });
}
}

Expand Down
5 changes: 1 addition & 4 deletions app/api/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ export async function requestOpenai(req: NextRequest) {
authHeaderName = "Authorization";
}

let path = `${req.nextUrl.pathname}${req.nextUrl.search}`.replaceAll(
"/api/openai/",
"",
);
let path = `${req.nextUrl.pathname}`.replaceAll("/api/openai/", "");

let baseUrl =
(isAzure ? serverConfig.azureUrl : serverConfig.baseUrl) || OPENAI_BASE_URL;
Expand Down
75 changes: 75 additions & 0 deletions app/api/proxy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { NextRequest, NextResponse } from "next/server";

export async function handle(
req: NextRequest,
{ params }: { params: { path: string[] } },
) {
console.log("[Proxy Route] params ", params);

if (req.method === "OPTIONS") {
return NextResponse.json({ body: "OK" }, { status: 200 });
}

// remove path params from searchParams
req.nextUrl.searchParams.delete("path");
req.nextUrl.searchParams.delete("provider");

const subpath = params.path.join("/");
const fetchUrl = `${req.headers.get(
"x-base-url",
)}/${subpath}?${req.nextUrl.searchParams.toString()}`;
const skipHeaders = ["connection", "host", "origin", "referer", "cookie"];
const headers = new Headers(
Array.from(req.headers.entries()).filter((item) => {
if (
item[0].indexOf("x-") > -1 ||
item[0].indexOf("sec-") > -1 ||
skipHeaders.includes(item[0])
) {
return false;
}
return true;
}),
);
const controller = new AbortController();
const fetchOptions: RequestInit = {
headers,
method: req.method,
body: req.body,
// to fix #2485: https://stackoverflow.com/questions/55920957/cloudflare-worker-typeerror-one-time-use-body
redirect: "manual",
// @ts-ignore
duplex: "half",
signal: controller.signal,
};

const timeoutId = setTimeout(
() => {
controller.abort();
},
10 * 60 * 1000,
);

try {
const res = await fetch(fetchUrl, fetchOptions);
// to prevent browser prompt for credentials
const newHeaders = new Headers(res.headers);
newHeaders.delete("www-authenticate");
// to disable nginx buffering
newHeaders.set("X-Accel-Buffering", "no");

// The latest version of the OpenAI API forced the content-encoding to be "br" in json response
// So if the streaming is disabled, we need to remove the content-encoding header
// Because Vercel uses gzip to compress the response, if we don't remove the content-encoding header
// The browser will try to decode the response with brotli and fail
newHeaders.delete("content-encoding");

return new Response(res.body, {
status: res.status,
statusText: res.statusText,
headers: newHeaders,
});
} finally {
clearTimeout(timeoutId);
}
}
10 changes: 9 additions & 1 deletion app/client/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import {
ModelProvider,
ServiceProvider,
} from "../constant";
import { ChatMessage, ModelType, useAccessStore, useChatStore } from "../store";
import {
ChatMessageTool,
ChatMessage,
ModelType,
useAccessStore,
useChatStore,
} from "../store";
import { ChatGPTApi, DalleRequestPayload } from "./platforms/openai";
import { GeminiProApi } from "./platforms/google";
import { ClaudeApi } from "./platforms/anthropic";
Expand Down Expand Up @@ -56,6 +62,8 @@ export interface ChatOptions {
onFinish: (message: string) => void;
onError?: (err: Error) => void;
onController?: (controller: AbortController) => void;
onBeforeTool?: (tool: ChatMessageTool) => void;
onAfterTool?: (tool: ChatMessageTool) => void;
}

export interface LLMUsage {
Expand Down
Loading
Loading