Skip to content

Commit

Permalink
Merge pull request #257 from myh-st/main
Browse files Browse the repository at this point in the history
Support Azure OpenAI API
  • Loading branch information
memochou1993 authored May 3, 2023
2 parents ec61054 + 51143de commit e9e593a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
GPT AI Assistant is an application that is implemented using the OpenAI API and LINE Messaging API. Through the installation process, you can start chatting with your own AI assistant using the LINE mobile app.

## News

- 2023-04-27: Support Azure OpenAi service with Cloudflare worker script to proxy OpenAI‘s request to Azure OpenAI Service https://github.com/haibbo/cf-openai-azure-proxy
deploy your proxy and then add "OPENAI_BASE_URL= " to .env to pass cf proxy to gpt-ai-assistant tested with model gpt-4
- 2023-03-05: The `4.1` version now support the audio message of LINE and `whisper-1` language model of OpenAI. :fire:
- 2023-03-02: The `4.0` version now support `gpt-3.5-turbo` language model of OpenAI. :fire:

Expand Down
1 change: 1 addition & 0 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const config = Object.freeze({
VERCEL_DEPLOY_HOOK_URL: env.VERCEL_DEPLOY_HOOK_URL || null,
OPENAI_TIMEOUT: env.OPENAI_TIMEOUT || env.APP_API_TIMEOUT,
OPENAI_API_KEY: env.OPENAI_API_KEY || null,
OPENAI_BASE_URL: env.OPENAI_BASE_URL || 'https://api.openai.com',
OPENAI_COMPLETION_MODEL: env.OPENAI_COMPLETION_MODEL || 'gpt-3.5-turbo',
OPENAI_COMPLETION_TEMPERATURE: Number(env.OPENAI_COMPLETION_TEMPERATURE) || 0.9,
OPENAI_COMPLETION_MAX_TOKENS: Number(env.OPENAI_COMPLETION_MAX_TOKENS) || 160,
Expand Down
4 changes: 2 additions & 2 deletions services/openai.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ export const IMAGE_SIZE_256 = '256x256';
export const IMAGE_SIZE_512 = '512x512';
export const IMAGE_SIZE_1024 = '1024x1024';

export const MODEL_GPT_3_5_TURBO = 'gpt-3.5-turbo';
export const MODEL_GPT = 'gpt-4';
export const MODEL_WHISPER_1 = 'whisper-1';

const client = axios.create({
baseURL: 'https://api.openai.com',
baseURL: config.OPENAI_BASE_URL,
timeout: config.OPENAI_TIMEOUT,
headers: {
'Accept-Encoding': 'gzip, deflate, compress',
Expand Down
4 changes: 2 additions & 2 deletions utils/generate-completion.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import config from '../config/index.js';
import { MOCK_TEXT_OK } from '../constants/mock.js';
import {
createChatCompletion, createTextCompletion, FINISH_REASON_STOP, MODEL_GPT_3_5_TURBO,
createChatCompletion, createTextCompletion, FINISH_REASON_STOP, MODEL_GPT,
} from '../services/openai.js';

class Completion {
Expand Down Expand Up @@ -31,7 +31,7 @@ const generateCompletion = async ({
prompt,
}) => {
if (config.APP_ENV !== 'production') return new Completion({ text: MOCK_TEXT_OK });
if (config.OPENAI_COMPLETION_MODEL.includes(MODEL_GPT_3_5_TURBO)) {
if (config.OPENAI_COMPLETION_MODEL.includes(MODEL_GPT)) {
const { data } = await createChatCompletion({ messages: prompt.messages });
const [choice] = data.choices;
return new Completion({
Expand Down

0 comments on commit e9e593a

Please sign in to comment.