mirror of
https://github.com/HeyPuter/puter.git
synced 2026-08-24 23:17:23 +00:00
dev: remove redundant message adaption from claude
This commit is contained in:
@@ -121,34 +121,10 @@ class ClaudeService extends BaseService {
|
|||||||
tools = FunctionCalling.make_claude_tools(tools);
|
tools = FunctionCalling.make_claude_tools(tools);
|
||||||
|
|
||||||
const system_prompts = [];
|
const system_prompts = [];
|
||||||
let previous_was_user = false;
|
for ( let i = messages.length - 1; i >= 0; i-- ) {
|
||||||
for ( const message of messages ) {
|
|
||||||
if ( typeof message.content === 'string' ) {
|
|
||||||
message.content = {
|
|
||||||
type: 'text',
|
|
||||||
text: message.content,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if ( whatis(message.content) !== 'array' ) {
|
|
||||||
message.content = [message.content];
|
|
||||||
}
|
|
||||||
if ( ! message.role ) message.role = 'user';
|
|
||||||
if ( message.role === 'user' && previous_was_user ) {
|
|
||||||
const last_msg = adapted_messages[adapted_messages.length-1];
|
|
||||||
last_msg.content.push(
|
|
||||||
...(Array.isArray ? message.content : [message.content])
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ( message.role === 'system' ) {
|
if ( message.role === 'system' ) {
|
||||||
system_prompts.push(...message.content);
|
system_prompts.push(...message.content);
|
||||||
continue;
|
messages.splice(i, 1);
|
||||||
}
|
|
||||||
adapted_messages.push(message);
|
|
||||||
if ( message.role === 'user' ) {
|
|
||||||
previous_was_user = true;
|
|
||||||
} else {
|
|
||||||
previous_was_user = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user