Skip to content

Commit

Permalink
chore: use env file.
Browse files Browse the repository at this point in the history
  • Loading branch information
thorwebdev committed Jan 2, 2025
1 parent d872e76 commit ca068d4
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OPENAI_API_KEY="<your-key-here>"
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ This is an example application showing how to use the [OpenAI Realtime API](http

## Installation and usage

Before you begin, you'll need an OpenAI API key - [create one in the dashboard here](https://platform.openai.com/settings/api-keys). Export it as a system environment variable:
Before you begin, you'll need an OpenAI API key - [create one in the dashboard here](https://platform.openai.com/settings/api-keys). Create a `.env` file from the example file and set your API key in there:

```bash
export OPENAI_API_KEY=<your key here>
cp .env.example .env
```

Running this application locally requires [Node.js](https://nodejs.org/) to be installed. Install dependencies for the application with:
Expand All @@ -24,6 +24,8 @@ npm run dev

This should start the console application on [http://localhost:3000](http://localhost:3000).

_Note:_ The `server.js` file uses [@fastify/vite](https://fastify-vite.dev/) to build and serve the Astro frontend contained in the `/client` folder. You can find the configuration in the [`vite.config.js` file](./vite.config.js)

## Previous WebSockets version

The previous version of this application that used WebSockets on the client (not recommended in client-side browsers) [can be found here](https://github.com/openai/openai-realtime-console/tree/websockets).
Expand Down
45 changes: 44 additions & 1 deletion package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"lint": "eslint . --ext .js,.jsx --fix"
},
"dependencies": {
"@fastify/env": "^4.4.0",
"@fastify/one-line-logger": "^1.2.0",
"@fastify/react": "^0.6.0",
"@fastify/vite": "^6.0.5",
Expand Down
13 changes: 13 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Fastify from "fastify";
import FastifyVite from "@fastify/vite";
import fastifyEnv from "@fastify/env";

// Fastify + React + Vite configuration
const server = Fastify({
Expand All @@ -10,6 +11,18 @@ const server = Fastify({
},
});

const schema = {
type: "object",
required: ["OPENAI_API_KEY"],
properties: {
OPENAI_API_KEY: {
type: "string",
},
},
};

await server.register(fastifyEnv, { dotenv: true, schema });

await server.register(FastifyVite, {
root: import.meta.url,
renderer: "@fastify/react",
Expand Down

0 comments on commit ca068d4

Please sign in to comment.