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",
"model": {
"api": "azure",
"url": "",
"model": "gpt-4o",
"api_version": "2024-08-01-preview"
"url": "https://<your-resource>.openai.azure.com",
"model": "<chat-deployment-name>",
"params": {
"apiVersion": "2024-08-01-preview"
}
},
"embedding": {
"api": "azure",
"url": "",
"model": "text-embedding-ada-002",
"api_version": "2024-08-01-preview"
"url": "https://<your-resource>.openai.azure.com",
"model": "<embedding-deployment-name>",
"params": {
"apiVersion": "2024-08-01-preview"
}
}
}

View file

@ -1,22 +1,31 @@
import { AzureOpenAI } from "openai";
import { getKey } from '../utils/keys.js';
import { getKey, hasKey } from '../utils/keys.js';
import { GPT } from './gpt.js'
export class AzureGPT extends GPT {
constructor(model_name, url, api_version, params) {
static prefix = 'azure';
constructor(model_name, url, params) {
super(model_name, url)
this.model_name = model_name;
this.params = params;
this.params = params || {};
let config = {}
const config = {};
if (url)
config.endpoint = url;
config.apiKey = 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.apiKey = hasKey('AZURE_OPENAI_API_KEY') ? getKey('AZURE_OPENAI_API_KEY') : getKey('OPENAI_API_KEY');
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)
}