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:
parent
9c7a3f5ddc
commit
f52e3d564a
@ -1,43 +1,46 @@
|
|||||||
import { isCustomModel } from "@/db/models"
|
import { isCustomModel } from "@/db/models"
|
||||||
import { HumanMessage, type MessageContent } from "@langchain/core/messages"
|
import { HumanMessage, type MessageContent } from "@langchain/core/messages"
|
||||||
|
|
||||||
|
|
||||||
type HumanMessageType = {
|
type HumanMessageType = {
|
||||||
content: MessageContent,
|
content: MessageContent
|
||||||
model: string
|
model: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const humanMessageFormatter = ({ content, model }: HumanMessageType) => {
|
export const humanMessageFormatter = ({ content, model }: HumanMessageType) => {
|
||||||
|
const isCustom = isCustomModel(model)
|
||||||
const isCustom = isCustomModel(model)
|
|
||||||
|
|
||||||
if(isCustom) {
|
if (isCustom) {
|
||||||
if(typeof content !== 'string') {
|
if (typeof content !== "string") {
|
||||||
if(content.length > 1) {
|
if (content.length > 1) {
|
||||||
// this means that we need to reformat the image_url
|
// this means that we need to reformat the image_url
|
||||||
const newContent: MessageContent = [
|
const newContent: MessageContent = [
|
||||||
{
|
{
|
||||||
type: "text",
|
type: "text",
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
text: content[0].text
|
text: content[0].text
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "image_url",
|
type: "image_url",
|
||||||
image_url: {
|
image_url: {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
url: content[1].image_url
|
url: content[1].image_url
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
return new HumanMessage({
|
|
||||||
content: newContent
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
return new HumanMessage({
|
||||||
|
content: newContent
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return new HumanMessage({
|
||||||
|
//@ts-ignore
|
||||||
|
content: content[0].text
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return new HumanMessage({
|
|
||||||
content,
|
return new HumanMessage({
|
||||||
})
|
content
|
||||||
}
|
})
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user