Skip to content

Commit 7ab7de7

Browse files
Merge pull request #61 from boldare/build/env-variables
build: env variables improvements
2 parents 6a5eda1 + 7fd05bf commit 7ab7de7

File tree

9 files changed

+58
-13
lines changed

9 files changed

+58
-13
lines changed

.env.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# OpenAI API Key
22
OPENAI_API_KEY=
3+
34
# Assistant ID - leave it empty if you don't have an assistant yet
45
ASSISTANT_ID=
56
ASSISTANT_IS_LOGGER_ENABLED=
67

8+
# For embedding the assistant in your website (build process)
9+
APP_URL=
10+
711
# Agents:
812
# -------------------------------------------------------------------
913
# OpenWeather (Current Weather Data)

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<p align="center">
2-
<a href="https://boldare.com/" target="blank">
2+
<a href="https://www.boldare.com/services/ai-software-development-consulting/" target="blank">
33
<img src="https://assistant.ai.boldare.dev/assets/ai-assistant.jpg" width="280" alt="Boldare" />
44
</a>
55
</p>
66

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

3636
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.
3737

38-
### Step 0: Prerequiring
38+
### Step 0: Prerequisites
39+
40+
Install Node.js which includes Node Package Manager (`^20.0.0` version).
3941

4042
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/).
4143

apps/spa/src/app/modules/+chat/containers/chat/chat.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
</a>
3333
</div>
3434

35-
<a href="https://boldare.com" target="_blank" class="chat__header">
35+
<a href="https://www.boldare.com/services/ai-software-development-consulting/" target="_blank" class="chat__header">
3636
<span>Powered by digital product creators at</span>
3737
<img
3838
[src]="'/assets/boldare.svg'"

apps/spa/src/environments/environment.development.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
const { protocol, hostname, port } = window.location;
2+
13
export const environment = {
24
env: 'dev',
3-
appUrl: 'http://localhost:4200',
4-
apiUrl: 'http://localhost:3000/api',
5-
websocketUrl: 'http://localhost:3000',
5+
appUrl: `${protocol}//${hostname}:${port}`,
6+
apiUrl: `${protocol}//${hostname}:3000/api`,
7+
websocketUrl: `${protocol}//${hostname}:3000`,
68
isThreadMemorized: true,
79
isAudioEnabled: true,
810
isTranscriptionEnabled: true,

apps/spa/src/environments/environment.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
const { protocol, hostname, port } = window.location;
2+
13
export const environment = {
24
env: 'prod',
3-
appUrl: 'https://assistant.ai.boldare.dev',
4-
apiUrl: 'https://assistant.ai.boldare.dev/api',
5-
websocketUrl: 'https://assistant.ai.boldare.dev',
5+
appUrl: `${protocol}//${hostname}:${port}`,
6+
apiUrl: `${protocol}//${hostname}:${port}/api`,
7+
websocketUrl: `${protocol}//${hostname}:${port}`,
68
isThreadMemorized: true,
79
isAudioEnabled: true,
810
isTranscriptionEnabled: true,

libs/ai-embedded/set-env.mjs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { readFileSync, writeFileSync } from 'fs';
2+
import { config } from 'dotenv';
3+
import path from 'node:path';
4+
5+
config();
6+
7+
const environmentProdFilePath = path.resolve('./libs/ai-embedded/src/environments/environment.prod.ts');
8+
9+
const variableMap = {
10+
appUrl: 'APP_URL',
11+
};
12+
13+
const updateEnvironmentFile = (filePath) => {
14+
let content = readFileSync(filePath, 'utf8');
15+
16+
Object.keys(variableMap).forEach(key => {
17+
const envKey = variableMap[key];
18+
const value = process.env[envKey];
19+
if (value) {
20+
const regex = new RegExp(`(${key}:\\s*).*(,)`, 'g');
21+
content = content.replace(regex, `$1'${value}'$2`);
22+
}
23+
});
24+
25+
writeFileSync(filePath, content, 'utf8');
26+
console.log(`Updated ${filePath}`);
27+
};
28+
29+
updateEnvironmentFile(environmentProdFilePath);
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
const { protocol, hostname, port } = window.location;
2+
13
export const environment = {
24
env: 'dev',
3-
appUrl: 'http://localhost:4200',
5+
appUrl: `${protocol}//${hostname}:${port}`,
46
};

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
"version": "1.1.0",
44
"license": "MIT",
55
"scripts": {
6+
"set-env": "ts-node libs/ai-embedded/set-env.mjs",
67
"start": "node dist/apps/api/main.js",
78
"start:dev": "nx run-many --parallel --target=serve --projects=api,spa ",
89
"start:spa": "nx serve spa",
910
"start:api": "nx serve api",
10-
"build": "npm run build:ai-embedded && npm run build:spa && npm run build:api",
11+
"build": "npm run set-env && npm run build:ai-embedded && npm run build:spa && npm run build:api",
1112
"build:spa": "nx build --prod --skip-nx-cache spa",
1213
"build:api": "nx build --prod api",
1314
"build:openai-assistant": "nx build --prod openai-assistant",
14-
"build:ai-embedded": "nx build --prod ai-embedded --no-cache && npm run cp:ai-embedded",
15+
"build:ai-embedded": "nx build ai-embedded --prod --skip-nx-cache && npm run cp:ai-embedded",
1516
"publish": "npm run build:openai-assistant && npm run cp:readme && cd dist/libs/openai-assistant/ && npm publish --access=public && cd ../../..",
1617
"cp:ai-embedded": "cp ./dist/libs/ai-embedded/main.js ./apps/spa/src/assets/js/ai-embedded.js",
1718
"cp:readme": "cp ./README.md ./dist/libs/openai-assistant/README.md",
@@ -95,6 +96,7 @@
9596
"@types/node": "20.12.11",
9697
"@typescript-eslint/eslint-plugin": "7.8.0",
9798
"@typescript-eslint/parser": "7.8.0",
99+
"dotenv": "^16.4.5",
98100
"esbuild": "^0.19.12",
99101
"eslint": "8.57.0",
100102
"eslint-config-prettier": "^9.0.0",

0 commit comments

Comments
 (0)