-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functionality to query user input based on code blocks, send rele…
…vant files to ChatGPT API
- Loading branch information
Showing
8 changed files
with
333 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const openai = require('../config/openaiConfig'); | ||
|
||
// Function to generate embeddings using OpenAI's API | ||
async function generateEmbeddings(text) { | ||
/* // Initialize OpenAI client | ||
const openai = new OpenAI({ | ||
apiKey: process.env.OPENAI_API_KEY, // Ensure your API key is set in the environment variables | ||
}); */ | ||
|
||
try { | ||
// Flatten the tokens into a format suitable for OpenAI | ||
// const text = tokens.map(token => JSON.stringify(token)).join('\n'); | ||
|
||
// Request embeddings | ||
const response = await openai.embeddings.create({ | ||
model: 'text-embedding-ada-002', // Use an appropriate embedding model | ||
input: text, | ||
encoding_format: 'float' | ||
}); | ||
|
||
/* console.log('Embedding Dimension: ', response.data[0].embedding.length); | ||
console.log('OpenAI embeddings response:', response.data); */ | ||
// return response.data | ||
return response.data[0].embedding; | ||
|
||
} catch (error) { | ||
console.error('Error generating embeddings with OpenAI:', error); | ||
} | ||
} | ||
|
||
// Main function to process and update the dictionary | ||
async function processAndUpdateDictionary(dict) { | ||
for (const func of dict.functions) { | ||
const embedding = await generateEmbeddings(func.code); | ||
if (embedding) { | ||
func.embedding = embedding; | ||
} | ||
} | ||
|
||
for (const cls of dict.classes) { | ||
const embedding = await generateEmbeddings(cls.code); | ||
if (embedding) { | ||
cls.embedding = embedding; | ||
} | ||
} | ||
|
||
// console.log('Updated dictionary with embeddings:', JSON.stringify(dict, null, 2)) | ||
// console.log(dict); | ||
|
||
|
||
|
||
return dict; | ||
} | ||
|
||
module.exports = {processAndUpdateDictionary, generateEmbeddings}; |
Oops, something went wrong.