├── .env-example
├── .eslintrc.cjs
├── .gitignore
├── .prettierrc.json
├── .vscode
└── extensions.json
├── LICENSE.txt
├── README.md
├── index.html
├── package-lock.json
├── package.json
├── postcss.config.js
├── public
└── ask.svg
├── server.js
├── src
├── App.vue
├── assets
│ ├── demo.png
│ └── index.css
├── components
│ ├── ChatWindowAudio.vue
│ ├── ChatWindowImage.vue
│ ├── Loading.vue
│ ├── Transcriber.vue
│ └── Uploader.vue
├── main.js
├── router
│ └── index.js
├── stores
│ ├── audioChat.js
│ ├── imageChat.js
│ ├── textChat.js
│ └── tokenize.js
└── views
│ ├── AudioView.vue
│ ├── HomeView.vue
│ ├── ImageView.vue
│ └── TextView.vue
├── tailwind.config.js
└── vite.config.js
/.env-example:
--------------------------------------------------------------------------------
1 | OPENAI_API_KEY=""
2 | DG_API=""
3 | REPLICATE=""
--------------------------------------------------------------------------------
/.eslintrc.cjs:
--------------------------------------------------------------------------------
1 | /* eslint-env node */
2 | require('@rushstack/eslint-patch/modern-module-resolution')
3 |
4 | module.exports = {
5 | root: true,
6 | 'extends': [
7 | 'plugin:vue/vue3-essential',
8 | 'eslint:recommended',
9 | '@vue/eslint-config-prettier/skip-formatting'
10 | ],
11 | parserOptions: {
12 | ecmaVersion: 'latest'
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .env
2 |
3 | # Logs
4 | logs
5 | *.log
6 | npm-debug.log*
7 | yarn-debug.log*
8 | yarn-error.log*
9 | pnpm-debug.log*
10 | lerna-debug.log*
11 |
12 | node_modules
13 | .DS_Store
14 | dist
15 | dist-ssr
16 | coverage
17 | *.local
18 |
19 | /cypress/videos/
20 | /cypress/screenshots/
21 |
22 | # Editor directories and files
23 | .vscode/*
24 | !.vscode/extensions.json
25 | .idea
26 | *.suo
27 | *.ntvs*
28 | *.njsproj
29 | *.sln
30 | *.sw?
31 |
--------------------------------------------------------------------------------
/.prettierrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://json.schemastore.org/prettierrc",
3 | "semi": false,
4 | "tabWidth": 2,
5 | "singleQuote": true,
6 | "printWidth": 100,
7 | "trailingComma": "none"
8 | }
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
3 | }
4 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 Sandra Rodgers
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AI-Powered-App
2 |
3 | 
4 |
5 | This is a project that demonstrates how to use several AI technologies:
6 |
7 | - OpenAI chat completion API
8 | - Deepgram speech-to-text API
9 | - Replicate API to run the miniGPT vision encoder model
10 | - gpt-3-encoder package to tokenize strings into tokens (which are used to set limits on the length of prompts sent to OpenAI)
11 | - Langchain model, chain, and memory interfaces
12 |
13 | ## Get it Working
14 |
15 | To see this project working, you can clone the project and then do the following.
16 |
17 | ### Install dependencies
18 |
19 | ```
20 | npm install
21 | ```
22 |
23 | ### Create .env file
24 |
25 | Create a `.env` file at the root of the project and then go into the `.gitignore` file and add `.env` to the list. This will make sure that the `.env` file does not get pushed up to github if you choose to push the project up to github.
26 |
27 | ## API Keys
28 |
29 | Add API keys to the `.env` file as you see in the `.env-example` file. Go to each of these websites to sign up for an API key:
30 |
31 | [OpenAI](https://platform.openai.com/signup)
32 |
33 | [Deepgram](https://dpgr.am/deepgram-signup)
34 |
35 | [Replicate](https://replicate.com/)
36 |
37 | ### Run the web server and the node server
38 |
39 | ```
40 | npm run start
41 | ```
42 |
43 | ### To see the Langchain features, switch to the `langchain` branch
44 |
45 | ```
46 | git checkout langchain
47 | ```
48 |
49 | ### To see the starter code before the features have been added, switch to the `starting-code` branch
50 |
51 | ```
52 | git checkout starting-code
53 | ```
54 |
55 | ### To see starting code and ending code for each chapter, switch to the chapter number + "start" or "end"
56 |
57 | ```
58 | git checkout 03-start
59 | git checkout 03-end
60 | ```
61 |
62 | ### Questions
63 |
64 | If you have any questions, you can reach out to me on [twitter](https://twitter.com/sandra_rodgers_)
65 |
66 | # December 2024 Updates
67 |
68 | Updates were made in December 2024 due to breaking changes to the OpenAI, Deepgram, and Replicate APIs. These are explanations of the changes that were made.
69 |
70 | ## Open AI updates
71 |
72 | Code was updated to use the new way of creating the openai client. You can see a diff at https://github.com/SandraRodgers/Ask-AI/commit/9cce3610593391d45739966072224b812f1d2232.
73 |
74 | These updates were made to branches `main`, `langchain`, `03-end`, `04-start`, `04-end`, `05-start`, `05-end`, `06-start`, `06-end`, `07-start`, `07-end`, `08-start`, `08-end`, `09-start`, `09-end` (so all branches except for `03-start`)
75 |
76 | Lesson 3 in the video course will need to be updated to present this new way of creating the openai client.There is also one example in lesson two that presents a snippet of the code (see the section "Request Prompt Format")
77 |
78 | ### Code changes
79 |
80 | 1. Updated to version `^4.71.1`
81 | 2. Updated openai config in `server.js`:
82 |
83 | ```js
84 | ////// OpenAI config //////
85 | const { OpenAI } = require('openai')
86 |
87 | const client = new OpenAI({
88 | apiKey: process.env.OPENAI_API_KEY
89 | })
90 |
91 | // OpenAI chat completion
92 | app.post('/chat', async (req, res) => {
93 | const messages = req.body.messages
94 | console.log(messages)
95 | try {
96 | if (messages == null) {
97 | throw new Error('We have a problem - no prompt was provided')
98 | }
99 |
100 | const response = await client.chat.completions.create({
101 | model: 'gpt-3.5-turbo',
102 | messages
103 | })
104 | const completion = response.choices[0].message
105 | console.dir(response.choices[0], { depth: 4 })
106 | return res.status(200).json({
107 | success: true,
108 | message: completion
109 | })
110 | } catch (error) {
111 | console.log(error.message)
112 | }
113 | })
114 | ```
115 |
116 | ## Deepgram updates
117 |
118 | Code was updated to use the new way of creating the deepgram client. You can see a diff at https://github.com/SandraRodgers/Ask-AI/commit/e2df40f043662ff44747f8d938f41b540ee1d52b
119 |
120 | These updates were made to branches `main`, `langchain`,`05-end`, `06-start`, `06-end`, `07-start`, `07-end`, `08-start`, `08-end`, `09-start`, `09-end` (so all branches except for `03-start`, `04-start`, `04-end`)
121 |
122 | Lesson 5 in the video course will need to be updated to present this new way of creating the deepgram client.
123 |
124 | ### Code changes
125 |
126 | 1. Updated to version `^3.9.0`
127 | 2. Updated deepgram config in `server.js`:
128 |
129 | ```js
130 | ////// Deepgram config //////
131 | const { createClient } = require('@deepgram/sdk')
132 | const deepgram = createClient(process.env.DG_API)
133 |
134 | // Deepgram transcription
135 | app.post('/dg-transcription', upload.single('file'), async (req, res) => {
136 | try {
137 | console.log(req.file)
138 | if (!req.file) {
139 | return res.status(400).send('No file uploaded')
140 | }
141 |
142 | const audioBuffer = req.file.buffer
143 |
144 | const response = await deepgram.listen.prerecorded.transcribeFile(audioBuffer, {
145 | punctuate: true,
146 | model: 'nova-2'
147 | })
148 |
149 | console.dir(response, { depth: 4 })
150 |
151 | res.send({ transcript: response.result })
152 | } catch (e) {
153 | console.error('Error:', e)
154 | res.status(500).send('An error occurred during transcription')
155 | }
156 | })
157 | ```
158 |
159 | ## Langchain updates
160 |
161 | Code was updated to use the new way of creating the langchain-openai client (just two lines of code). You can see a diff at https://github.com/SandraRodgers/Ask-AI/commit/55b2c88ae3701647ca224376bc11bdbca41ff381
162 |
163 | These updates were made to branches `langchain`, `07-end`, `08-start`, `08-end`, `09-start`, `09-end`
164 |
165 | Lesson 7 in the video course will need to be updated to present this new way of creating the langchain-openai client. However, it's a very small change.
166 |
167 | The change adds `const { OpenAI: OpenAIClient } = require('@langchain/openai')`, and the reason that we add the `: OpenAIClient` is so that we can use a different name from the openai client used higher up in the same file. Thus when we instantiate the model, we can do: `const model = new OpenAIClient({}) `
168 |
169 | ### Code changes
170 |
171 | 1. Updated to version `^0.0.299`
172 | 2. Updated `server.js`
173 |
174 | ```js
175 | ////// LangChain Config //////
176 | const { OpenAI: OpenAIClient } = require('@langchain/openai')
177 | const { BufferMemory } = require('langchain/memory')
178 | const { ConversationChain } = require('langchain/chains')
179 |
180 | // Specify the model here
181 | const model = new OpenAIClient({})
182 | const memory = new BufferMemory()
183 | const chain = new ConversationChain({ llm: model, memory: memory })
184 | let chainNum = 0
185 | ```
186 |
187 | ## Replicate updates
188 |
189 | Code was updated because the model id for minigpt-4 had changed. See a diff at: https://github.com/SandraRodgers/Ask-AI/commit/0775a8537d046475877c8b85b8d9c1e34ab2633d
190 |
191 | These updates were made to branches `main`, `08-end`, `09-start`, `09-end`.
192 |
193 | Lesson 8 and 9 in the video course (server.js section) will need to be updated with the new model id.
194 |
195 | ### Code changes
196 |
197 | 1. Update `server.js`
198 |
199 | ```js
200 | const miniGPT =
201 | 'daanelson/minigpt-4:e447a8583cffd86ce3b93f9c2cd24f2eae603d99ace6afa94b33a08e94a3cd06'
202 | ```
203 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |