Fix: Handle image URLs in custom model responses

Improves the formatting of image URLs within responses from custom models.  This ensures that image URLs are correctly presented in the user interface.
This commit is contained in:
n4ze3m 2024-11-10 13:29:41 +05:30
parent 9c7a3f5ddc
commit f52e3d564a

View File

@ -1,18 +1,16 @@
import { isCustomModel } from "@/db/models"
import { HumanMessage, type MessageContent } from "@langchain/core/messages"
type HumanMessageType = {
content: MessageContent,
content: MessageContent
model: string
}
export const humanMessageFormatter = ({ content, model }: HumanMessageType) => {
const isCustom = isCustomModel(model)
if (isCustom) {
if(typeof content !== 'string') {
if (typeof content !== "string") {
if (content.length > 1) {
// this means that we need to reformat the image_url
const newContent: MessageContent = [
@ -33,11 +31,16 @@ export const humanMessageFormatter = ({ content, model }: HumanMessageType) => {
return new HumanMessage({
content: newContent
})
} else {
return new HumanMessage({
//@ts-ignore
content: content[0].text
})
}
}
}
return new HumanMessage({
content,
content
})
}