in src/app/app.component.ts [74:113]
async recognize() {
if (!this.canvas()) return;
if (!this.prompt) return;
this.error = null;
console.info('Querying the model with prompt', this.prompt);
const data = this.canvas()!.getBase64Drawing();
if (!data) return;
this.disabled = true;
this.model = this.generativeService.getModel(this.apiKey);
try {
const result = await this.model.generateContent([
this.prompt,
{
inlineData: {
data,
mimeType: 'image/png',
},
},
]);
const response = await result.response;
const text = response.text();
this.output = this.sanitizer.bypassSecurityTrustHtml(
await marked.parse(text)
);
console.info('Received output from the model', text);
await this.say(text);
} catch (e) {
this.error = e;
} finally {
this.disabled = false;
}
}