-
Notifications
You must be signed in to change notification settings - Fork 183
feat: add azure model provider #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
858e9a9
feat: add azure model provider
thucpn 62eea2a
refactor: remove unused model infor
thucpn dc438a9
fix: lint
thucpn 25b355b
fix: use correct env for python azure
thucpn 09b0460
Create smooth-points-float.md
thucpn 7b98865
fix: type azure-openai
thucpn 32fc88f
fix: seperate llm and embedding deployment env
thucpn 3026e32
fix: apply version and endpoint to python azure
thucpn d31fee4
feat: map azure model to openai model in ts
thucpn 233b8e0
fix: rename to azure-openai
thucpn 9050e19
fix: keep gpt-4o-mini
thucpn df91d48
fix: lint
thucpn f9208d2
fix: azure model configured always false
thucpn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-llama": patch | ||
--- | ||
|
||
Add azure model provider |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import ciInfo from "ci-info"; | ||
import prompts from "prompts"; | ||
import { ModelConfigParams, ModelConfigQuestionsParams } from "."; | ||
import { questionHandlers } from "../../questions"; | ||
|
||
const ALL_AZURE_OPENAI_CHAT_MODELS: Record<string, { openAIModel: string }> = { | ||
"gpt-35-turbo": { openAIModel: "gpt-3.5-turbo" }, | ||
"gpt-35-turbo-16k": { | ||
openAIModel: "gpt-3.5-turbo-16k", | ||
}, | ||
"gpt-4o": { openAIModel: "gpt-4o" }, | ||
"gpt-4": { openAIModel: "gpt-4" }, | ||
"gpt-4-32k": { openAIModel: "gpt-4-32k" }, | ||
"gpt-4-turbo": { | ||
openAIModel: "gpt-4-turbo", | ||
}, | ||
"gpt-4-turbo-2024-04-09": { | ||
openAIModel: "gpt-4-turbo", | ||
}, | ||
"gpt-4-vision-preview": { | ||
openAIModel: "gpt-4-vision-preview", | ||
}, | ||
"gpt-4-1106-preview": { | ||
openAIModel: "gpt-4-1106-preview", | ||
}, | ||
"gpt-4o-2024-05-13": { | ||
openAIModel: "gpt-4o-2024-05-13", | ||
}, | ||
}; | ||
|
||
const ALL_AZURE_OPENAI_EMBEDDING_MODELS: Record< | ||
string, | ||
{ | ||
dimensions: number; | ||
openAIModel: string; | ||
} | ||
> = { | ||
"text-embedding-ada-002": { | ||
dimensions: 1536, | ||
openAIModel: "text-embedding-ada-002", | ||
}, | ||
"text-embedding-3-small": { | ||
dimensions: 1536, | ||
openAIModel: "text-embedding-3-small", | ||
}, | ||
"text-embedding-3-large": { | ||
dimensions: 3072, | ||
openAIModel: "text-embedding-3-large", | ||
}, | ||
}; | ||
|
||
const DEFAULT_MODEL = "gpt-4o"; | ||
const DEFAULT_EMBEDDING_MODEL = "text-embedding-3-large"; | ||
|
||
export async function askAzureQuestions({ | ||
openAiKey, | ||
askModels, | ||
}: ModelConfigQuestionsParams): Promise<ModelConfigParams> { | ||
const config: ModelConfigParams = { | ||
apiKey: openAiKey, | ||
model: DEFAULT_MODEL, | ||
embeddingModel: DEFAULT_EMBEDDING_MODEL, | ||
dimensions: getDimensions(DEFAULT_EMBEDDING_MODEL), | ||
isConfigured(): boolean { | ||
// the Azure model provider can't be fully configured as endpoint and deployment names have to be configured with env variables | ||
return false; | ||
}, | ||
}; | ||
|
||
if (!config.apiKey) { | ||
const { key } = await prompts( | ||
{ | ||
type: "text", | ||
name: "key", | ||
message: askModels | ||
? "Please provide your Azure OpenAI API key (or leave blank to use AZURE_OPENAI_KEY env variable):" | ||
: "Please provide your Azure OpenAI API key (leave blank to skip):", | ||
validate: (value: string) => { | ||
if (askModels && !value) { | ||
if (process.env.AZURE_OPENAI_KEY) { | ||
return true; | ||
} | ||
return "AZURE_OPENAI_KEY env variable is not set - key is required"; | ||
} | ||
return true; | ||
}, | ||
}, | ||
questionHandlers, | ||
); | ||
config.apiKey = key || process.env.AZURE_OPENAI_KEY; | ||
} | ||
|
||
// use default model values in CI or if user should not be asked | ||
const useDefaults = ciInfo.isCI || !askModels; | ||
if (!useDefaults) { | ||
const { model } = await prompts( | ||
{ | ||
type: "select", | ||
name: "model", | ||
message: "Which LLM model would you like to use?", | ||
choices: getAvailableModelChoices(), | ||
initial: 0, | ||
}, | ||
questionHandlers, | ||
); | ||
config.model = model; | ||
|
||
const { embeddingModel } = await prompts( | ||
{ | ||
type: "select", | ||
name: "embeddingModel", | ||
message: "Which embedding model would you like to use?", | ||
choices: getAvailableEmbeddingModelChoices(), | ||
initial: 0, | ||
}, | ||
questionHandlers, | ||
); | ||
config.embeddingModel = embeddingModel; | ||
config.dimensions = getDimensions(embeddingModel); | ||
} | ||
|
||
return config; | ||
} | ||
|
||
function getAvailableModelChoices() { | ||
return Object.keys(ALL_AZURE_OPENAI_CHAT_MODELS).map((key) => ({ | ||
title: key, | ||
value: key, | ||
})); | ||
} | ||
|
||
function getAvailableEmbeddingModelChoices() { | ||
return Object.keys(ALL_AZURE_OPENAI_EMBEDDING_MODELS).map((key) => ({ | ||
title: key, | ||
value: key, | ||
})); | ||
} | ||
|
||
function getDimensions(modelName: string) { | ||
return ALL_AZURE_OPENAI_EMBEDDING_MODELS[modelName].dimensions; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.