-
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 the codebase using Pinecone based on the u…
…ser query
- Loading branch information
Showing
15 changed files
with
355 additions
and
289 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 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
58 changes: 27 additions & 31 deletions
58
server/database/EmbeddingService.js → .../config/pineconeConfig/embeddingConfig.js
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 |
---|---|---|
@@ -1,31 +1,27 @@ | ||
const { OpenAI } = require('openai'); | ||
require('dotenv').config() | ||
// Function to generate embeddings using OpenAI's API | ||
async function generateEmbeddings(tokens) { | ||
// 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 | ||
|
||
|
||
} catch (error) { | ||
console.error('Error generating embeddings with OpenAI:', error); | ||
} | ||
} | ||
|
||
module.exports = generateEmbeddings; | ||
const openai = require('../openaiConfig') | ||
require('dotenv').config(); | ||
|
||
// Function to generate embeddings using OpenAI's API | ||
async function generateEmbeddings(tokens) { | ||
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; | ||
|
||
|
||
} catch (error) { | ||
console.error('Error generating embeddings with OpenAI:', error); | ||
} | ||
} | ||
|
||
module.exports = generateEmbeddings; |
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,5 @@ | ||
const PineconeManager = require('../pineconeConfig/pineconeManager'); | ||
|
||
const pinecone = new PineconeManager(process.env.PINECONE_API_KEY, "syntaxsorcerer"); | ||
|
||
module.exports = pinecone; |
Oops, something went wrong.