Skip to content

Commit

Permalink
feat: refactor text-only Gemini prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
irataxy committed May 13, 2024
1 parent f25b3c7 commit b0c75cd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
21 changes: 3 additions & 18 deletions generative-ai/snippets/gemini-text-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,10 @@ async function generate_from_text_input(projectId = 'PROJECT_ID') {
model: 'gemini-1.0-pro-002',
});

// Does the returned sentiment score match the reviewer's movie rating?
const textPart = {
text: `
Give a score from 1 - 10 to suggest if the following movie review is
negative or positive (1 is most negative, 10 is most positive, 5 will be
neutral). Include an explanation.
const prompt =
"What's a good name for a flower shop that specializes in selling bouquets of dried flowers?";

The movie takes some time to build, but that is part of its beauty. By the
time you are hooked, this tale of friendship and hope is thrilling and
affecting, until the very last scene. You will find yourself rooting for
the hero every step of the way. This is the sharpest, most original
animated film I have seen in years. I would give it 8 out of 10 stars.`,
};

const request = {
contents: [{role: 'user', parts: [textPart]}],
};

const resp = await generativeModel.generateContent(request);
const resp = await generativeModel.generateContent(prompt);
const contentResponse = await resp.response;
console.log(JSON.stringify(contentResponse));
}
Expand Down
4 changes: 2 additions & 2 deletions generative-ai/snippets/test/gemini-text-input.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const projectId = process.env.CAIP_PROJECT_ID;

describe('Get sentiment score from text input', async () => {
it('should get sentiment score from text input', async () => {
describe('Get store name ideas from text input prompt', async () => {
it('should get store name ideas from text input prompt', async () => {
const output = execSync(`node ./gemini-text-input.js ${projectId}`);

assert(output.length > 0);
Expand Down

0 comments on commit b0c75cd

Please sign in to comment.