Skip to content

Commit

Permalink
Move create session in try/catch block.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdharmesh committed Dec 17, 2024
1 parent 0942a85 commit 93d2a54
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,16 @@ export const chromeAITextGeneration = async ( prompt = '', content = '' ) => {
supportsTextGeneration &&
supportsTextGeneration.available === 'readily'
) {
const session = await window.ai.languageModel.create( {
initialPrompts: [
{
role: 'system',
content: prompt,
},
],
} );
try {
const session = await window.ai.languageModel.create( {
initialPrompts: [
{
role: 'system',
content: prompt,
},
],
} );

result = await session.prompt( `"""${ content }"""` );
} catch ( e ) {
// eslint-disable-next-line no-alert
Expand Down

0 comments on commit 93d2a54

Please sign in to comment.