Skip to content

Commit

Permalink
Added chatgpt model in .env
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin-Umali committed Mar 13, 2024
1 parent f458616 commit 1586644
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions server/.env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
PORT=3000 # 8080 if deploying in fly.io
NODE_ENV="development | production | test"
OPENAI_API_KEY="<your_openai_secret_key>"
OPENAI_CHATGPT_MODEL="<your_openai_chatgpt_model>"
WEBSITE_URL="<your_front_end_url>"
UNSPLASH_ACCESS_KEY="<your_unpslash_access_key>"
UNSPLASH_SECRET_KEY="<your_unpslash_secret_key>"
Expand Down
4 changes: 2 additions & 2 deletions server/src/controllers/openai.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const generateIdea = async (req: BodyRequest<IdeaRequest>, res: Response,
`;

const completion = await openai.chat.completions.create({
model: "gpt-3.5-turbo-0613",
model: process.env.OPENAI_CHATGPT_MODEL,
response_format: {
type: "json_object",
},
Expand Down Expand Up @@ -109,7 +109,7 @@ export const explainProjectByTitle = async (req: BodyRequest<ExplainRequest>, re
`;

const completion = await openai.chat.completions.create({
model: "gpt-3.5-turbo-0613",
model: process.env.OPENAI_CHATGPT_MODEL,
messages: [
{
role: "system",
Expand Down
28 changes: 28 additions & 0 deletions server/src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,33 @@ const environmentSchema = z.object({
PORT: z.number().default(3000),
NODE_ENV: z.enum(["development", "production", "test"]).default("development"),
OPENAI_API_KEY: z.string(),
OPENAI_CHATGPT_MODEL: z
.enum([
"gpt-3.5-turbo-0125",
"gpt-3.5-turbo",
"gpt-3.5-turbo-1106",
"gpt-3.5-turbo-instruct",
"gpt-3.5-turbo-16k",
"gpt-3.5-turbo-0613",
"gpt-3.5-turbo-16k-0613",
"gpt-4-0125-preview",
"gpt-4-turbo-preview",
"gpt-4-1106-preview",
"gpt-4-vision-preview",
"gpt-4-1106-vision-preview",
"gpt-4",
"gpt-4-0613",
"gpt-4-32k",
"gpt-4-32k-0613",
])
.refine((value) => {
if (["gpt-3.5-turbo-16k", "gpt-3.5-turbo-0613", "gpt-3.5-turbo-16k-0613"].includes(value)) {
console.warn(`WARNING: ${value} is a legacy model and will be deprecated on June 13, 2024.`);
}

return true;
})
.default("gpt-3.5-turbo-0613"),
WEBSITE_URL: z.string(),
UNSPLASH_ACCESS_KEY: z.string(),
UNSPLASH_SECRET_KEY: z.string(),
Expand Down Expand Up @@ -34,6 +61,7 @@ const env = {
PORT: process.env.PORT ? Number(process.env.PORT) : 3000,
NODE_ENV: process.env.NODE_ENV,
OPENAI_API_KEY: process.env.OPENAI_API_KEY,
OPENAI_CHATGPT_MODEL: process.env.OPENAI_CHATGPT_MODEL,
WEBSITE_URL: process.env.WEBSITE_URL,
UNSPLASH_ACCESS_KEY: process.env.UNSPLASH_ACCESS_KEY,
UNSPLASH_SECRET_KEY: process.env.UNSPLASH_SECRET_KEY,
Expand Down

0 comments on commit 1586644

Please sign in to comment.