Skip to content

Commit

Permalink
feat(AI-130): changed model and added missing tools (#14)
Browse files Browse the repository at this point in the history
* feat(AI-130): changed model and added missing tools

* feat(AI-130): bot as an external script
  • Loading branch information
sebastianmusial authored Feb 6, 2024
1 parent 68396f9 commit 2ca364d
Show file tree
Hide file tree
Showing 26 changed files with 4,044 additions and 1,396 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ Thumbs.db
.env.*
!.env.dist
/apps/spa/src/assets/uploads
/apps/spa/src/assets/js
9 changes: 6 additions & 3 deletions apps/api/src/app/chat/chat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import { AssistantConfigParams } from '@boldare/ai-assistant';
import 'dotenv/config';

export const assistantParams: AssistantCreateParams = {
name: '@boldare/assistant-ai',
name: '@boldare/ai-assistant',
instructions: `You are a chatbot assistant. Use the general knowledge to answer questions. Speak briefly and clearly.`,
tools: [],
model: 'gpt-3.5-turbo',
tools: [
{ type: 'code_interpreter' },
{ type: 'retrieval' },
],
model: 'gpt-4-1106-preview',
metadata: {},
};

Expand Down
6 changes: 5 additions & 1 deletion apps/spa/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
"assets": ["apps/spa/src/assets"],
"styles": [
"@angular/material/prebuilt-themes/indigo-pink.css",
"node_modules/prismjs/themes/prism-tomorrow.css",
"apps/spa/src/styles/styles.scss"
],
"stylePreprocessorOptions": {
"includePaths": ["apps/spa/src/styles"]
},
"scripts": [],
"scripts": [
"node_modules/prismjs/prism.js",
"node_modules/prismjs/components/prism-javascript.min.js"
],
"allowedCommonJsDependencies": ["recordrtc"]
},
"configurations": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1>
How to add a chatbot to the website?
</h1>

Please copy the code provided below and paste it into your HTML file.

<markdown [data]="markdown"></markdown>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@import 'settings';

:host {
display: flex;
flex-direction: column;
gap: $size-2;
max-width: 600px;
font-size: 16px;
margin: 0 auto;
padding: 40px 20px;
color: var(--color-grey-600);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
import { Component } from '@angular/core';
import { AssistantIframe } from '@boldare/ai-iframe';
import { ChatService } from '../../shared/chat.service';
import { environment } from '../../../../../environments/environment';
import { MarkdownComponent, MarkdownPipe } from 'ngx-markdown';
import { AsyncPipe } from '@angular/common';

@Component({
selector: 'ai-chat-example',
standalone: true,
templateUrl: './chat-example.component.html',
styleUrl: './chat-example.component.scss',
imports: [
MarkdownComponent,
MarkdownPipe,
AsyncPipe,
],
})
export class ChatExampleComponent {
iframe = new AssistantIframe({ url: `${environment.appUrl}/chat/iframe` });
markdown = `\`\`\`html
<script
src="${environment.appUrl}/assets/js/ai-embedded.js"
type="module"
defer
></script>
\`\`\``;

constructor(private readonly chatService: ChatService,) {
this.chatService.loadScript();
}
}
12 changes: 12 additions & 0 deletions apps/spa/src/app/modules/+chat/shared/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,16 @@ export class ChatService {
}
});
}

loadScript(): void {
const body: HTMLDivElement = document.body as HTMLDivElement;
const script = document.createElement('script') as HTMLScriptElement;

script.innerHTML = '';
script.src = '/assets/js/ai-embedded.js';
script.async = true;
script.defer = true;
script.type = 'module';
body.appendChild(script);
}
}
1 change: 1 addition & 0 deletions apps/spa/src/styles/_settings/_colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
--color-black: #000000;

--color-grey-900: #2a2a2a;
--color-grey-600: #464646;
--color-grey-500: #656565;
--color-grey-300: #e0e0e0;
--color-grey-200: #f2f2f2;
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions libs/ai-embedded/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ai-embedded

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build ai-embedded` to build the library.

## Running unit tests

Run `nx test ai-embedded` to execute the unit tests via [Jest](https://jestjs.io).
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable */
export default {
displayName: 'ai-iframe',
displayName: 'ai-embedded',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/libs/ai-iframe',
coverageDirectory: '../../coverage/libs/ai-embedded',
};
4 changes: 2 additions & 2 deletions libs/ai-iframe/package.json → libs/ai-embedded/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@boldare/ai-iframe",
"name": "@boldare/ai-embedded",
"version": "0.0.1",
"dependencies": {},
"type": "commonjs",
"main": "./index.cjs"
"main": "./index.js"
}
32 changes: 32 additions & 0 deletions libs/ai-embedded/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "ai-embedded",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/ai-embedded/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/esbuild:esbuild",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/ai-embedded",
"main": "libs/ai-embedded/src/index.ts",
"tsConfig": "libs/ai-embedded/tsconfig.lib.json",
"assets": ["libs/ai-embedded/*.md"],
"generatePackageJson": false,
"format": ["esm"]
}
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"]
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/ai-embedded/jest.config.ts"
}
}
},
"tags": []
}
8 changes: 8 additions & 0 deletions libs/ai-embedded/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { AssistantIframe } from './lib/assistant-iframe';

export * from './lib/assistant-iframe';
export * from './lib/assistant-iframe.model';

(function () {
new AssistantIframe();
})();
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ export class AssistantIframe {
trigger!: HTMLElement;

constructor(config: Partial<AssistantIframeConfig> = {}) {
// @TODO: set URL as an env variable
const url = 'https://ai-assistant-c8b469d88808.herokuapp.com';

this.config = {
url: config.url || '',
url: `${url}/chat/iframe`,
elementId: config.elementId || '',
iframeId: config.elementId || 'ai-assistant-iframe',
iframeClass: 'ai-assistant-iframe',
toggleClass: 'ai-assistant-toggle',
bodyOpenClass: 'ai-assistant-open',
toggleIsAnimated: config.toggleIsAnimated || true,
};

this.init();
}

Expand Down Expand Up @@ -56,14 +58,15 @@ export class AssistantIframe {
const iframe = document.createElement('iframe');
iframe.src = this.config.url;
iframe.classList.add(this.config.iframeClass);
iframe.id = this.config.elementId;
iframe.id = this.config.iframeId;

return iframe;
}

appendElement(element: HTMLElement): void {
if (!this.config.elementId) {
document.body.appendChild(element);
return;
}

const wrapper = document.getElementById(this.config.elementId);
Expand All @@ -84,6 +87,7 @@ export class AssistantIframe {
this.iframe?.contentDocument?.body.classList.contains(
this.config.bodyOpenClass,
);

this.toggleModal(!currentState);
this.watchToggleButton();
});
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"],
"target": "es2021",
"strictNullChecks": true,
"noImplicitAny": true,
"strictBindCallApply": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
Expand Down
File renamed without changes.
11 changes: 0 additions & 11 deletions libs/ai-iframe/README.md

This file was deleted.

46 changes: 0 additions & 46 deletions libs/ai-iframe/project.json

This file was deleted.

2 changes: 0 additions & 2 deletions libs/ai-iframe/src/index.ts

This file was deleted.

Loading

0 comments on commit 2ca364d

Please sign in to comment.