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

Staging into Main #259

Merged
merged 6 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ VERCEL_DEPLOY_HOOK_URL=

OPENAI_TIMEOUT=
OPENAI_API_KEY=
OPENAI_BASE_URL=
OPENAI_COMPLETION_MODEL=
OPENAI_COMPLETION_TEMPERATURE=
OPENAI_COMPLETION_MAX_TOKENS=
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 4.6.0 (2023-05-03)

### New Features

- Support `gpt-4` model

## 4.5.0 (2023-04-27)

### New Features
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ GPT AI Assistant is an application that is implemented using the OpenAI API and

## News

- 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:
- 2023-05-03: The `4.6` version now support `gpt-4` OpenAI model. :fire:
- 2023-03-05: The `4.1` version now support the audio message of LINE and `whisper-1` OpenAI model. :fire:
- 2023-03-02: The `4.0` version now support `gpt-3.5-turbo` OpenAI model. :fire:

## Documentations

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 package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gpt-ai-assistant",
"version": "4.5.0",
"version": "4.6.0",
"type": "module",
"scripts": {
"dev": "nodemon api/index.js",
Expand Down
3 changes: 2 additions & 1 deletion services/openai.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ 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_4 = '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
11 changes: 7 additions & 4 deletions utils/generate-completion.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
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,
} from '../services/openai.js';
import { createChatCompletion, createTextCompletion, FINISH_REASON_STOP } from '../services/openai.js';

class Completion {
text;
Expand All @@ -22,6 +20,11 @@ class Completion {
}
}

const isChatCompletionModel = (model) => (
String(model).startsWith('gpt-4')
|| String(model).startsWith('gpt-3.5')
);

/**
* @param {Object} param
* @param {Prompt} param.prompt
Expand All @@ -31,7 +34,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 (isChatCompletionModel(config.OPENAI_COMPLETION_MODEL)) {
const { data } = await createChatCompletion({ messages: prompt.messages });
const [choice] = data.choices;
return new Completion({
Expand Down