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,19 +1,17 @@
|
||||
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(content.length > 1) {
|
||||
if (isCustom) {
|
||||
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
|
||||
})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user