Skip to content

Commit 732b5de

Browse files
authored
Revert "Fix Tool Parsing to Allow Object Return Value" (#534)
1 parent 27d12fa commit 732b5de

File tree

1 file changed

+21
-30
lines changed

1 file changed

+21
-30
lines changed

plugins/openai/src/llm.ts

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -636,36 +636,27 @@ const buildMessage = async (msg: llm.ChatMessage, cacheKey: any) => {
636636
break;
637637
}
638638

639-
if (msg.role === llm.ChatRole.TOOL) {
640-
try {
641-
const toolCallOutput = JSON.stringify(msg.content);
642-
oaiMsg.content = toolCallOutput;
643-
} catch (e) {
644-
throw Error(`Tool call output is not JSON serializable: ${e}`);
645-
}
646-
} else {
647-
if (typeof msg.content === 'string') {
648-
oaiMsg.content = msg.content;
649-
} else if (Array.isArray(msg.content)) {
650-
oaiMsg.content = (await Promise.all(
651-
msg.content.map(async (c) => {
652-
if (typeof c === 'string') {
653-
return { type: 'text', text: c };
654-
} else if (
655-
// typescript type guard for determining ChatAudio vs ChatImage
656-
((c: llm.ChatAudio | llm.ChatImage): c is llm.ChatImage => {
657-
return (c as llm.ChatImage).image !== undefined;
658-
})(c)
659-
) {
660-
return await buildImageContent(c, cacheKey);
661-
} else {
662-
throw new Error('ChatAudio is not supported');
663-
}
664-
}),
665-
)) as OpenAI.ChatCompletionContentPart[];
666-
} else if (msg.content === undefined) {
667-
oaiMsg.content = '';
668-
}
639+
if (typeof msg.content === 'string') {
640+
oaiMsg.content = msg.content;
641+
} else if (Array.isArray(msg.content)) {
642+
oaiMsg.content = (await Promise.all(
643+
msg.content.map(async (c) => {
644+
if (typeof c === 'string') {
645+
return { type: 'text', text: c };
646+
} else if (
647+
// typescript type guard for determining ChatAudio vs ChatImage
648+
((c: llm.ChatAudio | llm.ChatImage): c is llm.ChatImage => {
649+
return (c as llm.ChatImage).image !== undefined;
650+
})(c)
651+
) {
652+
return await buildImageContent(c, cacheKey);
653+
} else {
654+
throw new Error('ChatAudio is not supported');
655+
}
656+
}),
657+
)) as OpenAI.ChatCompletionContentPart[];
658+
} else if (msg.content === undefined) {
659+
oaiMsg.content = '';
669660
}
670661

671662
// make sure to provide when function has been called inside the context

0 commit comments

Comments
 (0)