🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(nvidia): add new models and simplify payload handling for NVIDIA NIM (#12333)
Hardyef474afe8441
diff --git a/packages/model-bank/src/aiModels/index.ts b/packages/model-bank/src/aiModels/index.tsindex 95762028547..a0b3c6ea605 100644--- a/packages/model-bank/src/aiModels/index.ts+++ b/packages/model-bank/src/aiModels/index.ts@@ -1,6 +1,6 @@import { ENABLE_BUSINESS_FEATURES } from '@lobechat/business-const';-import type { AiFullModelCard, LobeDefaultAiModelListItem } from '../types/aiModel';+import { type AiFullModelCard, type LobeDefaultAiModelListItem } from '../types/aiModel';import { default as ai21 } from './ai21';import { default as ai302 } from './ai302';import { default as ai360 } from './ai360';diff --git a/packages/model-bank/src/aiModels/nvidia.ts b/packages/model-bank/src/aiModels/nvidia.tsindex 45e87567a56..d91a95d780d 100644--- a/packages/model-bank/src/aiModels/nvidia.ts+++ b/packages/model-bank/src/aiModels/nvidia.ts@@ -26,6 +26,88 @@ const nvidiaChatModels: AIChatModelCard[] = [maxOutput: 16_384,type: 'chat',},+ {+ abilities: {+ functionCall: true,+ reasoning: true,+ },+ contextWindowTokens: 204_800,+ description:+ 'MiniMax-M2.1 is a compact, fast, cost-effective MoE model built for top-tier coding and agent performance.',+ displayName: 'MiniMax-M2.1',+ enabled: true,+ id: 'minimaxai/minimax-m2.1',+ maxOutput: 131_072,+ type: 'chat',+ },+ {+ abilities: {+ functionCall: true,+ reasoning: true,+ },+ contextWindowTokens: 131_072,+ description:+ 'DeepSeek V3.2 is a next-gen reasoning model with stronger complex reasoning and chain-of-thought capabilities.',+ displayName: 'DeepSeek V3.2',+ enabled: true,+ id: 'deepseek-ai/deepseek-v3.2',+ maxOutput: 65_536,+ settings: {+ extendParams: ['enableReasoning'],+ },+ type: 'chat',+ },+ {+ abilities: {+ functionCall: true,+ reasoning: true,+ },+ contextWindowTokens: 200_000,+ description:+ 'GLM-4.7 is Zhipu latest flagship model, enhanced for Agentic Coding scenarios with improved coding capabilities.',+ displayName: 'GLM-4.7',+ enabled: true,+ id: 'z-ai/glm4.7',+ maxOutput: 131_072,+ settings: {+ extendParams: ['enableReasoning'],+ },+ type: 'chat',+ },+ {+ abilities: {+ functionCall: true,+ reasoning: true,+ },+ contextWindowTokens: 200_000,+ description:+ "GLM-5 is Zhipu AI's new flagship foundation model for agent engineering, achieving open-source SOTA performance in coding and agent capabilities. It matches Claude Opus 4.5 in performance.",+ displayName: 'GLM-5',+ enabled: true,+ id: 'z-ai/glm5',+ maxOutput: 131_072,+ settings: {+ extendParams: ['enableReasoning'],+ },+ type: 'chat',+ },+ {+ abilities: {+ functionCall: true,+ reasoning: true,+ },+ contextWindowTokens: 262_144,+ description:+ 'Kimi K2.5 is the most intelligent Kimi model to date, featuring native multimodal architecture.',+ displayName: 'Kimi K2.5',+ enabled: true,+ id: 'moonshotai/kimi-k2.5',+ maxOutput: 65_536,+ settings: {+ extendParams: ['enableReasoning'],+ },+ type: 'chat',+ },{abilities: {functionCall: true,diff --git a/packages/model-bank/src/types/aiModel.ts b/packages/model-bank/src/types/aiModel.tsindex 6a58d92008a..3b9f9bbb8e6 100644--- a/packages/model-bank/src/types/aiModel.ts+++ b/packages/model-bank/src/types/aiModel.ts@@ -1,6 +1,6 @@import { z } from 'zod';-import type { ModelParamsSchema } from '../standard-parameters';+import { type ModelParamsSchema } from '../standard-parameters';export type ModelPriceCurrency = 'CNY' | 'USD';diff --git a/packages/model-runtime/src/providers/nvidia/index.test.ts b/packages/model-runtime/src/providers/nvidia/index.test.tsindex 944ea4fd89f..2def07d6d6b 100644--- a/packages/model-runtime/src/providers/nvidia/index.test.ts+++ b/packages/model-runtime/src/providers/nvidia/index.test.ts@@ -21,7 +21,8 @@ testProvider({describe('LobeNvidiaAI - custom features', () => {describe('handlePayload', () => {- it('should add chat_template_kwargs with thinking enabled for thinking models', () => {+ // thinking parameter conversion+ it('should add chat_template_kwargs with thinking: true when thinking.type is enabled', () => {const payload = {model: 'deepseek-ai/deepseek-v3.1',messages: [{ role: 'user', content: 'test' }],@@ -37,9 +38,9 @@ describe('LobeNvidiaAI - custom features', () => {});});- it('should add chat_template_kwargs with thinking disabled for thinking models', () => {+ it('should add chat_template_kwargs with thinking: false when thinking.type is disabled', () => {const payload = {- model: 'deepseek-ai/deepseek-v3.1-terminus',+ model: 'deepseek-ai/deepseek-v3.1',messages: [{ role: 'user', content: 'test' }],thinking: { type: 'disabled' as const },};@@ -47,13 +48,13 @@ describe('LobeNvidiaAI - custom features', () => {const result = params.chatCompletion!.handlePayload!(payload as any);expect(result).toEqual({- model: 'deepseek-ai/deepseek-v3.1-terminus',+ model: 'deepseek-ai/deepseek-v3.1',messages: [{ role: 'user', content: 'test' }],chat_template_kwargs: { thinking: false },});});- it('should add chat_template_kwargs with thinking undefined for thinking models without thinking type', () => {+ it('should not add chat_template_kwargs when thinking type is not set', () => {const payload = {model: 'deepseek-ai/deepseek-v3.1',messages: [{ role: 'user', content: 'test' }],@@ -65,15 +66,13 @@ describe('LobeNvidiaAI - custom features', () => {expect(result).toEqual({model: 'deepseek-ai/deepseek-v3.1',messages: [{ role: 'user', content: 'test' }],- chat_template_kwargs: { thinking: undefined },});});- it('should not add chat_template_kwargs for non-thinking models', () => {+ it('should not add chat_template_kwargs when thinking param is not provided', () => {const payload = {model: 'meta/llama-3.1-8b-instruct',messages: [{ role: 'user', content: 'test' }],- thinking: { type: 'enabled' as const },};const result = params.chatCompletion!.handlePayload!(payload as any);@@ -84,21 +83,83 @@ describe('LobeNvidiaAI - custom features', () => {});});- it('should handle payload without thinking parameter', () => {+ it('should use enable_thinking and clear_thinking for GLM models when enabled', () => {const payload = {- model: 'deepseek-ai/deepseek-v3.1',+ model: 'z-ai/glm5',messages: [{ role: 'user', content: 'test' }],+ thinking: { type: 'enabled' as const },};const result = params.chatCompletion!.handlePayload!(payload as any);- expect(result).toEqual({- model: 'deepseek-ai/deepseek-v3.1',+ expect(result.chat_template_kwargs).toEqual({ enable_thinking: true, clear_thinking: false });+ });++ it('should use enable_thinking and clear_thinking for GLM models when disabled', () => {+ const payload = {+ model: 'z-ai/glm5',messages: [{ role: 'user', content: 'test' }],- chat_template_kwargs: { thinking: undefined },+ thinking: { type: 'disabled' as const },+ };++ const result = params.chatCompletion!.handlePayload!(payload as any);++ expect(result.chat_template_kwargs).toEqual({+ enable_thinking: false,+ clear_thinking: false,});});+ it('should use thinking for non-GLM models', () => {+ const payload = {+ model: 'deepseek-ai/deepseek-v3.2',+ messages: [{ role: 'user', content: 'test' }],+ thinking: { type: 'enabled' as const },+ };++ const result = params.chatCompletion!.handlePayload!(payload as any);++ expect(result.chat_template_kwargs).toEqual({ thinking: true });+ });++ // reasoning -> reasoning_content conversion+ it('should convert reasoning to reasoning_content for all NVIDIA models', () => {+ const payload = {+ model: 'meta/llama-3.1-8b-instruct',+ messages: [+ { role: 'user', content: 'test' },+ { role: 'assistant', reasoning: { content: 'thinking process' }, content: 'response' },+ ],+ };++ const result = params.chatCompletion!.handlePayload!(payload as any);++ expect(result.messages).toEqual([+ { role: 'user', content: 'test' },+ { role: 'assistant', content: 'response', reasoning_content: 'thinking process' },+ ]);+ });++ it('should convert reasoning to reasoning_content combined with thinking param', () => {+ const payload = {+ model: 'z-ai/glm5',+ messages: [+ { role: 'user', content: 'test' },+ { role: 'assistant', reasoning: { content: 'thinking process' }, content: 'response' },+ ],+ thinking: { type: 'enabled' as const },+ };++ const result = params.chatCompletion!.handlePayload!(payload as any);++ expect(result.messages).toEqual([+ { role: 'user', content: 'test' },+ { role: 'assistant', content: 'response', reasoning_content: 'thinking process' },+ ]);+ // GLM models use enable_thinking + clear_thinking+ expect(result.chat_template_kwargs).toEqual({ enable_thinking: true, clear_thinking: false });+ });+it('should preserve other payload properties', () => {const payload = {model: 'deepseek-ai/deepseek-v3.1',diff --git a/packages/model-runtime/src/providers/nvidia/index.ts b/packages/model-runtime/src/providers/nvidia/index.tsindex f1ed28aaeb5..9f1aa908809 100644--- a/packages/model-runtime/src/providers/nvidia/index.ts+++ b/packages/model-runtime/src/providers/nvidia/index.ts@@ -1,13 +1,12 @@import { ModelProvider } from 'model-bank';-import type { OpenAICompatibleFactoryOptions } from '../../core/openaiCompatibleFactory';+import { type OpenAICompatibleFactoryOptions } from '../../core/openaiCompatibleFactory';import { createOpenAICompatibleRuntime } from '../../core/openaiCompatibleFactory';import { processMultiProviderModelList } from '../../utils/modelParse';-const THINKING_MODELS = new Set([- 'deepseek-ai/deepseek-v3.1',- 'deepseek-ai/deepseek-v3.1-terminus',-]);+// Models that support preserved thinking (enable_thinking + clear_thinking parameters)+// Ref: https://docs.z.ai/guides/capabilities/thinking-mode#preserved-thinking+const supportPreservedThinkingModels = new Set(['z-ai/glm4.7', 'z-ai/glm5']);export interface NvidiaModelCard {id: string;@@ -17,18 +16,49 @@ export const params = {baseURL: 'https://integrate.api.nvidia.com/v1',chatCompletion: {handlePayload: (payload) => {- const { model, thinking, ...rest } = payload;+ const { model, thinking, messages, ...rest } = payload;+ // Convert reasoning to reasoning_content for NVIDIA API format+ // NVIDIA NIM requires reasoning_content instead of reasoning for all models+ const processedMessages = messages?.map((message: any) => {+ if (message.role === 'assistant' && message.reasoning?.content) {+ const { reasoning, ...restMessage } = message;+ return {+ ...restMessage,+ reasoning_content: reasoning.content,+ };+ }+ return message;+ });++ // Convert thinking.type to boolean for APIconst thinkingFlag =thinking?.type === 'enabled' ? true : thinking?.type === 'disabled' ? false : undefined;+ // Check if model uses preserved thinking (enable_thinking + clear_thinking)+ const usePreservedThinking = model && supportPreservedThinkingModels.has(model);++ const chatTemplateKwargs: Record<string, any> = {};++ if (thinkingFlag !== undefined) {+ if (usePreservedThinking) {+ // Models with preserved thinking: use enable_thinking + clear_thinking+ // set clear_thinking to false to preserve reasoning content across turns+ chatTemplateKwargs.enable_thinking = thinkingFlag;+ chatTemplateKwargs.clear_thinking = false;+ } else {+ // Other models: use thinking parameter+ chatTemplateKwargs.thinking = thinkingFlag;+ }+ }+return {...rest,model,- ...(THINKING_MODELS.has(model)- ? {- chat_template_kwargs: { thinking: thinkingFlag },- }+ messages: processedMessages,+ // Send chat_template_kwargs when thinking is explicitly set+ ...(Object.keys(chatTemplateKwargs).length > 0+ ? { chat_template_kwargs: chatTemplateKwargs }: {}),} as any;},