Skip to content

Commit 5f6f02b

Browse files
Fix prompt format for image description in prompt array (#1516)
* Fix prompt format for image description in prompt array * [Bug] Fix syntax error (#1515) * Fix syntax error * Fix prompt format for audio transcription in session.promptStreaming * Fix formatting --------- Co-authored-by: Sebastian Benz <sbenz@google.com>
1 parent eca778c commit 5f6f02b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

functional-samples/ai.gemini-on-device-alt-texter/background.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,16 @@ async function generateAltText(imgSrc) {
2020

2121
// Run the prompt
2222
const prompt = [
23-
`Please provide a functional, objective description of the provided image in no more than around 30 words so that someone who could not see it would be able to imagine it. If possible, follow an “object-action-context” framework. The object is the main focus. The action describes what’s happening, usually what the object is doing. The context describes the surrounding environment. If there is text found in the image, do your best to transcribe the important bits, even if it extends the word count beyond 30 words. It should not contain quotation marks, as those tend to cause issues when rendered on the web. If there is no text found in the image, then there is no need to mention it. You should not begin the description with any variation of “The image”.`,
24-
{ type: 'image', content: imageBitmap }
23+
{
24+
role: 'user',
25+
content: [
26+
{
27+
type: 'text',
28+
value: `Please provide a functional, objective description of the provided image in no more than around 30 words so that someone who could not see it would be able to imagine it. If possible, follow an “object-action-context” framework. The object is the main focus. The action describes what’s happening, usually what the object is doing. The context describes the surrounding environment. If there is text found in the image, do your best to transcribe the important bits, even if it extends the word count beyond 30 words. It should not contain quotation marks, as those tend to cause issues when rendered on the web. If there is no text found in the image, then there is no need to mention it. You should not begin the description with any variation of “The image”.`
29+
},
30+
{ type: 'image', value: imageBitmap }
31+
]
32+
}
2533
];
2634
return await session.prompt(prompt);
2735
}

functional-samples/ai.gemini-on-device-audio-scribe/sidepanel.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ chrome.runtime.onMessage.addListener(async ({ data }) => {
4646
const session = await LanguageModel.create({
4747
expectedInputs: [{ type: 'audio' }]
4848
});
49+
4950
const stream = session.promptStreaming([
5051
{
5152
role: 'user',

0 commit comments

Comments
 (0)