You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this case we select Python, which will mean we pick this code:
29
31
30
32
```python
@@ -100,6 +102,8 @@ call_llm("Tell me about you", "You're Albert Einstein, you only know of things i
100
102
101
103
Great, we have an AI part done, let's see how we can integrate that into a Web API. For the Web API, we're choosing to use Flask, but any web framework should be good. Let's see the code for it:
102
104
105
+
### Using Python
106
+
103
107
```python
104
108
# api.py
105
109
from flask import Flask, request, jsonify
@@ -168,9 +172,13 @@ To integrate *llm.py* here's what we need to do:
168
172
169
173
Great, now we have done what we need.
170
174
171
-
### Configure Cors
175
+
## Configure Cors
176
+
177
+
We should call out that we set up something like CORS, cross-origin resource sharing. This means that because our backend and frontend will ron on different ports, we need to allow the frontend to call into the backend.
172
178
173
-
We should call out that we set up something like CORS, cross-origin resource sharing. This means that because our backend and frontend will ron on different ports, we need to allow the frontend to call into the backend. There's a piece of code in *api.py* that sets this up:
179
+
### Using Python
180
+
181
+
There's a piece of code in *api.py* that sets this up:
174
182
175
183
```python
176
184
from flask_cors importCORS
@@ -183,6 +191,10 @@ Right now it's been set up to allow "*" which is all origins and that's a bit un
183
191
184
192
## Run your project
185
193
194
+
To run your project, you need to start up your backend first and then your frontend.
195
+
196
+
### Using Python
197
+
186
198
Ok, so we have *llm.py* and *api.py*, how can we make this work with a backend? Well, there's two things we need to do:
187
199
188
200
- Install dependencies:
@@ -338,8 +350,7 @@ project/
338
350
app.js
339
351
styles.css
340
352
backend/
341
-
api.py
342
-
llm.py
353
+
...
343
354
```
344
355
345
356
Copy the content from what was instructed from above but feel free to customize to your liking
@@ -350,12 +361,18 @@ Copy the content from what was instructed from above but feel free to customize
350
361
351
362
## Bonus
352
363
353
-
Try changing the personality of the AIassistant. When you call `call_llm`in*api.py* you can change the second argument to what you want, for example:
364
+
Try changing the personality of the AI assistant.
365
+
366
+
### For Python
367
+
368
+
When you call `call_llm`in*api.py* you can change the second argument to what you want, for example:
354
369
355
370
```python
356
371
call_llm(message, "You are Captain Picard")
357
372
```
358
373
374
+
### Frontend
375
+
359
376
Change also the CSS and text to your liking, so do changes in*index.html* and *styles.css*.
0 commit comments