Skip to content
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
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ node_modules

/.cache
/build
.env
.env
18 changes: 14 additions & 4 deletions app/routes/_index/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,19 @@ import { initParticlesEngine, Particles } from '@tsparticles/react';
import { DESKTOP_OPTIONS, MOBILE_OPTIONS } from './tsparticlesPresets';
import { MAIN_PAGE_DESCRIPTION, MAIN_PAGE_TITLE } from '~/constants/metadata';

const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
let openaiClient: OpenAI | null = null;

const getOpenAI = () => {
if (!process.env.OPENAI_API_KEY) {
throw new Error('OPENAI_API_KEY environment variable is not set');
}
if (!openaiClient) {
openaiClient = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
}
return openaiClient;
};

export type Message = {
role: 'user' | 'llm';
Expand All @@ -50,7 +60,7 @@ export const action = async ({
}

const initialTimestamp = new Date().getTime();
const completion = await openai.chat.completions.create({
const completion = await getOpenAI().chat.completions.create({
messages: [
{ role: 'system', content: wrapWithPrompt(userInput.toString()) },
],
Expand Down
18 changes: 14 additions & 4 deletions app/routes/chat/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ import { HomeIcon } from './homeIcon';
import { log } from '~/utils/logging';
import { MAIN_PAGE_TITLE } from '~/constants/metadata';

const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
let openaiClient: OpenAI | null = null;

const getOpenAI = () => {
if (!process.env.OPENAI_API_KEY) {
throw new Error('OPENAI_API_KEY environment variable is not set');
}
if (!openaiClient) {
openaiClient = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
}
return openaiClient;
};

export type Message = {
role: 'user' | 'llm';
Expand Down Expand Up @@ -43,7 +53,7 @@ export const action = async ({
userInput.toString()
);

const completion = await openai.chat.completions.create({
const completion = await getOpenAI().chat.completions.create({
messages: [
{ role: 'system', content: wrapWithPrompt(userInput.toString()) },
],
Expand Down
11 changes: 8 additions & 3 deletions app/utils/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ import chalk from 'chalk';

type LogType = 'log' | 'info' | 'warn' | 'error';

if (!process.env.VITEST && !process.env.CI)
if (
!process.env.VITEST &&
!process.env.CI &&
process.env.LOGGLY_TOKEN &&
process.env.LOGGLY_SUBDOMAIN
)
winston.add(
new Loggly({
token: process.env.LOGGLY_TOKEN!,
subdomain: process.env.LOGGLY_SUBDOMAIN!,
token: process.env.LOGGLY_TOKEN,
subdomain: process.env.LOGGLY_SUBDOMAIN,
tags: ['justinfarrell'],
})
);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"dependencies": {
"@heroicons/react": "^2.1.3",
"@react-router/node": "^7.10.1",
"@react-router/serve": "^7.10.1",
"@tsparticles/react": "^3.0.0",
"chalk": "^5.3.0",
"dompurify": "^3.1.2",
Expand Down
Loading