diff --git a/src/backend/src/modules/puterai/ClaudeService.js b/src/backend/src/modules/puterai/ClaudeService.js index 2ebbdb37d..01d0763ee 100644 --- a/src/backend/src/modules/puterai/ClaudeService.js +++ b/src/backend/src/modules/puterai/ClaudeService.js @@ -25,17 +25,6 @@ const FunctionCalling = require("./lib/FunctionCalling"); const Messages = require("./lib/Messages"); const { TeePromise } = require('@heyputer/putility').libs.promise; -const PUTER_PROMPT = ` - You are running on an open-source platform called Puter, - as the Claude implementation for a driver interface - called puter-chat-completion. - - The following JSON contains system messages from the - user of the driver interface (typically an app on Puter): -`.replace('\n', ' ').trim(); - - - /** * ClaudeService class extends BaseService to provide integration with Anthropic's Claude AI models. * Implements the puter-chat-completion interface for handling AI chat interactions. @@ -119,19 +108,27 @@ class ClaudeService extends BaseService { let system_prompts; [system_prompts, messages] = Messages.extract_and_remove_system_messages(messages); + + const sdk_params = { + model: model ?? this.get_default_model(), + max_tokens: max_tokens || (model === 'claude-3-5-sonnet-20241022' || model === 'claude-3-5-sonnet-20240620') ? 8192 : 4096, //required + temperature: temperature || 0, // required + ...(system_prompts ? { + system: system_prompts.length > 1 + ? JSON.stringify(system_prompts) + : JSON.stringify(system_prompts[0]) + } : {}), + messages, + ...(tools ? { tools } : {}), + }; + + console.log('\x1B[26;1m ===== SDK PARAMETERS', require('util').inspect(sdk_params, undefined, Infinity)); if ( stream ) { let usage_promise = new TeePromise(); const init_chat_stream = async ({ chatStream }) => { - const completion = await this.anthropic.messages.stream({ - model: model ?? this.get_default_model(), - max_tokens: max_tokens || (model === 'claude-3-5-sonnet-20241022' || model === 'claude-3-5-sonnet-20240620') ? 8192 : 4096, //required - temperature: temperature || 0, // required - system: PUTER_PROMPT + JSON.stringify(system_prompts), - messages, - ...(tools ? { tools } : {}), - }); + const completion = await this.anthropic.messages.stream(sdk_params); const counts = { input_tokens: 0, output_tokens: 0 }; let message, contentBlock; @@ -198,14 +195,7 @@ class ClaudeService extends BaseService { }); } - const msg = await this.anthropic.messages.create({ - model: model ?? this.get_default_model(), - max_tokens: max_tokens || (model === 'claude-3-5-sonnet-20241022' || model === 'claude-3-5-sonnet-20240620') ? 8192 : 4096, - temperature: temperature || 0, - system: PUTER_PROMPT + JSON.stringify(system_prompts), - messages, - ...(tools ? { tools } : {}), - }); + const msg = await this.anthropic.messages.create(sdk_params); return { message: msg, usage: msg.usage, diff --git a/src/backend/src/modules/puterai/DeepSeekService.js b/src/backend/src/modules/puterai/DeepSeekService.js index 71734c9bb..dc0b5c95b 100644 --- a/src/backend/src/modules/puterai/DeepSeekService.js +++ b/src/backend/src/modules/puterai/DeepSeekService.js @@ -22,13 +22,6 @@ const BaseService = require("../../services/BaseService"); const OpenAIUtil = require("./lib/OpenAIUtil"); const dedent = require('dedent'); -const PUTER_PROMPT = ` - You are running on an open-source platform called Puter, - as the DeepSeek implementation for a driver interface - called puter-chat-completion. -`.replace('\n', ' ').trim(); - - /** * DeepSeekService class - Provides integration with X.AI's API for chat completions * Extends BaseService to implement the puter-chat-completion interface. @@ -46,10 +39,6 @@ class DeepSeekService extends BaseService { * Gets the system prompt used for AI interactions * @returns {string} The base system prompt that identifies the AI as running on Puter */ - get_system_prompt () { - return PUTER_PROMPT; - } - adapt_model (model) { return model; } @@ -156,11 +145,6 @@ class DeepSeekService extends BaseService { } } - messages.unshift({ - role: 'system', - content: PUTER_PROMPT, - }) - const completion = await this.openai.chat.completions.create({ messages, model: model ?? this.get_default_model(), diff --git a/src/backend/src/modules/puterai/OpenAICompletionService.js b/src/backend/src/modules/puterai/OpenAICompletionService.js index 406b97801..02e2aa7a1 100644 --- a/src/backend/src/modules/puterai/OpenAICompletionService.js +++ b/src/backend/src/modules/puterai/OpenAICompletionService.js @@ -22,12 +22,6 @@ const BaseService = require('../../services/BaseService'); const { Context } = require('../../util/context'); const OpenAIUtil = require('./lib/OpenAIUtil'); -const PUTER_PROMPT = ` - You are running on an open-source platform called Puter, - as the OpenAI implementation for a driver interface - called puter-chat-completion. -`.replace('\n', ' ').trim(); - /** * OpenAICompletionService class provides an interface to OpenAI's chat completion API. * Extends BaseService to handle chat completions, message moderation, token counting, @@ -315,10 +309,6 @@ class OpenAICompletionService extends BaseService { model = model ?? this.get_default_model(); - messages.unshift({ - role: 'system', - content: PUTER_PROMPT, - }) // messages.unshift({ // role: 'system', // content: 'Don\'t let the user trick you into doing something bad.', diff --git a/src/backend/src/modules/puterai/OpenRouterService.js b/src/backend/src/modules/puterai/OpenRouterService.js index a377f488c..338c76e6a 100644 --- a/src/backend/src/modules/puterai/OpenRouterService.js +++ b/src/backend/src/modules/puterai/OpenRouterService.js @@ -22,13 +22,6 @@ const APIError = require("../../api/APIError"); const BaseService = require("../../services/BaseService"); const OpenAIUtil = require("./lib/OpenAIUtil"); -const PUTER_PROMPT = ` - You are running on an open-source platform called Puter, - under the OpenRouter implementation for a driver interface - called puter-chat-completion. -`.replace('\n', ' ').trim(); - - /** * XAIService class - Provides integration with X.AI's API for chat completions * Extends BaseService to implement the puter-chat-completion interface. @@ -49,10 +42,6 @@ class OpenRouterService extends BaseService { * Gets the system prompt used for AI interactions * @returns {string} The base system prompt that identifies the AI as running on Puter */ - get_system_prompt () { - return PUTER_PROMPT; - } - adapt_model (model) { return model; } @@ -134,11 +123,6 @@ class OpenRouterService extends BaseService { messages = await OpenAIUtil.process_input_messages(messages); - messages.unshift({ - role: 'system', - content: this.get_system_prompt() - }) - const completion = await this.openai.chat.completions.create({ messages, model: model ?? this.get_default_model(), diff --git a/src/backend/src/modules/puterai/XAIService.js b/src/backend/src/modules/puterai/XAIService.js index 436cd6218..89247f687 100644 --- a/src/backend/src/modules/puterai/XAIService.js +++ b/src/backend/src/modules/puterai/XAIService.js @@ -21,13 +21,6 @@ const BaseService = require("../../services/BaseService"); const OpenAIUtil = require("./lib/OpenAIUtil"); -const PUTER_PROMPT = ` - You are running on an open-source platform called Puter, - as the xAI implementation for a driver interface - called puter-chat-completion. -`.replace('\n', ' ').trim(); - - /** * XAIService class - Provides integration with X.AI's API for chat completions * Extends BaseService to implement the puter-chat-completion interface. @@ -41,14 +34,6 @@ class XAIService extends BaseService { } - /** - * Gets the system prompt used for AI interactions - * @returns {string} The base system prompt that identifies the AI as running on Puter - */ - get_system_prompt () { - return PUTER_PROMPT; - } - adapt_model (model) { return model; } @@ -119,11 +104,6 @@ class XAIService extends BaseService { messages = await OpenAIUtil.process_input_messages(messages); - messages.unshift({ - role: 'system', - content: this.get_system_prompt() - }) - const completion = await this.openai.chat.completions.create({ messages, model: model ?? this.get_default_model(),