mirror of
https://github.com/jina-ai/node-DeepResearch.git
synced 2026-03-22 07:29:35 +08:00
Merge branch 'main' of https://github.com/jina-ai/node-DeepResearch
This commit is contained in:
36
src/app.ts
36
src/app.ts
@@ -391,16 +391,32 @@ app.post('/v1/chat/completions', (async (req: Request, res: Response) => {
|
|||||||
console.log('messages', JSON.stringify(body.messages));
|
console.log('messages', JSON.stringify(body.messages));
|
||||||
|
|
||||||
// clean <think> from all assistant messages
|
// clean <think> from all assistant messages
|
||||||
body.messages?.filter(message => message.role === 'assistant').forEach(message => {
|
body.messages?.forEach(message => {
|
||||||
// 2 cases message.content can be a string or an array
|
if (message.role === 'assistant') {
|
||||||
if (typeof message.content === 'string') {
|
// 2 cases message.content can be a string or an array
|
||||||
message.content = (message.content as string).replace(/<think>[\s\S]*?<\/think>/g, '').trim();
|
if (typeof message.content === 'string') {
|
||||||
} else if (Array.isArray(message.content)) {
|
message.content = (message.content as string).replace(/<think>[\s\S]*?<\/think>/g, '').trim();
|
||||||
// find all type: text and clean <think> from .text
|
} else if (Array.isArray(message.content)) {
|
||||||
message.content.forEach((content: any) => {
|
// find all type: text and clean <think> from .text
|
||||||
if (content.type === 'text') {
|
message.content.forEach((content: any) => {
|
||||||
content.text = (content.text as string).replace(/<think>[\s\S]*?<\/think>/g, '').trim();
|
if (content.type === 'text') {
|
||||||
}});
|
content.text = (content.text as string).replace(/<think>[\s\S]*?<\/think>/g, '').trim();
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
} else if (message.role === 'user' && Array.isArray(message.content)) {
|
||||||
|
message.content = message.content.map((content: any) => {
|
||||||
|
if (content.type === 'image_url') {
|
||||||
|
return {
|
||||||
|
type: 'image',
|
||||||
|
image: content.image_url?.url || '',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return content;
|
||||||
|
});
|
||||||
|
} else if (message.role === 'system') {
|
||||||
|
if (Array.isArray(message.content)) {
|
||||||
|
message.content = message.content.map((content: any) => `${content.text || content}`).join(' ');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user