Skip to content

Commit 6a0b031

Browse files
authored
Create aap_chatbot directory for AAP-UI integration (#1557)
* Create aap_chatbot directory for AAP-UI integration * Fix an issue found by CI (Code scanning results/CodeQL)
1 parent 985e4b7 commit 6a0b031

33 files changed

+14806
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,6 @@ ansible_ai_connect/main/templates/chatbot/*
174174
# Files generated by vite
175175
ansible_ai_connect_chatbot/.vite/
176176
ansible_ai_connect_chatbot/coverage/
177+
178+
aap_chatbot/.vite/
179+
aap_chatbot/coverage/

aap_chatbot/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Ansible AI Connect Chatbot UI
2+
3+
## Build from source
4+
5+
To start building the "Chatbot" project, you're going to need:
6+
7+
- node (`18.20.0` was used for development)
8+
- npm (`10.5.0` was used for development)
9+
10+
For installing dependencies, **make sure that the current directory
11+
is the `ansible_ai_connect_chatbot` sub-directory first**:
12+
```commandline
13+
cd (your_git_work_directory)/ansible-ai-connect-service/ansible_ai_connect_chatbot
14+
```
15+
16+
and run
17+
18+
```commandline
19+
npm install
20+
```
21+
22+
## Available Scripts
23+
24+
### npm start
25+
26+
Runs the app in the development mode. In the developing mode,
27+
the UI attempts to connect to the local chatbot service
28+
`http://localhost:8080/v1/query`. If you need to connect
29+
to a different URL, edit `useChatbot.ts`.
30+
31+
### npm run build
32+
33+
Builds bundled javascript/css files.
34+
35+
The bundled javascript/css files are copied to
36+
`../ansible_ai_connect/main/static/chatbot` and the
37+
`index.html` file is copied to
38+
`../ansible_ai_connect/main/templates/chatbot/`.
39+
40+
### npm run test
41+
42+
Executes unit tests.
43+
44+
### npm run coverage
45+
46+
Executes unit tests with code coverage reports.
47+
The text version of the report is shown on the console,
48+
while the HTML version and the `lcov.info` file are saved
49+
in the `coverage` sub-directory.
50+
51+
## Test Chatbot in Local environment
52+
53+
**Chatbot is enabled when all of
54+
the following three parameters are defined:**
55+
56+
1. `ModelPipelineChatBot.config.inference_url` URL of the chat service to be used.
57+
2. `ModelPipelineChatBot.config.model_id` Default AI model. It should be
58+
one of models defined in the configuration used by the chat service.
59+
3. `CHATBOT_DEFAULT_PROVIDER` Default AI model provider. It should be
60+
one of providers defined in the configuration used by the chat service.
61+
62+
```commandline
63+
CHATBOT_DEFAULT_PROVIDER=wisdom
64+
```
65+
```json
66+
{
67+
"ModelPipelineChatBot": {
68+
"config": {
69+
"inference_url": "http://127.0.0.1:8080",
70+
"model_id": "granite3-8b"
71+
}
72+
}
73+
}
74+
```
75+
76+
You also need to configure Red Hat SSO authentication on your local
77+
AI Connect service.

aap_chatbot/eslint.config.mjs

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
// Originally found in https://github.com/patternfly/patternfly-react
2+
import { fixupPluginRules } from "@eslint/compat";
3+
import js from "@eslint/js";
4+
import patternflyReact from "eslint-plugin-patternfly-react";
5+
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
6+
import reactHooks from "eslint-plugin-react-hooks";
7+
import reactRecommended from "eslint-plugin-react/configs/recommended.js";
8+
import testingLibrary from "eslint-plugin-testing-library";
9+
import globals from "globals";
10+
import tseslint from "typescript-eslint";
11+
12+
// https://github.com/sindresorhus/globals/issues/239
13+
const GLOBALS_BROWSER_FIX = Object.assign({}, globals.browser, {
14+
AudioWorkletGlobalScope: globals.browser["AudioWorkletGlobalScope "],
15+
});
16+
delete GLOBALS_BROWSER_FIX["AudioWorkletGlobalScope "];
17+
18+
export default [
19+
{
20+
ignores: [
21+
"**/dist",
22+
"**/css",
23+
"packages/react-core/src/helpers/Popper/thirdparty",
24+
"packages/react-docs/patternfly-docs/generated",
25+
".history/*",
26+
"packages/react-docs/static",
27+
"**/*-env.d.ts",
28+
],
29+
},
30+
js.configs.recommended,
31+
...tseslint.configs.recommended,
32+
reactRecommended,
33+
eslintPluginPrettierRecommended,
34+
{
35+
plugins: {
36+
"patternfly-react": fixupPluginRules(patternflyReact),
37+
"react-hooks": fixupPluginRules(reactHooks),
38+
},
39+
languageOptions: {
40+
globals: {
41+
...GLOBALS_BROWSER_FIX,
42+
...globals.node,
43+
...globals.jest,
44+
},
45+
},
46+
settings: {
47+
react: {
48+
version: "detect",
49+
},
50+
},
51+
rules: {
52+
...reactHooks.configs.recommended.rules,
53+
"@typescript-eslint/ban-ts-comment": "off",
54+
"@typescript-eslint/adjacent-overload-signatures": "error",
55+
"@typescript-eslint/array-type": "error",
56+
"@typescript-eslint/ban-types": "off",
57+
"@typescript-eslint/consistent-type-assertions": "error",
58+
"@typescript-eslint/consistent-type-definitions": "off", // changed from 'error',
59+
"@typescript-eslint/explicit-member-accessibility": "off",
60+
"@typescript-eslint/explicit-module-boundary-types": "off",
61+
"@typescript-eslint/indent": "off",
62+
"@typescript-eslint/no-duplicate-enum-values": "off",
63+
"@typescript-eslint/no-empty-function": "off",
64+
"@typescript-eslint/no-empty-interface": "off",
65+
"@typescript-eslint/no-explicit-any": "off",
66+
"@typescript-eslint/no-inferrable-types": "off",
67+
"@typescript-eslint/no-misused-new": "error",
68+
"@typescript-eslint/no-namespace": "error",
69+
"@typescript-eslint/no-unused-vars": [
70+
"error",
71+
{
72+
argsIgnorePattern: "^_",
73+
},
74+
],
75+
"@typescript-eslint/no-use-before-define": "off",
76+
"@typescript-eslint/no-var-requires": "off",
77+
"@typescript-eslint/prefer-for-of": "error",
78+
"@typescript-eslint/prefer-function-type": "error",
79+
"@typescript-eslint/prefer-namespace-keyword": "error",
80+
"@typescript-eslint/unified-signatures": "error",
81+
"@typescript-eslint/explicit-function-return-type": "off",
82+
"arrow-body-style": "error",
83+
camelcase: "off", // changed
84+
// camelcase: [
85+
// 'error',
86+
// {
87+
// ignoreDestructuring: true
88+
// }
89+
// ],
90+
"constructor-super": "error",
91+
curly: "error",
92+
"dot-notation": "error",
93+
eqeqeq: ["error", "smart"],
94+
"guard-for-in": "error",
95+
"max-classes-per-file": ["error", 1],
96+
"max-len": "off",
97+
"no-nested-ternary": "error",
98+
"no-bitwise": "error",
99+
"no-caller": "error",
100+
"no-cond-assign": "error",
101+
"no-console": "off", // changed from 'error'
102+
"no-debugger": "error",
103+
"no-empty": "error",
104+
"no-eval": "error",
105+
"no-new-wrappers": "error",
106+
"no-prototype-builtins": "off",
107+
"no-shadow": "off",
108+
"no-throw-literal": "error",
109+
"no-trailing-spaces": "off",
110+
"no-undef-init": "error",
111+
"no-constant-binary-expression": "off",
112+
"no-unsafe-finally": "error",
113+
"no-unused-expressions": [
114+
"error",
115+
{
116+
allowTernary: true,
117+
allowShortCircuit: true,
118+
},
119+
],
120+
"no-unused-labels": "error",
121+
"no-var": "error",
122+
"object-shorthand": "error",
123+
"one-var": ["error", "never"],
124+
"patternfly-react/import-tokens-icons": "error",
125+
"patternfly-react/no-anonymous-functions": "error",
126+
"prefer-const": "error",
127+
radix: ["error", "as-needed"],
128+
"react/prop-types": 0,
129+
"react/display-name": 0,
130+
"react-hooks/exhaustive-deps": "warn",
131+
"react/no-unescaped-entities": ["error", { forbid: [">", "}"] }],
132+
"spaced-comment": "error",
133+
"use-isnan": "error",
134+
"patternfly-react/no-layout-effect": "error",
135+
"valid-typeof": "off",
136+
},
137+
},
138+
{
139+
files: ["**/examples/*", "**/demos/examples/**/*"],
140+
rules: {
141+
"patternfly-react/no-anonymous-functions": "off",
142+
},
143+
},
144+
{
145+
files: ["**/*.test.[jt]s?(x)"],
146+
plugins: {
147+
"testing-library": fixupPluginRules(testingLibrary),
148+
},
149+
rules: {
150+
...testingLibrary.configs.react.rules,
151+
"@typescript-eslint/no-unused-vars": "off",
152+
"testing-library/no-container": "off", // added
153+
"testing-library/no-node-access": "off",
154+
"testing-library/no-unnecessary-act": "off", // added
155+
"react/jsx-key": "off",
156+
"react/no-children-prop": "off",
157+
"no-console": "off",
158+
},
159+
},
160+
{
161+
files: ["packages/react-integration/demo-app-ts/**/*"],
162+
rules: {
163+
"patternfly-react/no-anonymous-functions": "off",
164+
"react/react-in-jsx-scope": "off",
165+
"spaced-comment": "off",
166+
},
167+
},
168+
];

aap_chatbot/index.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<meta name="theme-color" content="#000000" />
7+
<meta
8+
name="description"
9+
content="{{bot_name}}"
10+
/>
11+
<title>{{bot_name}}</title>
12+
<script type="module">
13+
import { Buffer } from "buffer";
14+
import process from "process";
15+
window.Buffer = Buffer;
16+
window.process = process;
17+
</script>
18+
</head>
19+
<body>
20+
<noscript>You need to enable JavaScript to run this app.</noscript>
21+
<div id="root">
22+
<script type="module" src="/src/index.tsx"></script>
23+
</div>
24+
<div id="user_name" hidden>{{user_name}}</div>
25+
<div id="bot_name" hidden>{{bot_name}}</div>
26+
<div id="debug" hidden>{{debug}}</div>
27+
</body>
28+
</html>

0 commit comments

Comments
 (0)