├── .editorconfig
├── .fb-gitignore
├── .gitignore
├── .vscode
├── extensions.json
├── launch.json
└── tasks.json
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── angular.json
├── firebase.json
├── firestore-debug.log
├── package-lock.json
├── package.json
├── src
├── app
│ ├── app.component.spec.ts
│ ├── app.component.ts
│ └── app.config.ts
├── assets
│ ├── .gitkeep
│ └── firestore-palm-chatbot-logo.png
├── environments
│ ├── environment.development.ts
│ └── environment.ts
├── favicon.ico
├── index.html
├── main.ts
└── styles.css
├── tsconfig.app.json
├── tsconfig.json
├── tsconfig.spec.json
└── ui-debug.log
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see https://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.ts]
12 | quote_type = single
13 |
14 | [*.md]
15 | max_line_length = off
16 | trim_trailing_whitespace = false
17 |
--------------------------------------------------------------------------------
/.fb-gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | firebase-debug.log*
8 | firebase-debug.*.log*
9 |
10 | # Firebase cache
11 | .firebase/
12 |
13 | # Firebase config
14 |
15 | # Uncomment this if you'd like others to create their own Firebase project.
16 | # For a team working on the same Firebase project(s), it is recommended to leave
17 | # it commented so all members can deploy to the same project(s) in .firebaserc.
18 | # .firebaserc
19 |
20 | # Runtime data
21 | pids
22 | *.pid
23 | *.seed
24 | *.pid.lock
25 |
26 | # Directory for instrumented libs generated by jscoverage/JSCover
27 | lib-cov
28 |
29 | # Coverage directory used by tools like istanbul
30 | coverage
31 |
32 | # nyc test coverage
33 | .nyc_output
34 |
35 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
36 | .grunt
37 |
38 | # Bower dependency directory (https://bower.io/)
39 | bower_components
40 |
41 | # node-waf configuration
42 | .lock-wscript
43 |
44 | # Compiled binary addons (http://nodejs.org/api/addons.html)
45 | build/Release
46 |
47 | # Dependency directories
48 | node_modules/
49 |
50 | # Optional npm cache directory
51 | .npm
52 |
53 | # Optional eslint cache
54 | .eslintcache
55 |
56 | # Optional REPL history
57 | .node_repl_history
58 |
59 | # Output of 'npm pack'
60 | *.tgz
61 |
62 | # Yarn Integrity file
63 | .yarn-integrity
64 |
65 | # dotenv environment variables file
66 | .env
67 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # Compiled output
4 | /dist
5 | /tmp
6 | /out-tsc
7 | /bazel-out
8 |
9 | # Node
10 | /node_modules
11 | npm-debug.log
12 | yarn-error.log
13 |
14 | # IDEs and editors
15 | .idea/
16 | .project
17 | .classpath
18 | .c9/
19 | *.launch
20 | .settings/
21 | *.sublime-workspace
22 |
23 | # Visual Studio Code
24 | .vscode/*
25 | !.vscode/settings.json
26 | !.vscode/tasks.json
27 | !.vscode/launch.json
28 | !.vscode/extensions.json
29 | .history/*
30 |
31 | # Miscellaneous
32 | /.angular/cache
33 | .sass-cache/
34 | /connect.lock
35 | /coverage
36 | /libpeerconnection.log
37 | testem.log
38 | /typings
39 |
40 | # System files
41 | .DS_Store
42 | Thumbs.db
43 |
44 | # Logs
45 | logs
46 | *.log
47 | npm-debug.log*
48 | yarn-debug.log*
49 | yarn-error.log*
50 | firebase-debug.log*
51 | firebase-debug.*.log*
52 |
53 | # Firebase cache
54 | .firebase/
55 |
56 | # Firebase config
57 |
58 | # Uncomment this if you'd like others to create their own Firebase project.
59 | # For a team working on the same Firebase project(s), it is recommended to leave
60 | # it commented so all members can deploy to the same project(s) in .firebaserc.
61 | # .firebaserc
62 |
63 | # Runtime data
64 | pids
65 | *.pid
66 | *.seed
67 | *.pid.lock
68 |
69 | # Directory for instrumented libs generated by jscoverage/JSCover
70 | lib-cov
71 |
72 | # Coverage directory used by tools like istanbul
73 | coverage
74 |
75 | # nyc test coverage
76 | .nyc_output
77 |
78 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
79 | .grunt
80 |
81 | # Bower dependency directory (https://bower.io/)
82 | bower_components
83 |
84 | # node-waf configuration
85 | .lock-wscript
86 |
87 | # Compiled binary addons (http://nodejs.org/api/addons.html)
88 | build/Release
89 |
90 | # Dependency directories
91 | node_modules/
92 |
93 | # Optional npm cache directory
94 | .npm
95 |
96 | # Optional eslint cache
97 | .eslintcache
98 |
99 | # Optional REPL history
100 | .node_repl_history
101 |
102 | # Output of 'npm pack'
103 | *.tgz
104 |
105 | # Yarn Integrity file
106 | .yarn-integrity
107 |
108 | # dotenv environment variables file
109 | .env
110 |
111 | # Local config telling the Firebase CLI which firebase project to deploy to
112 | .firebaserc
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
3 | "recommendations": ["angular.ng-template"]
4 | }
5 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
3 | "version": "0.2.0",
4 | "configurations": [
5 | {
6 | "name": "ng serve",
7 | "type": "chrome",
8 | "request": "launch",
9 | "preLaunchTask": "npm: start",
10 | "url": "http://localhost:4200/"
11 | },
12 | {
13 | "name": "ng test",
14 | "type": "chrome",
15 | "request": "launch",
16 | "preLaunchTask": "npm: test",
17 | "url": "http://localhost:9876/debug.html"
18 | }
19 | ]
20 | }
21 |
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558
3 | "version": "2.0.0",
4 | "tasks": [
5 | {
6 | "type": "npm",
7 | "script": "start",
8 | "isBackground": true,
9 | "problemMatcher": {
10 | "owner": "typescript",
11 | "pattern": "$tsc",
12 | "background": {
13 | "activeOnStart": true,
14 | "beginsPattern": {
15 | "regexp": "(.*?)"
16 | },
17 | "endsPattern": {
18 | "regexp": "bundle generation complete"
19 | }
20 | }
21 | }
22 | },
23 | {
24 | "type": "npm",
25 | "script": "test",
26 | "isBackground": true,
27 | "problemMatcher": {
28 | "owner": "typescript",
29 | "pattern": "$tsc",
30 | "background": {
31 | "activeOnStart": true,
32 | "beginsPattern": {
33 | "regexp": "(.*?)"
34 | },
35 | "endsPattern": {
36 | "regexp": "bundle generation complete"
37 | }
38 | }
39 | }
40 | }
41 | ]
42 | }
43 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to contribute
2 |
3 | We'd love to accept your patches and contributions to this project.
4 |
5 | ## Before you begin
6 |
7 | ### Sign our Contributor License Agreement
8 |
9 | Contributions to this project must be accompanied by a
10 | [Contributor License Agreement](https://cla.developers.google.com/about) (CLA).
11 | You (or your employer) retain the copyright to your contribution; this simply
12 | gives us permission to use and redistribute your contributions as part of the
13 | project.
14 |
15 | If you or your current employer have already signed the Google CLA (even if it
16 | was for a different project), you probably don't need to do it again.
17 |
18 | Visit to see your current agreements or to
19 | sign a new one.
20 |
21 | ### Review our community guidelines
22 |
23 | This project follows
24 | [Google's Open Source Community Guidelines](https://opensource.google/conduct/).
25 |
26 | ## Contribution process
27 |
28 | ### Code reviews
29 |
30 | All submissions, including submissions by project members, require review. We
31 | use GitHub pull requests for this purpose. Consult
32 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
33 | information on using pull requests.
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PalmApiApp
2 |
3 | A demo app to show how to use Firebase, Angular, and the PaLM API to create a customizable chat bot.
4 |
5 | ## Get started
6 |
7 | 1. [Create a Firebase project](https://firebase.google.com/docs/web/setup#create-project)
8 | 2. [Register a new web app with Firebase Hosting](https://firebase.google.com/docs/web/setup#register-app)
9 | 3. In the Firebase console, enable Cloud Firestore
10 | 4. Install the [Chatbot with PaLM API extension](https://extensions.dev/extensions/googlecloud/firestore-palm-chatbot)
11 | 5. Clone this repo into your local directory
12 | 6. `npm install` to install dependencies
13 | 7. Add the web app config object from the Firebase console in `src/environments/environment.ts` and `src/environments/environment.development.ts` files.
14 | 8. Use the [Angular CLI](https://angular.io/cli) to run `ng add @angular/fire --project=[YOUR PROJECT_NAME]`
15 | 9. `ng deploy` to compile your project and deploy to your hosting URL
16 |
17 | Your chatbot is deployed to Firebase, and ready to use!
18 |
19 | ## Development server
20 |
21 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files.
22 |
23 | ## Build
24 |
25 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory.
26 |
27 | ## Deploy
28 |
29 | Run `ng deploy` to deploy the project to your hosting website. Navigate to the provided Hosting URL to try out your chatbot.
30 |
31 | ## Further help
32 |
33 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
34 |
--------------------------------------------------------------------------------
/angular.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "version": 1,
4 | "newProjectRoot": "projects",
5 | "projects": {
6 | "palm-api-app": {
7 | "projectType": "application",
8 | "schematics": {},
9 | "root": "",
10 | "sourceRoot": "src",
11 | "prefix": "app",
12 | "architect": {
13 | "build": {
14 | "builder": "@angular-devkit/build-angular:browser",
15 | "options": {
16 | "outputPath": "dist/palm-api-app",
17 | "index": "src/index.html",
18 | "main": "src/main.ts",
19 | "polyfills": [
20 | "zone.js"
21 | ],
22 | "tsConfig": "tsconfig.app.json",
23 | "assets": [
24 | "src/favicon.ico",
25 | "src/assets"
26 | ],
27 | "styles": [
28 | "src/styles.css"
29 | ],
30 | "scripts": []
31 | },
32 | "configurations": {
33 | "production": {
34 | "budgets": [
35 | {
36 | "type": "initial",
37 | "maximumWarning": "500kb",
38 | "maximumError": "1mb"
39 | },
40 | {
41 | "type": "anyComponentStyle",
42 | "maximumWarning": "2kb",
43 | "maximumError": "4kb"
44 | }
45 | ],
46 | "outputHashing": "all"
47 | },
48 | "development": {
49 | "buildOptimizer": false,
50 | "optimization": false,
51 | "vendorChunk": true,
52 | "extractLicenses": false,
53 | "sourceMap": true,
54 | "namedChunks": true,
55 | "fileReplacements": [
56 | {
57 | "replace": "src/environments/environment.ts",
58 | "with": "src/environments/environment.development.ts"
59 | }
60 | ]
61 | }
62 | },
63 | "defaultConfiguration": "production"
64 | },
65 | "serve": {
66 | "builder": "@angular-devkit/build-angular:dev-server",
67 | "configurations": {
68 | "production": {
69 | "browserTarget": "palm-api-app:build:production"
70 | },
71 | "development": {
72 | "browserTarget": "palm-api-app:build:development"
73 | }
74 | },
75 | "defaultConfiguration": "development"
76 | },
77 | "extract-i18n": {
78 | "builder": "@angular-devkit/build-angular:extract-i18n",
79 | "options": {
80 | "browserTarget": "palm-api-app:build"
81 | }
82 | },
83 | "test": {
84 | "builder": "@angular-devkit/build-angular:karma",
85 | "options": {
86 | "polyfills": [
87 | "zone.js",
88 | "zone.js/testing"
89 | ],
90 | "tsConfig": "tsconfig.spec.json",
91 | "assets": [
92 | "src/favicon.ico",
93 | "src/assets"
94 | ],
95 | "styles": [
96 | "src/styles.css"
97 | ],
98 | "scripts": []
99 | }
100 | },
101 | "deploy": {
102 | "builder": "@angular/fire:deploy",
103 | "options": {
104 | "version": 2,
105 | "browserTarget": "palm-api-app:build:production"
106 | }
107 | }
108 | }
109 | }
110 | },
111 | "cli": {
112 | "analytics": "bc92bba8-fc99-4e7d-b704-1b072d5ff38a"
113 | }
114 | }
--------------------------------------------------------------------------------
/firebase.json:
--------------------------------------------------------------------------------
1 | {
2 | "hosting": [
3 | {
4 | "target": "palm-api-app",
5 | "source": ".",
6 | "frameworksBackend": {}
7 | }
8 | ]
9 | }
--------------------------------------------------------------------------------
/firestore-debug.log:
--------------------------------------------------------------------------------
1 | Aug 18, 2023 10:32:38 PM com.google.cloud.datastore.emulator.firestore.websocket.WebSocketServer start
2 | INFO: Started WebSocket server on ws://127.0.0.1:9150
3 | API endpoint: http://127.0.0.1:8080
4 | If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:
5 |
6 | export FIRESTORE_EMULATOR_HOST=127.0.0.1:8080
7 |
8 | Dev App Server is now running.
9 |
10 | Aug 18, 2023 10:32:57 PM com.google.cloud.datastore.emulator.firestore.websocket.WebSocketChannelHandler initChannel
11 | INFO: Connected to new websocket client
12 | Aug 18, 2023 10:33:05 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
13 | INFO: Detected non-HTTP/2 connection.
14 | Aug 18, 2023 10:33:05 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
15 | INFO: Detected HTTP/2 connection.
16 | Aug 18, 2023 10:40:10 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
17 | INFO: Detected non-HTTP/2 connection.
18 | *** shutting down gRPC server since JVM is shutting down
19 | *** server shut down
20 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "palm-api-app",
3 | "version": "0.0.0",
4 | "scripts": {
5 | "ng": "ng",
6 | "start": "ng serve",
7 | "build": "ng build",
8 | "watch": "ng build --watch --configuration development",
9 | "test": "ng test"
10 | },
11 | "private": true,
12 | "dependencies": {
13 | "@angular/animations": "^15.2.0",
14 | "@angular/common": "^15.2.0",
15 | "@angular/compiler": "^15.2.0",
16 | "@angular/core": "^15.2.0",
17 | "@angular/fire": "^7.6.1",
18 | "@angular/forms": "^15.2.0",
19 | "@angular/platform-browser": "^15.2.0",
20 | "@angular/platform-browser-dynamic": "^15.2.0",
21 | "@angular/router": "^15.2.0",
22 | "rxjs": "~7.8.0",
23 | "tslib": "^2.3.0",
24 | "zone.js": "~0.12.0"
25 | },
26 | "devDependencies": {
27 | "@angular-devkit/build-angular": "^15.2.7",
28 | "@angular/cli": "~15.2.7",
29 | "@angular/compiler-cli": "^15.2.0",
30 | "@types/jasmine": "~4.3.0",
31 | "jasmine-core": "~4.5.0",
32 | "karma": "~6.4.0",
33 | "karma-chrome-launcher": "~3.1.0",
34 | "karma-coverage": "~2.2.0",
35 | "karma-jasmine": "~5.1.0",
36 | "karma-jasmine-html-reporter": "~2.0.0",
37 | "typescript": "~4.9.4"
38 | }
39 | }
--------------------------------------------------------------------------------
/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | import { TestBed } from '@angular/core/testing';
18 | import { AppComponent } from './app.component';
19 |
20 | describe('AppComponent', () => {
21 | beforeEach(async () => {
22 | await TestBed.configureTestingModule({
23 | declarations: [
24 | AppComponent
25 | ],
26 | }).compileComponents();
27 | });
28 |
29 | it('should create the app', () => {
30 | const fixture = TestBed.createComponent(AppComponent);
31 | const app = fixture.componentInstance;
32 | expect(app).toBeTruthy();
33 | });
34 |
35 | it(`should have as title 'palm-api-app'`, () => {
36 | const fixture = TestBed.createComponent(AppComponent);
37 | const app = fixture.componentInstance;
38 | expect(app.title).toEqual('palm-api-app');
39 | });
40 |
41 | it('should render title', () => {
42 | const fixture = TestBed.createComponent(AppComponent);
43 | fixture.detectChanges();
44 | const compiled = fixture.nativeElement as HTMLElement;
45 | expect(compiled.querySelector('.content span')?.textContent).toContain('palm-api-app app is running!');
46 | });
47 | });
48 |
--------------------------------------------------------------------------------
/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | import { NgClass, NgFor, NgIf } from '@angular/common';
18 | import { Component, inject } from '@angular/core';
19 | import { Firestore, collection, getDoc, onSnapshot } from '@angular/fire/firestore';
20 | import { addDoc, doc } from '@firebase/firestore';
21 |
22 | interface DisplayMessage {
23 | text: string;
24 | type: 'PROMPT' | 'RESPONSE';
25 | }
26 |
27 | @Component({
28 | standalone: true,
29 | selector: 'app-root',
30 | template: `
31 |
32 |
Firebase 🤝 Palm API 🤝 Angular
33 |
34 |
35 |
36 |
37 |
38 |
43 |
{{ resp.text }}
44 |
45 |
46 |
47 |
48 |
64 |
65 |
{{ status }}
66 |
67 |
68 |
69 | `,
70 | styles: [
71 | `
72 | .prompt-controls {
73 | display: flex;
74 | }
75 | header > h1 {
76 | font-size: 20pt;
77 | }
78 | header {
79 | margin-bottom: 15px;
80 | }
81 | .prompt, .response {
82 | padding: 20px;
83 | max-width: 80%;
84 | border-radius: 10px;
85 | border: solid 5px white;
86 | margin-bottom: 10px;
87 | line-height: 1.5;
88 | }
89 | .prompt {
90 | margin-left: auto;
91 | }
92 | .response {
93 | background: white;
94 | display: flex;
95 | flex-wrap: nowrap;
96 | align-items: center;
97 | }
98 | .responses {
99 | border-radius: 10px;
100 | margin-bottom: 15px;
101 | display: flex;
102 | flex-direction: column;
103 | flex-wrap: nowrap;
104 | justify-content: flex-start;
105 | overflow-y: scroll;
106 | }
107 | .prompt-area {
108 | border-radius: 10px;
109 | }
110 | .prompt-form {
111 | display: flex;
112 | flex-flow: row nowrap;
113 | }
114 | .prompt-input {
115 | flex-grow: 9;
116 | margin-right: 20px;
117 | padding: 20px;
118 | border-radius: 10px;
119 | border: none;
120 | }
121 | .prompt-send-button {
122 | flex-grow: 0;
123 | flex-shrink: 0;
124 | border-radius: 50%;
125 | height: 56px;
126 | width: 56px;
127 | border: 2px solid black;
128 | }
129 | .conversation-window {
130 | padding: 20px;
131 | background: #f3f6fc;
132 | border-radius: 10px;
133 | display: flex;
134 | flex-direction: column;
135 | justify-content: space-between;
136 | height: calc(100vh - 150px);
137 | }
138 | .chatbot-logo {
139 | height: 56px;
140 | width: 56px;
141 | margin-right: 20px;
142 | }
143 | .status-indicator {
144 | padding: 20px;
145 | display: flex;
146 | justify-content: space-evenly
147 | }
148 | `,
149 | ],
150 | imports: [NgFor, NgClass, NgIf],
151 | })
152 | export class AppComponent {
153 | private readonly firestore: Firestore = inject(Firestore);
154 | private readonly discussionCollection = collection(this.firestore, 'discussions');
155 | title = 'palm-api-app';
156 | prompt = '';
157 | status = '';
158 | errorMsg = '';
159 | responses: DisplayMessage[] = [
160 | {
161 | text: "I'm a chatbot powered by the Palm API Firebase Extension and built with Angular.",
162 | type: 'RESPONSE'
163 | }
164 | ];
165 |
166 | async submitPrompt(event: Event, promptText: HTMLInputElement) {
167 | event.preventDefault();
168 |
169 | if (!promptText.value) return;
170 | this.prompt = promptText.value;
171 | promptText.value = '';
172 | this.responses.push({
173 | text: this.prompt,
174 | type: 'PROMPT',
175 | });
176 |
177 | this.status = 'sure, one sec';
178 | const discussionDoc = await addDoc(this.discussionCollection, { prompt: this.prompt });
179 |
180 | const destroyFn = onSnapshot(discussionDoc, {
181 | next: snap => {
182 | const conversation = snap.data();
183 | if (conversation && conversation['status']) {
184 | this.status = 'thinking...';
185 | const state = conversation['status']['state'];
186 |
187 | switch (state) {
188 | case 'COMPLETED':
189 | this.status = '';
190 | this.responses.push({
191 | text: conversation['response'],
192 | type: 'RESPONSE',
193 | });
194 | destroyFn();
195 | break;
196 | case 'PROCESSING':
197 | this.status = 'preparing your answer...';
198 | break;
199 | case 'ERRORED':
200 | this.status = 'Oh no! Something went wrong. Please try again.';
201 | destroyFn();
202 | break;
203 | }
204 | }
205 | },
206 | error: err => {
207 | console.log(err);
208 | this.errorMsg = err.message;
209 | destroyFn();
210 | }
211 | })
212 | }
213 | }
214 |
--------------------------------------------------------------------------------
/src/app/app.config.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | import { importProvidersFrom } from "@angular/core";
18 | import { initializeApp, provideFirebaseApp } from "@angular/fire/app";
19 | import { getFirestore, provideFirestore } from "@angular/fire/firestore";
20 | import { ApplicationConfig } from "@angular/platform-browser";
21 | import { environment } from "src/environments/environment.development";
22 |
23 | const appConfig: ApplicationConfig = {
24 | providers: [
25 | importProvidersFrom(
26 | provideFirebaseApp(() => initializeApp(environment.firebase)),
27 | provideFirestore(() => getFirestore()),
28 | )
29 | ]
30 | };
31 |
32 | export default appConfig;
--------------------------------------------------------------------------------
/src/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FirebaseExtended/palm-chatbot-angular/59f8bcd31bb845065d91b826a71926dbe831bf87/src/assets/.gitkeep
--------------------------------------------------------------------------------
/src/assets/firestore-palm-chatbot-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FirebaseExtended/palm-chatbot-angular/59f8bcd31bb845065d91b826a71926dbe831bf87/src/assets/firestore-palm-chatbot-logo.png
--------------------------------------------------------------------------------
/src/environments/environment.development.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | import { FirebaseOptions } from '@angular/fire/app';
18 |
19 | const devFirebaseConfig = {
20 | // Add the Firebase config object for your web app here
21 | // https://support.google.com/firebase/answer/7015592?hl=en#web&zippy=%2Cin-this-article
22 | };
23 |
24 | export const environment: { firebase: FirebaseOptions } = {
25 | firebase: devFirebaseConfig,
26 | };
27 |
--------------------------------------------------------------------------------
/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | import { FirebaseOptions } from '@angular/fire/app';
18 |
19 | const prodFirebaseConfig = {
20 | // Add the Firebase config object for your web app here
21 | // https://support.google.com/firebase/answer/7015592?hl=en#web&zippy=%2Cin-this-article
22 | };
23 |
24 | export const environment: { firebase: FirebaseOptions } = {
25 | firebase: prodFirebaseConfig,
26 | };
27 |
--------------------------------------------------------------------------------
/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FirebaseExtended/palm-chatbot-angular/59f8bcd31bb845065d91b826a71926dbe831bf87/src/favicon.ico
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 | Palm Api Angular Demo App
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/src/main.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
18 |
19 | import { bootstrapApplication } from '@angular/platform-browser';
20 | import { AppComponent } from './app/app.component';
21 | import appConfig from './app/app.config';
22 |
23 | bootstrapApplication(AppComponent, appConfig);
24 |
--------------------------------------------------------------------------------
/src/styles.css:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 Google LLC
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /* http://meyerweb.com/eric/tools/css/reset/
18 | v2.0 | 20110126
19 | License: none (public domain)
20 | */
21 |
22 | html,
23 | body,
24 | div,
25 | span,
26 | applet,
27 | object,
28 | iframe,
29 | h1,
30 | h2,
31 | h3,
32 | h4,
33 | h5,
34 | h6,
35 | p,
36 | blockquote,
37 | pre,
38 | a,
39 | abbr,
40 | acronym,
41 | address,
42 | big,
43 | cite,
44 | code,
45 | del,
46 | dfn,
47 | em,
48 | img,
49 | ins,
50 | kbd,
51 | q,
52 | s,
53 | samp,
54 | small,
55 | strike,
56 | strong,
57 | sub,
58 | sup,
59 | tt,
60 | var,
61 | b,
62 | u,
63 | i,
64 | center,
65 | dl,
66 | dt,
67 | dd,
68 | ol,
69 | ul,
70 | li,
71 | fieldset,
72 | form,
73 | label,
74 | legend,
75 | table,
76 | caption,
77 | tbody,
78 | tfoot,
79 | thead,
80 | tr,
81 | th,
82 | td,
83 | article,
84 | aside,
85 | canvas,
86 | details,
87 | embed,
88 | figure,
89 | figcaption,
90 | footer,
91 | header,
92 | hgroup,
93 | menu,
94 | nav,
95 | output,
96 | ruby,
97 | section,
98 | summary,
99 | time,
100 | mark,
101 | audio,
102 | video {
103 | margin: 0;
104 | padding: 0;
105 | border: 0;
106 | font-size: 100%;
107 | font: inherit;
108 | vertical-align: baseline;
109 | }
110 |
111 | /* HTML5 display-role reset for older browsers */
112 | article,
113 | aside,
114 | details,
115 | figcaption,
116 | figure,
117 | footer,
118 | header,
119 | hgroup,
120 | menu,
121 | nav,
122 | section {
123 | display: block;
124 | }
125 |
126 | body {
127 | line-height: 1;
128 | }
129 |
130 | ol,
131 | ul {
132 | list-style: none;
133 | }
134 |
135 | blockquote,
136 | q {
137 | quotes: none;
138 | }
139 |
140 | blockquote:before,
141 | blockquote:after,
142 | q:before,
143 | q:after {
144 | content: '';
145 | content: none;
146 | }
147 |
148 | table {
149 | border-collapse: collapse;
150 | border-spacing: 0;
151 | }
152 |
153 | /* You can add global styles to this file, and also import other style files */
154 | /* @import url('https://fonts.googleapis.com/css2?family=Lexend&family=Roboto:ital,wght@0,400;0,700;1,400;1,700&display=swap'); */
155 |
156 | * {
157 | /* font-family: 'Lexend', sans-serif; */
158 | font-family: 'Roboto', sans-serif;
159 | }
160 |
161 | body {
162 | padding: 30px;
163 | font-size: 16px;
164 | }
--------------------------------------------------------------------------------
/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */
2 | {
3 | "extends": "./tsconfig.json",
4 | "compilerOptions": {
5 | "outDir": "./out-tsc/app",
6 | "types": []
7 | },
8 | "files": [
9 | "src/main.ts"
10 | ],
11 | "include": [
12 | "src/**/*.d.ts"
13 | ]
14 | }
15 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */
2 | {
3 | "compileOnSave": false,
4 | "compilerOptions": {
5 | "baseUrl": "./",
6 | "outDir": "./dist/out-tsc",
7 | "forceConsistentCasingInFileNames": true,
8 | "strict": true,
9 | "noImplicitOverride": true,
10 | "noPropertyAccessFromIndexSignature": true,
11 | "noImplicitReturns": true,
12 | "noFallthroughCasesInSwitch": true,
13 | "sourceMap": true,
14 | "declaration": false,
15 | "downlevelIteration": true,
16 | "experimentalDecorators": true,
17 | "moduleResolution": "node",
18 | "importHelpers": true,
19 | "target": "ES2022",
20 | "module": "ES2022",
21 | "useDefineForClassFields": false,
22 | "lib": [
23 | "ES2022",
24 | "dom"
25 | ]
26 | },
27 | "angularCompilerOptions": {
28 | "enableI18nLegacyMessageIdFormat": false,
29 | "strictInjectionParameters": true,
30 | "strictInputAccessModifiers": true,
31 | "strictTemplates": true
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */
2 | {
3 | "extends": "./tsconfig.json",
4 | "compilerOptions": {
5 | "outDir": "./out-tsc/spec",
6 | "types": [
7 | "jasmine"
8 | ]
9 | },
10 | "include": [
11 | "src/**/*.spec.ts",
12 | "src/**/*.d.ts"
13 | ]
14 | }
15 |
--------------------------------------------------------------------------------
/ui-debug.log:
--------------------------------------------------------------------------------
1 | Web / API server started at 127.0.0.1:4000
2 |
--------------------------------------------------------------------------------