Skip to content

Commit

Permalink
🔀 Squashed merge from upstream/v2.15.8
Browse files Browse the repository at this point in the history
commit 38fa305
Author: lloydzhou <[email protected]>
Date:   Mon Nov 11 13:26:08 2024 +0800

    update version

commit 289aeec
Merge: f8f6954 7d71da9
Author: Lloyd Zhou <[email protected]>
Date:   Mon Nov 11 13:19:26 2024 +0800

    Merge pull request ChatGPTNextWeb#5786 from ConnectAI-E/feature/realtime-chat

    Feature/realtime chat

commit 7d71da9
Author: lloydzhou <[email protected]>
Date:   Mon Nov 11 13:15:09 2024 +0800

    remove close-24 svg

commit f8f6954
Merge: 6e03f32 64aa760
Author: Lloyd Zhou <[email protected]>
Date:   Mon Nov 11 13:13:09 2024 +0800

    Merge pull request ChatGPTNextWeb#5779 from ConnectAI-E/feature/model/claude35haiku

    add claude35haiku & not support vision

commit 6e03f32
Merge: 108069a 18a6571
Author: Lloyd Zhou <[email protected]>
Date:   Mon Nov 11 13:10:00 2024 +0800

    Merge pull request ChatGPTNextWeb#5795 from JingSyue/main

    fix: built-in plugin dalle3 error ChatGPTNextWeb#5787

commit 18a6571
Author: JingSyue <[email protected]>
Date:   Mon Nov 11 12:59:29 2024 +0800

    Update proxy.ts

    Update proxy.ts

commit 14f444e
Author: Dogtiti <[email protected]>
Date:   Mon Nov 11 11:47:41 2024 +0800

    doc: realtime chat

commit 2b0f2e5
Author: JingSyue <[email protected]>
Date:   Sun Nov 10 10:28:25 2024 +0800

    fix: built-in plugin dalle3 error ChatGPTNextWeb#5787

commit 4629b39
Author: Dogtiti <[email protected]>
Date:   Sat Nov 9 16:22:01 2024 +0800

    chore: comment context history

commit d33e772
Author: Dogtiti <[email protected]>
Date:   Fri Nov 8 22:39:17 2024 +0800

    feat: voice print

commit 89136fb
Author: Dogtiti <[email protected]>
Date:   Fri Nov 8 22:18:39 2024 +0800

    feat: voice print

commit 8b4ca13
Author: Dogtiti <[email protected]>
Date:   Fri Nov 8 22:02:31 2024 +0800

    feat: voice print

commit a4c9eaf
Author: lloydzhou <[email protected]>
Date:   Fri Nov 8 13:43:13 2024 +0800

    do not save empty audio file

commit 50e6310
Author: lloydzhou <[email protected]>
Date:   Fri Nov 8 13:21:40 2024 +0800

    merge code and get analyser data

commit 48a1e8a
Author: Dogtiti <[email protected]>
Date:   Thu Nov 7 21:32:47 2024 +0800

    chore: i18n

commit e44ebe3
Author: Dogtiti <[email protected]>
Date:   Thu Nov 7 21:28:23 2024 +0800

    feat: realtime config

commit 108069a
Merge: fbb9385 d5bda29
Author: Lloyd Zhou <[email protected]>
Date:   Thu Nov 7 20:06:30 2024 +0800

    Merge pull request ChatGPTNextWeb#5788 from ConnectAI-E/fix-o1-maxtokens

    chore: o1模型使用max_completion_tokens

commit d5bda29
Author: DDMeaqua <[email protected]>
Date:   Thu Nov 7 19:45:27 2024 +0800

    chore: o1模型使用max_completion_tokens

commit 283caba
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 18:57:57 2024 +0800

    stop streaming play after get input audio.

commit b78e5db
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 17:55:51 2024 +0800

    add temperature config

commit 46c469b
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 17:47:55 2024 +0800

    add voice config

commit c00ebbe
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 17:40:03 2024 +0800

    update

commit c526ff8
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 17:23:20 2024 +0800

    update

commit 0037b0c
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 17:03:04 2024 +0800

    ts error

commit 6f81bb3
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 16:56:15 2024 +0800

    add context after connected

commit 7bdc45e
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 16:41:24 2024 +0800

    connect realtime model when open panel

commit 88cd3ac
Author: Dogtiti <[email protected]>
Date:   Thu Nov 7 12:16:11 2024 +0800

    fix: ts error

commit 4988d2e
Author: Dogtiti <[email protected]>
Date:   Thu Nov 7 11:56:58 2024 +0800

    fix: ts error

commit 8deb7a9
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 11:53:01 2024 +0800

    hotfix for update target session

commit db060d7
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 11:45:38 2024 +0800

    upload save record wav file

commit 5226278
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 09:36:22 2024 +0800

    upload save wav file logic

commit cf46d5a
Author: lloydzhou <[email protected]>
Date:   Thu Nov 7 01:12:08 2024 +0800

    upload response audio, and update audio_url to session message

commit a494152
Author: Dogtiti <[email protected]>
Date:   Wed Nov 6 22:30:02 2024 +0800

    feat: audio to message

commit f6e1f83
Author: Dogtiti <[email protected]>
Date:   Wed Nov 6 22:07:33 2024 +0800

    wip

commit d544eea
Author: Dogtiti <[email protected]>
Date:   Wed Nov 6 21:14:45 2024 +0800

    feat: realtime chat ui

commit fbb9385
Merge: 6ded4e9 18144c3
Author: Lloyd Zhou <[email protected]>
Date:   Wed Nov 6 20:33:51 2024 +0800

    Merge pull request ChatGPTNextWeb#5782 from ConnectAI-E/style/classname

    style: improve classname by clsx

commit 18144c3
Author: Dogtiti <[email protected]>
Date:   Wed Nov 6 20:16:38 2024 +0800

    chore: clsx

commit 64aa760
Author: opchips <[email protected]>
Date:   Wed Nov 6 19:18:05 2024 +0800

    update claude rank

commit e0bbb8b
Author: Dogtiti <[email protected]>
Date:   Wed Nov 6 16:58:26 2024 +0800

    style: improve classname by clsx

commit 6667ee1
Merge: 3086a2f 6ded4e9
Author: opchips <[email protected]>
Date:   Wed Nov 6 15:08:18 2024 +0800

    merge main

commit 6ded4e9
Merge: f4c9410 85cdcab
Author: Lloyd Zhou <[email protected]>
Date:   Wed Nov 6 15:04:46 2024 +0800

    Merge pull request ChatGPTNextWeb#5778 from ConnectAI-E/fix/5436

    fix: botMessage reply date

commit 85cdcab
Author: Dogtiti <[email protected]>
Date:   Wed Nov 6 14:53:08 2024 +0800

    fix: botMessage reply date

commit f4c9410
Merge: f526d6f adf7d82
Author: Lloyd Zhou <[email protected]>
Date:   Wed Nov 6 14:02:20 2024 +0800

    Merge pull request ChatGPTNextWeb#5776 from ConnectAI-E/feat-glm

    fix: glm chatpath

commit adf7d82
Author: DDMeaqua <[email protected]>
Date:   Wed Nov 6 13:55:57 2024 +0800

    fix: glm chatpath

commit 3086a2f
Author: opchips <[email protected]>
Date:   Wed Nov 6 12:56:24 2024 +0800

    add claude35haiku not vision

commit f526d6f
Merge: f3603e5 106461a
Author: Lloyd Zhou <[email protected]>
Date:   Wed Nov 6 11:16:33 2024 +0800

    Merge pull request ChatGPTNextWeb#5774 from ConnectAI-E/feature/update-target-session

    fix: updateCurrentSession => updateTargetSession

commit 106461a
Merge: c4e19db f3603e5
Author: Dogtiti <[email protected]>
Date:   Wed Nov 6 11:08:41 2024 +0800

    Merge branch 'main' of https://github.com/ConnectAI-E/ChatGPT-Next-Web into feature/update-target-session

commit c4e19db
Author: Dogtiti <[email protected]>
Date:   Wed Nov 6 11:06:18 2024 +0800

    fix: updateCurrentSession => updateTargetSession

commit f3603e5
Merge: 00d6cb2 8e2484f
Author: Dogtiti <[email protected]>
Date:   Wed Nov 6 10:49:28 2024 +0800

    Merge pull request ChatGPTNextWeb#5769 from ryanhex53/fix-model-multi@

    Custom model names can include the `@` symbol by itself.

commit 8e2484f
Author: ryanhex53 <[email protected]>
Date:   Tue Nov 5 13:52:54 2024 +0000

    Refactor: Replace all provider split occurrences with getModelProvider utility method

commit 00d6cb2
Author: lloydzhou <[email protected]>
Date:   Tue Nov 5 17:42:55 2024 +0800

    update version

commit b844045
Author: ryanhex53 <[email protected]>
Date:   Tue Nov 5 07:44:12 2024 +0000

    Custom model names can include the `@` symbol by itself.

    To specify the model's provider, append it after the model name using `@` as before.

    This format supports cases like `google vertex ai` with a model name like `claude-3-5-sonnet@20240620`.

    For instance, `claude-3-5-sonnet@20240620@vertex-ai` will be split by `split(/@(?!.*@)/)` into:

    `[ 'claude-3-5-sonnet@20240620', 'vertex-ai' ]`, where the former is the model name and the latter is the custom provider.

commit e49fe97
Merge: 14f7519 e49466f
Author: Lloyd Zhou <[email protected]>
Date:   Tue Nov 5 15:07:52 2024 +0800

    Merge pull request ChatGPTNextWeb#5765 from ConnectAI-E/feature/onfinish

    feat: update real 'currentSession'

commit 14f7519
Merge: 820ab54 0ec4233
Author: Dogtiti <[email protected]>
Date:   Tue Nov 5 11:07:52 2024 +0800

    Merge pull request ChatGPTNextWeb#5767 from ConnectAI-E/feat-glm

    chore: update readme

commit 0ec4233
Author: DDMeaqua <[email protected]>
Date:   Tue Nov 5 11:06:20 2024 +0800

    chore: update readme

commit 820ab54
Merge: 0dc4071 a6c1eb2
Author: Dogtiti <[email protected]>
Date:   Tue Nov 5 10:54:52 2024 +0800

    Merge pull request ChatGPTNextWeb#5766 from ConnectAI-E/feature/add-claude-haiku3.5

    Feature/add claude haiku3.5

commit a6c1eb2
Merge: 801dc41 0dc4071
Author: lloydzhou <[email protected]>
Date:   Tue Nov 5 10:23:15 2024 +0800

    add claude 3.5 haiku

commit 0dc4071
Merge: aef535f 4d39497
Author: Lloyd Zhou <[email protected]>
Date:   Tue Nov 5 01:10:06 2024 +0800

    Merge pull request ChatGPTNextWeb#5464 from endless-learner/main

    Added 1-click deployment link for Alibaba Cloud.

commit 4d39497
Author: Lloyd Zhou <[email protected]>
Date:   Tue Nov 5 01:09:27 2024 +0800

    merge main

commit aef535f
Merge: 686a80e fbb7a1e
Author: Dogtiti <[email protected]>
Date:   Mon Nov 4 21:41:11 2024 +0800

    Merge pull request ChatGPTNextWeb#5753 from ChatGPTNextWeb/feat-bt-doc

    Feat bt doc

commit 686a80e
Merge: 5733e3c 4b93370
Author: Dogtiti <[email protected]>
Date:   Mon Nov 4 21:37:34 2024 +0800

    Merge pull request ChatGPTNextWeb#5764 from ChatGPTNextWeb/dependabot/npm_and_yarn/testing-library/react-16.0.1

    chore(deps-dev): bump @testing-library/react from 16.0.0 to 16.0.1

commit e49466f
Author: Dogtiti <[email protected]>
Date:   Mon Nov 4 21:25:56 2024 +0800

    feat: update real 'currentSession'

commit 4b93370
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon Nov 4 10:24:30 2024 +0000

    chore(deps-dev): bump @testing-library/react from 16.0.0 to 16.0.1

    Bumps [@testing-library/react](https://github.com/testing-library/react-testing-library) from 16.0.0 to 16.0.1.
    - [Release notes](https://github.com/testing-library/react-testing-library/releases)
    - [Changelog](https://github.com/testing-library/react-testing-library/blob/main/CHANGELOG.md)
    - [Commits](testing-library/react-testing-library@v16.0.0...v16.0.1)

    ---
    updated-dependencies:
    - dependency-name: "@testing-library/react"
      dependency-type: direct:development
      update-type: version-update:semver-patch
    ...

    Signed-off-by: dependabot[bot] <[email protected]>

commit 5733e3c
Merge: d66bfc6 44fc5b5
Author: Dogtiti <[email protected]>
Date:   Mon Nov 4 17:16:44 2024 +0800

    Merge pull request ChatGPTNextWeb#5759 from ConnectAI-E/feature/onfinish

    Feature/onfinish

commit 44fc5b5
Author: Dogtiti <[email protected]>
Date:   Mon Nov 4 17:00:45 2024 +0800

    fix: onfinish responseRes

commit 2d3f7c9
Author: Dogtiti <[email protected]>
Date:   Wed Oct 16 15:17:08 2024 +0800

    fix: vision model dalle3

commit fe8cca3
Merge: adf97c6 d66bfc6
Author: GH Action - Upstream Sync <[email protected]>
Date:   Sat Nov 2 01:12:09 2024 +0000

    Merge branch 'main' of https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web

commit fbb7a1e
Author: weige <[email protected]>
Date:   Fri Nov 1 18:20:16 2024 +0800

    fix

commit fb2c155
Author: weige <[email protected]>
Date:   Fri Nov 1 17:45:50 2024 +0800

    fix

commit c2c52a1
Author: weige <[email protected]>
Date:   Fri Nov 1 17:35:34 2024 +0800

    fix

commit 106ddc1
Author: weige <[email protected]>
Date:   Fri Nov 1 17:35:09 2024 +0800

    fix

commit 17d5209
Author: weige <[email protected]>
Date:   Fri Nov 1 17:28:20 2024 +0800

    add bt install doc

commit adf97c6
Merge: 7c466c9 0581e37
Author: GH Action - Upstream Sync <[email protected]>
Date:   Fri Nov 1 01:18:59 2024 +0000

    Merge branch 'main' of https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web

commit 7c466c9
Merge: b0d28eb a0fa4d7
Author: GH Action - Upstream Sync <[email protected]>
Date:   Thu Oct 31 01:14:28 2024 +0000

    Merge branch 'main' of https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web

commit b0d28eb
Merge: 064e964 613d67e
Author: endless-learner <[email protected]>
Date:   Tue Oct 29 14:38:49 2024 -0700

    Merge branch 'main' into main

commit 801dc41
Author: lloydzhou <[email protected]>
Date:   Thu Oct 24 15:28:05 2024 +0800

    add claude-3.5-haiku

commit 064e964
Author: endless-learner <[email protected]>
Date:   Tue Sep 24 23:05:32 2024 -0700

    Updated link to deploy on Alibaba Cloud, readable when not logged in, also, able to choose region.

commit 47fb40d
Merge: 9e18cc2 4c84182
Author: endless-learner <[email protected]>
Date:   Tue Sep 24 23:03:03 2024 -0700

    Merge branch 'ChatGPTNextWeb:main' into main

commit 9e18cc2
Author: endless-learner <[email protected]>
Date:   Tue Sep 24 13:55:00 2024 -0700

    Update README.md

    Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

commit 03268ce
Author: endless-learner <[email protected]>
Date:   Wed Sep 18 20:38:20 2024 -0700

    Added 1-click deployment link for Alibaba Cloud.
  • Loading branch information
frostime committed Nov 12, 2024
1 parent e6450bd commit b4756b3
Show file tree
Hide file tree
Showing 69 changed files with 2,298 additions and 804 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ One-Click to get a well-designed cross-platform ChatGPT web UI, with GPT3, GPT4
[MacOS-image]: https://img.shields.io/badge/-MacOS-black?logo=apple
[Linux-image]: https://img.shields.io/badge/-Linux-333?logo=ubuntu

[<img src="https://vercel.com/button" alt="Deploy on Zeabur" height="30">](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FChatGPTNextWeb%2FChatGPT-Next-Web&env=OPENAI_API_KEY&env=CODE&project-name=nextchat&repository-name=NextChat) [<img src="https://zeabur.com/button.svg" alt="Deploy on Zeabur" height="30">](https://zeabur.com/templates/ZBUEFA) [<img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" height="30">](https://gitpod.io/#https://github.com/Yidadaa/ChatGPT-Next-Web) [<img src="https://img.shields.io/badge/BT_Deploy-Install-20a53a" alt="Open in Gitpod" height="30">](https://www.bt.cn/new/download.html)
[<img src="https://vercel.com/button" alt="Deploy on Vercel" height="30">](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FChatGPTNextWeb%2FChatGPT-Next-Web&env=OPENAI_API_KEY&env=CODE&project-name=nextchat&repository-name=NextChat) [<img src="https://zeabur.com/button.svg" alt="Deploy on Zeabur" height="30">](https://zeabur.com/templates/ZBUEFA) [<img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" height="30">](https://gitpod.io/#https://github.com/Yidadaa/ChatGPT-Next-Web) [<img src="https://img.shields.io/badge/BT_Deploy-Install-20a53a" alt="BT Deply Install" height="30">](https://www.bt.cn/new/download.html) [<img src="https://svgshare.com/i/1AVg.svg" alt="Deploy to Alibaba Cloud" height="30">](https://computenest.aliyun.com/market/service-f1c9b75e59814dc49d52)

[<img src="https://github.com/user-attachments/assets/903482d4-3e87-4134-9af1-f2588fa90659" height="60" width="288" >](https://monica.im/?utm=nxcrp)

Expand Down Expand Up @@ -96,10 +96,11 @@ For enterprise inquiries, please contact: **[email protected]**
- [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 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)
- [x] Supports Realtime Chat [#5672](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/issues/5672)
- [ ] local knowledge base

## What's New

- 🚀 v2.15.8 Now supports Realtime Chat [#5672](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/issues/5672)
- 🚀 v2.15.4 The Application supports using Tauri fetch LLM API, MORE SECURITY! [#5379](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/issues/5379)
- 🚀 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
Expand Down Expand Up @@ -134,10 +135,11 @@ For enterprise inquiries, please contact: **[email protected]**
- [x] Artifacts: 通过独立窗口,轻松预览、复制和分享生成的内容/可交互网页 [#5092](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/pull/5092)
- [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)
- [x] 支持 Realtime Chat [#5672](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/issues/5672)
- [ ] 本地知识库

## 最新动态

- 🚀 v2.15.8 现在支持Realtime Chat [#5672](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/issues/5672)
- 🚀 v2.15.4 客户端支持Tauri本地直接调用大模型API,更安全![#5379](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/issues/5379)
- 🚀 v2.15.0 现在支持插件功能了!了解更多:[NextChat-Awesome-Plugins](https://github.com/ChatGPTNextWeb/NextChat-Awesome-Plugins)
- 🚀 v2.14.0 现在支持 Artifacts & SD 了。
Expand Down Expand Up @@ -301,6 +303,14 @@ iflytek Api Key.

iflytek Api Secret.

### `CHATGLM_API_KEY` (optional)

ChatGLM Api Key.

### `CHATGLM_URL` (optional)

ChatGLM Api Url.

### `HIDE_USER_API_KEY` (optional)

> Default: Empty
Expand Down Expand Up @@ -397,6 +407,9 @@ yarn dev

> [简体中文 > 如何部署到私人服务器](./README_CN.md#部署)
### BT Install
> [简体中文 > 如何通过宝塔一键部署](./docs/bt-cn.md)
### Docker (Recommended)

```shell
Expand Down
10 changes: 10 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ ByteDance Api Url.

讯飞星火Api Secret.

### `CHATGLM_API_KEY` (可选)

ChatGLM Api Key.

### `CHATGLM_URL` (可选)

ChatGLM Api Url.


### `HIDE_USER_API_KEY` (可选)
Expand Down Expand Up @@ -264,6 +271,9 @@ BASE_URL=https://b.nextweb.fun/api/proxy

## 部署

### 宝塔面板部署
> [简体中文 > 如何通过宝塔一键部署](./docs/bt-cn.md)
### 容器部署 (推荐)

> Docker 版本需要在 20 及其以上,否则会提示找不到镜像。
Expand Down
4 changes: 2 additions & 2 deletions app/api/common.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NextRequest, NextResponse } from "next/server";
import { getServerSideConfig } from "../config/server";
import { OPENAI_BASE_URL, ServiceProvider } from "../constant";
import { isModelAvailableInServer } from "../utils/model";
import { cloudflareAIGatewayUrl } from "../utils/cloudflare";
import { getModelProvider, isModelAvailableInServer } from "../utils/model";

const serverConfig = getServerSideConfig();

Expand Down Expand Up @@ -71,7 +71,7 @@ export async function requestOpenai(req: NextRequest) {
.filter((v) => !!v && !v.startsWith("-") && v.includes(modelName))
.forEach((m) => {
const [fullName, displayName] = m.split("=");
const [_, providerName] = fullName.split("@");
const [_, providerName] = getModelProvider(fullName);
if (providerName === "azure" && !displayName) {
const [_, deployId] = (serverConfig?.azureUrl ?? "").split(
"deployments/",
Expand Down
14 changes: 14 additions & 0 deletions app/api/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NextRequest, NextResponse } from "next/server";
import { getServerSideConfig } from "@/app/config/server";

export async function handle(
req: NextRequest,
Expand All @@ -9,6 +10,7 @@ export async function handle(
if (req.method === "OPTIONS") {
return NextResponse.json({ body: "OK" }, { status: 200 });
}
const serverConfig = getServerSideConfig();

// remove path params from searchParams
req.nextUrl.searchParams.delete("path");
Expand All @@ -31,6 +33,18 @@ export async function handle(
return true;
}),
);
// if dalle3 use openai api key
const baseUrl = req.headers.get("x-base-url");
if (baseUrl?.includes("api.openai.com")) {
if (!serverConfig.apiKey) {
return NextResponse.json(
{ error: "OpenAI API key not configured" },
{ status: 500 },
);
}
headers.set("Authorization", `Bearer ${serverConfig.apiKey}`);
}

const controller = new AbortController();
const fetchOptions: RequestInit = {
headers,
Expand Down
2 changes: 1 addition & 1 deletion app/client/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface ChatOptions {
config: LLMConfig;

onUpdate?: (message: string, chunk: string) => void;
onFinish: (message: string) => void;
onFinish: (message: string, responseRes: Response) => void;
onError?: (err: Error) => void;
onController?: (controller: AbortController) => void;
onBeforeTool?: (tool: ChatMessageTool) => void;
Expand Down
6 changes: 4 additions & 2 deletions app/client/platforms/alibaba.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export class QwenApi implements LLMApi {
let responseText = "";
let remainText = "";
let finished = false;
let responseRes: Response;

// animate response to make it looks smooth
function animateResponseText() {
Expand Down Expand Up @@ -172,7 +173,7 @@ export class QwenApi implements LLMApi {
const finish = () => {
if (!finished) {
finished = true;
options.onFinish(responseText + remainText);
options.onFinish(responseText + remainText, responseRes);
}
};

Expand All @@ -188,6 +189,7 @@ export class QwenApi implements LLMApi {
"[Alibaba] request response content type: ",
contentType,
);
responseRes = res;

if (contentType?.startsWith("text/plain")) {
responseText = await res.clone().text();
Expand Down Expand Up @@ -254,7 +256,7 @@ export class QwenApi implements LLMApi {

const resJson = await res.json();
const message = this.extractMessage(resJson);
options.onFinish(message);
options.onFinish(message, res);
}
} catch (e) {
console.log("[Request] failed to make a chat request", e);
Expand Down
5 changes: 3 additions & 2 deletions app/client/platforms/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,14 @@ export class ClaudeApi implements LLMApi {
};

try {
controller.signal.onabort = () => options.onFinish("");
controller.signal.onabort = () =>
options.onFinish("", new Response(null, { status: 400 }));

const res = await fetch(path, payload);
const resJson = await res.json();

const message = this.extractMessage(resJson);
options.onFinish(message);
options.onFinish(message, res);
} catch (e) {
console.error("failed to chat", e);
options.onError?.(e as Error);
Expand Down
7 changes: 4 additions & 3 deletions app/client/platforms/baidu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export class ErnieApi implements LLMApi {
let responseText = "";
let remainText = "";
let finished = false;
let responseRes: Response;

// animate response to make it looks smooth
function animateResponseText() {
Expand Down Expand Up @@ -191,7 +192,7 @@ export class ErnieApi implements LLMApi {
const finish = () => {
if (!finished) {
finished = true;
options.onFinish(responseText + remainText);
options.onFinish(responseText + remainText, responseRes);
}
};

Expand All @@ -204,7 +205,7 @@ export class ErnieApi implements LLMApi {
clearTimeout(requestTimeoutId);
const contentType = res.headers.get("content-type");
console.log("[Baidu] request response content type: ", contentType);

responseRes = res;
if (contentType?.startsWith("text/plain")) {
responseText = await res.clone().text();
return finish();
Expand Down Expand Up @@ -267,7 +268,7 @@ export class ErnieApi implements LLMApi {

const resJson = await res.json();
const message = resJson?.result;
options.onFinish(message);
options.onFinish(message, res);
}
} catch (e) {
console.log("[Request] failed to make a chat request", e);
Expand Down
7 changes: 4 additions & 3 deletions app/client/platforms/bytedance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export class DoubaoApi implements LLMApi {
let responseText = "";
let remainText = "";
let finished = false;
let responseRes: Response;

// animate response to make it looks smooth
function animateResponseText() {
Expand Down Expand Up @@ -159,7 +160,7 @@ export class DoubaoApi implements LLMApi {
const finish = () => {
if (!finished) {
finished = true;
options.onFinish(responseText + remainText);
options.onFinish(responseText + remainText, responseRes);
}
};

Expand All @@ -175,7 +176,7 @@ export class DoubaoApi implements LLMApi {
"[ByteDance] request response content type: ",
contentType,
);

responseRes = res;
if (contentType?.startsWith("text/plain")) {
responseText = await res.clone().text();
return finish();
Expand Down Expand Up @@ -241,7 +242,7 @@ export class DoubaoApi implements LLMApi {

const resJson = await res.json();
const message = this.extractMessage(resJson);
options.onFinish(message);
options.onFinish(message, res);
}
} catch (e) {
console.log("[Request] failed to make a chat request", e);
Expand Down
2 changes: 1 addition & 1 deletion app/client/platforms/glm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class ChatGLMApi implements LLMApi {

const resJson = await res.json();
const message = this.extractMessage(resJson);
options.onFinish(message);
options.onFinish(message, res);
}
} catch (e) {
console.log("[Request] failed to make a chat request", e);
Expand Down
2 changes: 1 addition & 1 deletion app/client/platforms/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export class GeminiProApi implements LLMApi {
);
}
const message = apiClient.extractMessage(resJson);
options.onFinish(message);
options.onFinish(message, res);
}
} catch (e) {
console.log("[Request] failed to make a chat request", e);
Expand Down
7 changes: 4 additions & 3 deletions app/client/platforms/iflytek.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export class SparkApi implements LLMApi {
let responseText = "";
let remainText = "";
let finished = false;
let responseRes: Response;

// Animate response text to make it look smooth
function animateResponseText() {
Expand All @@ -143,7 +144,7 @@ export class SparkApi implements LLMApi {
const finish = () => {
if (!finished) {
finished = true;
options.onFinish(responseText + remainText);
options.onFinish(responseText + remainText, responseRes);
}
};

Expand All @@ -156,7 +157,7 @@ export class SparkApi implements LLMApi {
clearTimeout(requestTimeoutId);
const contentType = res.headers.get("content-type");
console.log("[Spark] request response content type: ", contentType);

responseRes = res;
if (contentType?.startsWith("text/plain")) {
responseText = await res.clone().text();
return finish();
Expand Down Expand Up @@ -231,7 +232,7 @@ export class SparkApi implements LLMApi {

const resJson = await res.json();
const message = this.extractMessage(resJson);
options.onFinish(message);
options.onFinish(message, res);
}
} catch (e) {
console.log("[Request] failed to make a chat request", e);
Expand Down
2 changes: 1 addition & 1 deletion app/client/platforms/moonshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class MoonshotApi implements LLMApi {

const resJson = await res.json();
const message = this.extractMessage(resJson);
options.onFinish(message);
options.onFinish(message, res);
}
} catch (e) {
console.log("[Request] failed to make a chat request", e);
Expand Down
8 changes: 7 additions & 1 deletion app/client/platforms/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface RequestPayload {
frequency_penalty: number;
top_p: number;
max_tokens?: number;
max_completion_tokens?: number;
}

export interface DalleRequestPayload {
Expand Down Expand Up @@ -233,6 +234,11 @@ export class ChatGPTApi implements LLMApi {
// Please do not ask me why not send max_tokens, no reason, this param is just shit, I dont want to explain anymore.
};

// O1 使用 max_completion_tokens 控制token数 (https://platform.openai.com/docs/guides/reasoning#controlling-costs)
if (isO1) {
requestPayload["max_completion_tokens"] = modelConfig.max_tokens;
}

// add max_tokens to vision model
if (visionModel) {
requestPayload["max_tokens"] = Math.max(modelConfig.max_tokens, 4000);
Expand Down Expand Up @@ -361,7 +367,7 @@ export class ChatGPTApi implements LLMApi {

const resJson = await res.json();
const message = await this.extractMessage(resJson);
options.onFinish(message);
options.onFinish(message, res);
}
} catch (e) {
console.log("[Request] failed to make a chat request", e);
Expand Down
7 changes: 4 additions & 3 deletions app/client/platforms/tencent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class HunyuanApi implements LLMApi {
let responseText = "";
let remainText = "";
let finished = false;
let responseRes: Response;

// animate response to make it looks smooth
function animateResponseText() {
Expand Down Expand Up @@ -171,7 +172,7 @@ export class HunyuanApi implements LLMApi {
const finish = () => {
if (!finished) {
finished = true;
options.onFinish(responseText + remainText);
options.onFinish(responseText + remainText, responseRes);
}
};

Expand All @@ -187,7 +188,7 @@ export class HunyuanApi implements LLMApi {
"[Tencent] request response content type: ",
contentType,
);

responseRes = res;
if (contentType?.startsWith("text/plain")) {
responseText = await res.clone().text();
return finish();
Expand Down Expand Up @@ -253,7 +254,7 @@ export class HunyuanApi implements LLMApi {

const resJson = await res.json();
const message = this.extractMessage(resJson);
options.onFinish(message);
options.onFinish(message, res);
}
} catch (e) {
console.log("[Request] failed to make a chat request", e);
Expand Down
Loading

0 comments on commit b4756b3

Please sign in to comment.