From 3317fbdba13fa48a6deb1d0c7b7c4d3679e0ec87 Mon Sep 17 00:00:00 2001 From: sxjeru Date: Tue, 29 Oct 2024 21:18:19 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix:=20Update=20zhipu=20para?= =?UTF-8?q?m=20process=20(#4523)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update index.ts * Update index.ts * Update index.ts * Update index.test.ts * Update index.ts --- src/libs/agent-runtime/zhipu/index.test.ts | 25 +++++++++++++++++++--- src/libs/agent-runtime/zhipu/index.ts | 18 +++++++++++++--- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/libs/agent-runtime/zhipu/index.test.ts b/src/libs/agent-runtime/zhipu/index.test.ts index e2f0ebf6f6c0..54e6e648abf3 100644 --- a/src/libs/agent-runtime/zhipu/index.test.ts +++ b/src/libs/agent-runtime/zhipu/index.test.ts @@ -107,6 +107,26 @@ describe('LobeZhipuAI', () => { { content: [{ type: 'text', text: 'Hello again' }], role: 'user' }, ], model: 'glm-4', + temperature: 1.6, + top_p: 1, + }); + + const calledWithParams = spyOn.mock.calls[0][0]; + + expect(calledWithParams.messages[1].content).toEqual([{ type: 'text', text: 'Hello again' }]); + expect(calledWithParams.temperature).toBe(0.8); // temperature should be divided by two + expect(calledWithParams.top_p).toEqual(1); + }); + + it('should pass arameters correctly', async () => { + const spyOn = vi.spyOn(instance['client'].chat.completions, 'create'); + + await instance.chat({ + messages: [ + { content: 'Hello', role: 'user' }, + { content: [{ type: 'text', text: 'Hello again' }], role: 'user' }, + ], + model: 'glm-4-alltools', temperature: 0, top_p: 1, }); @@ -114,9 +134,8 @@ describe('LobeZhipuAI', () => { const calledWithParams = spyOn.mock.calls[0][0]; expect(calledWithParams.messages[1].content).toEqual([{ type: 'text', text: 'Hello again' }]); - expect(calledWithParams.temperature).toBe(0); // temperature 0 should be undefined - expect((calledWithParams as any).do_sample).toBeTruthy(); // temperature 0 should be undefined - expect(calledWithParams.top_p).toEqual(1); // top_p should be transformed correctly + expect(calledWithParams.temperature).toBe(0.01); + expect(calledWithParams.top_p).toEqual(0.99); }); describe('Error', () => { diff --git a/src/libs/agent-runtime/zhipu/index.ts b/src/libs/agent-runtime/zhipu/index.ts index 5f92756e234c..bea46fd33129 100644 --- a/src/libs/agent-runtime/zhipu/index.ts +++ b/src/libs/agent-runtime/zhipu/index.ts @@ -6,12 +6,24 @@ import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory'; export const LobeZhipuAI = LobeOpenAICompatibleFactory({ baseURL: 'https://open.bigmodel.cn/api/paas/v4', chatCompletion: { - handlePayload: ({ temperature, ...payload }: ChatStreamPayload) => + handlePayload: ({ model, temperature, top_p, ...payload }: ChatStreamPayload) => ({ ...payload, - do_sample: temperature === 0, + model, stream: true, - temperature, + ...(model === "glm-4-alltools" ? { + temperature: temperature !== undefined + ? Math.max(0.01, Math.min(0.99, temperature / 2)) + : undefined, + top_p: top_p !== undefined + ? Math.max(0.01, Math.min(0.99, top_p)) + : undefined, + } : { + temperature: temperature !== undefined + ? temperature / 2 + : undefined, + top_p, + }), }) as OpenAI.ChatCompletionCreateParamsStreaming, }, debug: { From d5f029e07ffed929a1cd305891a5e2d3acdcdd2a Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 29 Oct 2024 13:25:35 +0000 Subject: [PATCH 2/2] :bookmark: chore(release): v1.26.8 [skip ci] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### [Version 1.26.8](https://github.com/lobehub/lobe-chat/compare/v1.26.7...v1.26.8) Released on **2024-10-29** #### 🐛 Bug Fixes - **misc**: Update zhipu param process.
Improvements and Fixes #### What's fixed * **misc**: Update zhipu param process, closes [#4523](https://github.com/lobehub/lobe-chat/issues/4523) ([3317fbd](https://github.com/lobehub/lobe-chat/commit/3317fbd))
[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
--- CHANGELOG.md | 25 +++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34faa7c21ed7..ce60f6ed23df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,31 @@ # Changelog +### [Version 1.26.8](https://github.com/lobehub/lobe-chat/compare/v1.26.7...v1.26.8) + +Released on **2024-10-29** + +#### 🐛 Bug Fixes + +- **misc**: Update zhipu param process. + +
+ +
+Improvements and Fixes + +#### What's fixed + +- **misc**: Update zhipu param process, closes [#4523](https://github.com/lobehub/lobe-chat/issues/4523) ([3317fbd](https://github.com/lobehub/lobe-chat/commit/3317fbd)) + +
+ +
+ +[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) + +
+ ### [Version 1.26.7](https://github.com/lobehub/lobe-chat/compare/v1.26.6...v1.26.7) Released on **2024-10-29** diff --git a/package.json b/package.json index bd49bfdd56eb..81ec2b1bcb73 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lobehub/chat", - "version": "1.26.7", + "version": "1.26.8", "description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.", "keywords": [ "framework",