Skip to content

Commit

Permalink
Update load-and-vectorize-data.js
Browse files Browse the repository at this point in the history
Code broke with the latest version of the OpenAI libraries, fixed code to use new library
  • Loading branch information
MScalopez authored Oct 14, 2024
1 parent 47283dd commit 0fbb87b
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions 04-vector-search/node.js/load-and-vectorize-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const rl = readline.createInterface({
});
const dotenv = require('dotenv');
const MongoClient = require('mongodb').MongoClient;
const { OpenAIClient, AzureKeyCredential } = require("@azure/openai");
const { AzureOpenAI } = require("openai");
const apiVersion = "2024-07-01-preview";

// Load environment variables
dotenv.config({ path: '../.env' });
Expand Down Expand Up @@ -39,10 +40,7 @@ async function main() {
const completion_deployment = process.env.OpenAICompletionDeploymentName;

// Initialize Azure OpenAI client
const AzureOpenAIClient = new OpenAIClient(
ai_endpoint,
new AzureKeyCredential(ai_key)
);
const azureOpenAIClient = new AzureOpenAI({endpoint: ai_endpoint, apiKey: ai_key, apiVersion: apiVersion});

// Replace placeholders in the connection string with actual values
cosmosdb_connection_string = cosmosdb_connection_string.replace("<user>", encodeURIComponent(cosmos_mongo_user));
Expand Down Expand Up @@ -109,4 +107,4 @@ async function main() {
}

// Run the main function
main();
main();

0 comments on commit 0fbb87b

Please sign in to comment.