Skip to content

Commit

Permalink
refactor: extract constants
Browse files Browse the repository at this point in the history
  • Loading branch information
sinedied authored and anfibiacreativa committed Sep 1, 2023
1 parent 18fe2b4 commit 7b20ef4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/api/src/plugins/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export type OpenAiClients = {
getEmbeddings(): Promise<Embeddings>;
};

const AZURE_OPENAI_API_VERSION = '2023-05-15';
const AZURE_COGNITIVE_SERVICES_AD_SCOPE = 'https://cognitiveservices.azure.com/.default';

export default fp(
async (fastify, opts) => {
const config = fastify.config;
Expand All @@ -21,11 +24,11 @@ export default fp(

const refreshOpenAiToken = async () => {
if (!openAiToken || openAiToken.expiresOnTimestamp < Date.now() + 60 * 1000) {
openAiToken = await fastify.azure.credential.getToken('https://cognitiveservices.azure.com/.default');
openAiToken = await fastify.azure.credential.getToken(AZURE_COGNITIVE_SERVICES_AD_SCOPE);

const commonOptions = {
apiKey: openAiToken.token,
defaultQuery: { 'api-version': '2023-05-15' },
defaultQuery: { 'api-version': AZURE_OPENAI_API_VERSION },
defaultHeaders: { 'api-key': openAiToken.token },
};

Expand Down

0 comments on commit 7b20ef4

Please sign in to comment.