Update makersuite-vectors.js to use Gemini API text-embedding-004 model

4acd7296118aafd2e02ea966d68cd604fdb6447a

ceruleandeep <83318388+ceruleandeep@users.noreply.github.com>

Signed
1 files changed, +18 -12Showing whitespace changes
src/vectors/makersuite-vectors.js+18 -12
@@ -1,5 +1,6 @@
11const fetch = require('node-fetch').default;
22const { SECRET_KEYS, readSecret } = require('../endpoints/secrets');
3+const API_MAKERSUITE = 'https://generativelanguage.googleapis.com';
34
45/**
56 * Gets the vector for the given text from gecko model
@@ -9,12 +10,11 @@ const { SECRET_KEYS, readSecret } = require('../endpoints/secrets');
910 */
1011async function getMakerSuiteBatchVector(texts, directories) {
1112 const promises = texts.map(text => getMakerSuiteVector(text, directories));
1213 const vectors =return await Promise.all(promises);
13- return vectors;
1414}
1515
1616/**
1717 * Gets the vector for the given text from PaLMGemini geckoAPI text-embedding-004 model
1818 * @param {string} text - The text to get the vector for
1919 * @param {import('../users').UserDirectoryList} directories - The directories object for the user
2020 * @returns {Promise<number[]>} - The vector for the text
@@ -27,14 +27,23 @@ async function getMakerSuiteVector(text, directories) {
2727 throw new Error('No Google AI Studio key found');
2828 }
2929
30- const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/embedding-gecko-001:embedText?key=${key}`, {
30+ const apiUrl = new URL(API_MAKERSUITE);
31+ const model = 'text-embedding-004';
32+ const url = `${apiUrl.origin}/v1beta/models/${model}:embedContent?key=${key}`;
33+ const body = {
34+ content: {
35+ parts: [
36+ { text: text },
37+ ],
38+ },
39+ };
40+
41+ const response = await fetch(url, {
42+ body: JSON.stringify(body),
3143 method: 'POST',
3244 headers: {
3345 'Content-Type': 'application/json',
3446 },
35- body: JSON.stringify({
36- text: text,
37- }),
3847 });
3948
4049 if (!response.ok) {
@@ -44,11 +53,8 @@ async function getMakerSuiteVector(text, directories) {
4453 }
4554
4655 const data = await response.json();
47-
56+ // noinspection JSValidateTypes
48- // Access the "value" dictionary
57+ return data['embedding']['values'];
49- const vector = data.embedding.value;
50-
51- return vector;
5258}
5359
5460module.exports = {