Browse Source

Adds custom url support for Open AI models (Azure)

Refs: #2743
main
Eric Amodio 1 year ago
parent
commit
2fd5560b55
3 changed files with 17 additions and 2 deletions
  1. +10
    -0
      package.json
  2. +6
    -2
      src/ai/openaiProvider.ts
  3. +1
    -0
      src/config.ts

+ 10
- 0
package.json View File

@ -2878,6 +2878,16 @@
"scope": "window",
"order": 101
},
"gitlens.ai.experimental.openai.url": {
"type": [
"string",
"null"
],
"default": null,
"markdownDescription": "Specifies a custom URL to use for access to an OpenAI model via Azure. Azure URLs should be in the following format: https://{your-resource-name}.openai.azure.com/openai/deployments/{deployment-id}/chat/completions?api-version={api-version}",
"scope": "window",
"order": 102
},
"gitlens.ai.experimental.anthropic.model": {
"type": "string",
"default": "claude-v1",

+ 6
- 2
src/ai/openaiProvider.ts View File

@ -19,6 +19,10 @@ export class OpenAIProvider implements AIProvider {
dispose() {}
private get url(): string {
return configuration.get('ai.experimental.openai.url') ?? 'https://api.openai.com/v1/chat/completions';
}
async generateCommitMessage(diff: string, options?: { context?: string }): Promise<string | undefined> {
const apiKey = await getApiKey(this.container.storage);
if (apiKey == null) return undefined;
@ -64,7 +68,7 @@ export class OpenAIProvider implements AIProvider {
content: `Write a meaningful commit message for the following code changes:\n\n${code}`,
});
const rsp = await fetch('https://api.openai.com/v1/chat/completions', {
const rsp = await fetch(this.url, {
headers: {
Accept: 'application/json',
Authorization: `Bearer ${apiKey}`,
@ -126,7 +130,7 @@ export class OpenAIProvider implements AIProvider {
],
};
const rsp = await fetch('https://api.openai.com/v1/chat/completions', {
const rsp = await fetch(this.url, {
headers: {
Accept: 'application/json',
Authorization: `Bearer ${apiKey}`,

+ 1
- 0
src/config.ts View File

@ -9,6 +9,7 @@ export interface Config {
provider: 'openai' | 'anthropic';
openai: {
model?: OpenAIModels;
url?: string | null;
};
anthropic: {
model?: AnthropicModels;

Loading…
Cancel
Save