Add support for GPT models in Azure AI Studio

This commit is contained in:
Zgrill2 2025-02-06 00:20:52 -05:00
parent 32d0462c5d
commit 18300a8f13
3 changed files with 43 additions and 0 deletions

15
profiles/azure.json Normal file
View file

@ -0,0 +1,15 @@
{
"name": "azure",
"model": {
"api": "azure",
"url": "",
"model": "gpt-4o",
"api_version": "2024-08-01-preview"
},
"embedding": {
"api": "azure",
"url": "",
"model": "text-embedding-ada-002",
"api_version": "2024-08-01-preview"
}
}

23
src/models/azure.js Normal file
View file

@ -0,0 +1,23 @@
import { AzureOpenAI } from "openai";
import { getKey } from '../utils/keys.js';
import { GPT } from './gpt.js'
export class AzureGPT extends GPT {
constructor(model_name, url, api_version, params) {
super(model_name, url)
this.model_name = model_name;
this.params = params;
let 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
this.openai = new AzureOpenAI(config)
}
}

View file

@ -19,6 +19,7 @@ import { HuggingFace } from './huggingface.js';
import { Qwen } from "./qwen.js"; import { Qwen } from "./qwen.js";
import { Grok } from "./grok.js"; import { Grok } from "./grok.js";
import { DeepSeek } from './deepseek.js'; import { DeepSeek } from './deepseek.js';
import { AzureGPT } from './azure.js';
export class Prompter { export class Prompter {
constructor(agent, fp) { constructor(agent, fp) {
@ -72,6 +73,8 @@ export class Prompter {
this.embedding_model = new Gemini(embedding.model, embedding.url); this.embedding_model = new Gemini(embedding.model, embedding.url);
else if (embedding.api === 'openai') else if (embedding.api === 'openai')
this.embedding_model = new GPT(embedding.model, embedding.url); this.embedding_model = new GPT(embedding.model, embedding.url);
else if (embedding.api === 'azure')
this.embedding_model = new AzureGPT(embedding.model, embedding.url, embedding.api_version);
else if (embedding.api === 'replicate') else if (embedding.api === 'replicate')
this.embedding_model = new ReplicateAPI(embedding.model, embedding.url); this.embedding_model = new ReplicateAPI(embedding.model, embedding.url);
else if (embedding.api === 'ollama') else if (embedding.api === 'ollama')
@ -139,6 +142,8 @@ export class Prompter {
model = new Gemini(profile.model, profile.url, profile.params); model = new Gemini(profile.model, profile.url, profile.params);
else if (profile.api === 'openai') else if (profile.api === 'openai')
model = new GPT(profile.model, profile.url, profile.params); model = new GPT(profile.model, profile.url, profile.params);
else if (profile.api === 'azure')
model = new AzureGPT(profile.model, profile.url, profile.api_version, profile.params);
else if (profile.api === 'anthropic') else if (profile.api === 'anthropic')
model = new Claude(profile.model, profile.url, profile.params); model = new Claude(profile.model, profile.url, profile.params);
else if (profile.api === 'replicate') else if (profile.api === 'replicate')