clean up azure

This commit is contained in:
MaxRobinsonTheGreat 2025-08-23 16:00:59 -05:00
parent f41f03cdb3
commit 1588a8770b
2 changed files with 27 additions and 14 deletions

View file

@ -2,14 +2,18 @@
"name": "azure", "name": "azure",
"model": { "model": {
"api": "azure", "api": "azure",
"url": "", "url": "https://<your-resource>.openai.azure.com",
"model": "gpt-4o", "model": "<chat-deployment-name>",
"api_version": "2024-08-01-preview" "params": {
"apiVersion": "2024-08-01-preview"
}
}, },
"embedding": { "embedding": {
"api": "azure", "api": "azure",
"url": "", "url": "https://<your-resource>.openai.azure.com",
"model": "text-embedding-ada-002", "model": "<embedding-deployment-name>",
"api_version": "2024-08-01-preview" "params": {
"apiVersion": "2024-08-01-preview"
}
} }
} }

View file

@ -1,22 +1,31 @@
import { AzureOpenAI } from "openai"; import { AzureOpenAI } from "openai";
import { getKey } from '../utils/keys.js'; import { getKey, hasKey } from '../utils/keys.js';
import { GPT } from './gpt.js' import { GPT } from './gpt.js'
export class AzureGPT extends GPT { export class AzureGPT extends GPT {
constructor(model_name, url, api_version, params) { static prefix = 'azure';
constructor(model_name, url, params) {
super(model_name, url) super(model_name, url)
this.model_name = model_name; this.model_name = model_name;
this.params = params; this.params = params || {};
let config = {} const config = {};
if (url) if (url)
config.endpoint = url; config.endpoint = url;
config.apiKey = getKey('OPENAI_API_KEY'); config.apiKey = hasKey('AZURE_OPENAI_API_KEY') ? getKey('AZURE_OPENAI_API_KEY') : getKey('OPENAI_API_KEY');
config.deployment = model_name; // This must be what you named the deployment in Azure, not the model version itself
config.apiVersion = api_version; // This is required for Azure config.deployment = model_name;
if (this.params.apiVersion) {
config.apiVersion = this.params.apiVersion;
delete this.params.apiVersion; // remove from params for later use in requests
}
else {
throw new Error('apiVersion is required in params for azure!');
}
this.openai = new AzureOpenAI(config) this.openai = new AzureOpenAI(config)
} }