Skip to content

Commit

Permalink
Revert "Disable managed identity for now"
Browse files Browse the repository at this point in the history
This reverts commit 9b98534.
  • Loading branch information
andychase committed Sep 30, 2024
1 parent edeee5e commit 3822f78
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 25 deletions.
4 changes: 0 additions & 4 deletions .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,3 @@ OPENAI_API_KEY=YOUR_KEY
# Google
GOOGLE_API_KEY=YOUR_API_KEY
GOOGLE_CSE_ID=YOUR_ENGINE_ID



AZURE_USE_MANAGED_IDENTITY=false
18 changes: 9 additions & 9 deletions instrumentation.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// import * as Sentry from '@sentry/nextjs';
import * as Sentry from '@sentry/nextjs';

// export async function register() {
// if (process.env.NEXT_RUNTIME === 'nodejs') {
// await import('./sentry.server.config');
// }
export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
await import('./sentry.server.config');
}

// if (process.env.NEXT_RUNTIME === 'edge') {
// await import('./sentry.edge.config');
// }
// }
if (process.env.NEXT_RUNTIME === 'edge') {
await import('./sentry.edge.config');
}
}

// export const onRequestError = Sentry.captureRequestError;
export {}
2 changes: 1 addition & 1 deletion pages/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const handler = async (req: Request): Promise<Response> => {
...(OPENAI_API_TYPE === 'openai' && {
Authorization: `Bearer ${key ? key : process.env.OPENAI_API_KEY}`
}),
...(OPENAI_API_TYPE === 'azure' && process.env.AZURE_USE_MANAGED_IDENTITY!="true" && {
...(OPENAI_API_TYPE === 'azure' && process.env.AZURE_USE_MANAGED_IDENTITY=="false" && {
'api-key': `${key ? key : process.env.OPENAI_API_KEY}`
}),
...(OPENAI_API_TYPE === 'azure' && process.env.AZURE_USE_MANAGED_IDENTITY=="true" && {
Expand Down
12 changes: 2 additions & 10 deletions utils/lib/azure.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
// lib/azure.js

//import { DefaultAzureCredential } from "@azure/identity";
//import { log } from "console";
import { DefaultAzureCredential } from "@azure/identity";
//import { getCache, setCache } from "./cache";



export async function getAuthToken() {
if (process.env.AZURE_USE_MANAGED_IDENTITY != "true") {
return "";
}
let cachedToken = process.env.AUTH_TOKEN ? JSON.parse(process.env.AUTH_TOKEN) : '';
if (!cachedToken || cachedToken.expiresOnTimestamp < Date.now()) {
let cachedCredential = new DefaultAzureCredential();
cachedToken = await cachedCredential.getToken("https://cognitiveservices.azure.com/.default");
//setCache("cachedToken", JSON.stringify(cachedToken));
//console.log("set the cachedToken in cache");
//let a = JSON.parse(getCache("cachedToken"));
//console.log("cachedToken from memory", a);
process.env.AUTH_TOKEN = JSON.stringify(cachedToken);
return cachedToken;
}
console.log("cachedToken from memory", cachedToken);
// console.log("cachedToken from memory", cachedToken);
return process.env.AUTH_TOKEN ? JSON.parse(process.env.AUTH_TOKEN) : '';;
}

2 changes: 1 addition & 1 deletion utils/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const OpenAIStream = async (
...(OPENAI_API_TYPE === 'openai' && {
Authorization: `Bearer ${key ? key : process.env.OPENAI_API_KEY}`
}),
...(OPENAI_API_TYPE === 'azure' && process.env.AZURE_USE_MANAGED_IDENTITY!="true" && {
...(OPENAI_API_TYPE === 'azure' && process.env.AZURE_USE_MANAGED_IDENTITY=="false" && {
'api-key': `${key ? key : process.env.OPENAI_API_KEY}`
}),
...(OPENAI_API_TYPE === 'azure' && process.env.AZURE_USE_MANAGED_IDENTITY=="true" && {
Expand Down

0 comments on commit 3822f78

Please sign in to comment.