forked from langchain-ai/langchainjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
format prompt messages with openai image content (langchain-ai#3212)
* format prompt messages with openai image content * cleanup
- Loading branch information
1 parent
da7f671
commit 25c3cff
Showing
2 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { ChatPromptTemplate } from "../../prompts/chat.js"; | ||
import { HumanMessage } from "../index.js"; | ||
|
||
test("Test ChatPromptTemplate can format OpenAI content image messages", async () => { | ||
const message = new HumanMessage({ | ||
content: [ | ||
{ | ||
type: "image_url", | ||
image_url: { | ||
url: `data:image/jpeg;base64,{image_string}`, | ||
}, | ||
}, | ||
], | ||
}); | ||
const prompt = ChatPromptTemplate.fromMessages([ | ||
message, | ||
["ai", "Will this format with multiple messages?: {yes_or_no}"], | ||
]); | ||
const formatted = await prompt.invoke({ | ||
image_string: "base_64_encoded_string", | ||
yes_or_no: "YES!", | ||
}); | ||
expect(formatted.messages[0].content[0]).toEqual({ | ||
type: "image_url", | ||
image_url: { | ||
url: "data:image/jpeg;base64,base_64_encoded_string", | ||
}, | ||
}); | ||
expect(formatted.messages[1].content).toEqual( | ||
"Will this format with multiple messages?: YES!" | ||
); | ||
}); |