Skip to content

Commit

Permalink
build: env variables improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianmusial committed May 22, 2024
1 parent 6a5eda1 commit 7fd05bf
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# OpenAI API Key
OPENAI_API_KEY=

# Assistant ID - leave it empty if you don't have an assistant yet
ASSISTANT_ID=
ASSISTANT_IS_LOGGER_ENABLED=

# For embedding the assistant in your website (build process)
APP_URL=

# Agents:
# -------------------------------------------------------------------
# OpenWeather (Current Weather Data)
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<p align="center">
<a href="https://boldare.com/" target="blank">
<a href="https://www.boldare.com/services/ai-software-development-consulting/" target="blank">
<img src="https://assistant.ai.boldare.dev/assets/ai-assistant.jpg" width="280" alt="Boldare" />
</a>
</p>

<p align="center">
<a href="https://assistant.ai.boldare.dev/chat" target="_blank">demo</a> 🔹
<a href="https://assistant.ai.boldare.dev/" target="_blank">demo</a> 🔹
<a href="https://assistant.ai.boldare.dev/api/docs" target="_blank">api docs</a> 🔹
<a href="https://www.npmjs.com/package/@boldare/openai-assistant" target="_blank">npm</a> 🔹
<a href="https://github.com/boldare/openai-assistant" target="_blank">github</a>
Expand Down Expand Up @@ -35,7 +35,9 @@ Introducing the NestJS library, designed to harness the power of OpenAI's Assist

In this section, you will learn how to integrate the AI Assistant library into your NestJS application. The following steps will guide you through the process of setting up the library and creating simple functionalities.

### Step 0: Prerequiring
### Step 0: Prerequisites

Install Node.js which includes Node Package Manager (`^20.0.0` version).

Before you start, you will need to have an account on the OpenAI platform and an API key. You can create an account [here](https://platform.openai.com/).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</a>
</div>

<a href="https://boldare.com" target="_blank" class="chat__header">
<a href="https://www.boldare.com/services/ai-software-development-consulting/" target="_blank" class="chat__header">
<span>Powered by digital product creators at</span>
<img
[src]="'/assets/boldare.svg'"
Expand Down
8 changes: 5 additions & 3 deletions apps/spa/src/environments/environment.development.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const { protocol, hostname, port } = window.location;

export const environment = {
env: 'dev',
appUrl: 'http://localhost:4200',
apiUrl: 'http://localhost:3000/api',
websocketUrl: 'http://localhost:3000',
appUrl: `${protocol}//${hostname}:${port}`,
apiUrl: `${protocol}//${hostname}:3000/api`,
websocketUrl: `${protocol}//${hostname}:3000`,
isThreadMemorized: true,
isAudioEnabled: true,
isTranscriptionEnabled: true,
Expand Down
8 changes: 5 additions & 3 deletions apps/spa/src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const { protocol, hostname, port } = window.location;

export const environment = {
env: 'prod',
appUrl: 'https://assistant.ai.boldare.dev',
apiUrl: 'https://assistant.ai.boldare.dev/api',
websocketUrl: 'https://assistant.ai.boldare.dev',
appUrl: `${protocol}//${hostname}:${port}`,
apiUrl: `${protocol}//${hostname}:${port}/api`,
websocketUrl: `${protocol}//${hostname}:${port}`,
isThreadMemorized: true,
isAudioEnabled: true,
isTranscriptionEnabled: true,
Expand Down
29 changes: 29 additions & 0 deletions libs/ai-embedded/set-env.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { readFileSync, writeFileSync } from 'fs';
import { config } from 'dotenv';
import path from 'node:path';

config();

const environmentProdFilePath = path.resolve('./libs/ai-embedded/src/environments/environment.prod.ts');

const variableMap = {
appUrl: 'APP_URL',
};

const updateEnvironmentFile = (filePath) => {
let content = readFileSync(filePath, 'utf8');

Object.keys(variableMap).forEach(key => {
const envKey = variableMap[key];
const value = process.env[envKey];
if (value) {
const regex = new RegExp(`(${key}:\\s*).*(,)`, 'g');
content = content.replace(regex, `$1'${value}'$2`);
}
});

writeFileSync(filePath, content, 'utf8');
console.log(`Updated ${filePath}`);
};

updateEnvironmentFile(environmentProdFilePath);
4 changes: 3 additions & 1 deletion libs/ai-embedded/src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { protocol, hostname, port } = window.location;

export const environment = {
env: 'dev',
appUrl: 'http://localhost:4200',
appUrl: `${protocol}//${hostname}:${port}`,
};
2 changes: 2 additions & 0 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
"version": "1.1.0",
"license": "MIT",
"scripts": {
"set-env": "ts-node libs/ai-embedded/set-env.mjs",
"start": "node dist/apps/api/main.js",
"start:dev": "nx run-many --parallel --target=serve --projects=api,spa ",
"start:spa": "nx serve spa",
"start:api": "nx serve api",
"build": "npm run build:ai-embedded && npm run build:spa && npm run build:api",
"build": "npm run set-env && npm run build:ai-embedded && npm run build:spa && npm run build:api",
"build:spa": "nx build --prod --skip-nx-cache spa",
"build:api": "nx build --prod api",
"build:openai-assistant": "nx build --prod openai-assistant",
"build:ai-embedded": "nx build --prod ai-embedded --no-cache && npm run cp:ai-embedded",
"build:ai-embedded": "nx build ai-embedded --prod --skip-nx-cache && npm run cp:ai-embedded",
"publish": "npm run build:openai-assistant && npm run cp:readme && cd dist/libs/openai-assistant/ && npm publish --access=public && cd ../../..",
"cp:ai-embedded": "cp ./dist/libs/ai-embedded/main.js ./apps/spa/src/assets/js/ai-embedded.js",
"cp:readme": "cp ./README.md ./dist/libs/openai-assistant/README.md",
Expand Down Expand Up @@ -95,6 +96,7 @@
"@types/node": "20.12.11",
"@typescript-eslint/eslint-plugin": "7.8.0",
"@typescript-eslint/parser": "7.8.0",
"dotenv": "^16.4.5",
"esbuild": "^0.19.12",
"eslint": "8.57.0",
"eslint-config-prettier": "^9.0.0",
Expand Down

0 comments on commit 7fd05bf

Please sign in to comment.