Skip to content

Commit

Permalink
fix: remove console log and dotnet
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestocarocca committed Dec 5, 2024
1 parent 8a4ca5a commit 6ec487e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"dependencies": {
"@fastify/cors": "^8.2.0",
"@fastify/env": "^5.0.1",
"@fastify/static": "^7.0.4",
"@fastify/swagger": "^8.3.1",
"@fastify/swagger-ui": "^1.5.0",
Expand All @@ -31,6 +32,7 @@
"@tabler/icons-react": "^3.19.0",
"dotenv": "^16.4.6",
"fastify": "4.23.2",
"fastify-env": "^2.1.1",
"next": "^14.2.15",
"nodemon": "^2.0.20",
"openai": "^4.74.0",
Expand Down
11 changes: 2 additions & 9 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox';
import { Static, Type } from '@sinclair/typebox';
import { FastifyPluginCallback } from 'fastify';
import apiService from './api_service';
import dotnev from 'dotenv';
dotnev.config();

const openAiApiKey = process.env.OPENAI_API_KEY as string;
const HelloWorld = Type.String({
description: 'The magical words!'
});
Expand Down Expand Up @@ -67,16 +66,10 @@ export default (opts: ApiOptions) => {

api.register(healthcheck, { prefix: '/api', title: opts.title });
// register other API routes here
console.log('process.env.OPENAI_API_KEY', process.env.OPENAI_API_KEY);

if (!process.env.OPENAI_API_KEY) {
throw new Error(
'The OPENAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the OpenAI client with an apiKey option, like new OpenAI({ apiKey: "My API Key" }).'
);
}
api.register(apiService, {
prefix: '/api/v1',
openAiApiKey: process.env.OPENAI_API_KEY
openAiApiKey: openAiApiKey as string
});

return api;
Expand Down
4 changes: 3 additions & 1 deletion src/api_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const apiService: FastifyPluginCallback<ApiServiceOptions> = (
next
) => {
fastify.post('/message', async (request, reply) => {
console.log('request.body', request.body);
const userMessage = request.body as string;
await chat(reply, userMessage);
});
Expand All @@ -21,6 +20,9 @@ const apiService: FastifyPluginCallback<ApiServiceOptions> = (

async function chat(reply: FastifyReply, userMessage: string) {
const openai = opts.openAiApiKey;
if (!openai) {
throw new Error('OpenAI API key is required');
}

const client = new OpenAI({ apiKey: openai });
reply.raw.setHeader('Content-Type', 'text/event-stream');
Expand Down
1 change: 0 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export default function Page() {
method: 'POST',
body: JSON.stringify({ userMessage: input })
});
console.log('response', response);
if (response.ok) {
setResponse(await response.text());
}
Expand Down

0 comments on commit 6ec487e

Please sign in to comment.