diff --git a/profiles/azure.json b/profiles/azure.json index fbd382d..29b1122 100644 --- a/profiles/azure.json +++ b/profiles/azure.json @@ -2,14 +2,18 @@ "name": "azure", "model": { "api": "azure", - "url": "", - "model": "gpt-4o", - "api_version": "2024-08-01-preview" + "url": "https://.openai.azure.com", + "model": "", + "params": { + "apiVersion": "2024-08-01-preview" + } }, "embedding": { "api": "azure", - "url": "", - "model": "text-embedding-ada-002", - "api_version": "2024-08-01-preview" + "url": "https://.openai.azure.com", + "model": "", + "params": { + "apiVersion": "2024-08-01-preview" + } } -} \ No newline at end of file + } \ No newline at end of file diff --git a/src/models/azure.js b/src/models/azure.js index d8e2f4a..b6be3e0 100644 --- a/src/models/azure.js +++ b/src/models/azure.js @@ -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) }