Skip to content
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

✨ feat(api.ts): add support for Azure OpenAI API #167

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
🔧 fix(AzureOpenAI.ts): import RequiredError to fix error handling and…
… remove commented out debug code

The RequiredError class was not being imported from the openai/dist/base module, causing errors to be thrown incorrectly. This has been fixed by importing the RequiredError class. Debug code has been removed and comments have been updated to reflect the changes made.
  • Loading branch information
takuya-o committed May 7, 2023
commit a78d61d40b29e52d95d63097f586835dd9e56793
22 changes: 6 additions & 16 deletions src/utils/AzureOpenAI.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import {
CreateChatCompletionRequest,
Configuration,
} from "openai";
import { BaseAPI } from 'openai/dist/base';
import { BaseAPI, RequiredError } from 'openai/dist/base';
import { AxiosRequestConfig} from 'openai/node_modules/axios';

export class AzureOpenAIApi extends BaseAPI {
@@ -27,16 +27,16 @@ export class AzureOpenAIApi extends BaseAPI {
*/
public async createChatCompletion(createChatCompletionRequest: CreateChatCompletionRequest, options?: AxiosRequestConfig) {
if (!this.configuration) {
throw new Error('Required parameter configuration was null or undefined when calling createChatCompletion.');
throw new RequiredError('configuration', 'Required configuration was null or undefined when calling createChatCompletion.');
}
if (!this.configuration.basePath) {
throw new Error('Required parameter basePath was null or undefined when calling createChatCompletion.');
throw new RequiredError('basePath', 'Required configuration basePath was null or undefined when calling createChatCompletion.');
}
if (!this.configuration.apiKey) {
throw new Error('Required parameter apiKey was null or undefined when calling createChatCompletion.');
throw new RequiredError('apiKey', 'Required configuration apiKey was null or undefined when calling createChatCompletion.');
}
if (typeof this.configuration.apiKey !== 'string') {
throw new Error('Required parameter apiKey was of type string when calling createChatCompletion.');
throw new RequiredError('apiKey', 'Required configuration apiKey was not string when calling createChatCompletion');
}

const url = this.configuration.basePath + 'openai/deployments/' + createChatCompletionRequest.model + '/chat/completions';
@@ -53,17 +53,7 @@ export class AzureOpenAIApi extends BaseAPI {
...options.params,
}

// axios DEBUG
// this.axios.interceptors.request.use(request => {
// console.log('Starting Request: ', request)
// return request
// })
// this.axios.interceptors.response.use(response => {
// console.log('Response: ', response)
// return response
// })

// Azure OpenAI APIのREST呼び出し
// Azure OpenAI APIのREST call
const response = await this.axios.post(url, createChatCompletionRequest, options);

// console.log(response.data.usage);