Skip to content

Commit 4fa6d0f

Browse files
authored
Merge pull request #1502 from microsoft/softchris-patch-5
docs: adding room for pivot for AI project
2 parents 1230bc7 + e545305 commit 4fa6d0f

File tree

7 files changed

+77
-45
lines changed

7 files changed

+77
-45
lines changed

9-chat-project/README.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ As we said, select the "Code" tab and your chosen runtime.
2525
<img src="./assets/playground-choice.png" alt="playground choice" with="600">
2626
</div>
2727

28+
### Using Python
29+
2830
In this case we select Python, which will mean we pick this code:
2931

3032
```python
@@ -100,6 +102,8 @@ call_llm("Tell me about you", "You're Albert Einstein, you only know of things i
100102

101103
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:
102104

105+
### Using Python
106+
103107
```python
104108
# api.py
105109
from flask import Flask, request, jsonify
@@ -168,9 +172,13 @@ To integrate *llm.py* here's what we need to do:
168172

169173
Great, now we have done what we need.
170174

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.
172178

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:
174182

175183
```python
176184
from flask_cors import CORS
@@ -183,6 +191,10 @@ Right now it's been set up to allow "*" which is all origins and that's a bit un
183191

184192
## Run your project
185193

194+
To run your project, you need to start up your backend first and then your frontend.
195+
196+
### Using Python
197+
186198
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:
187199

188200
- Install dependencies:
@@ -338,8 +350,7 @@ project/
338350
app.js
339351
styles.css
340352
backend/
341-
api.py
342-
llm.py
353+
...
343354
```
344355
345356
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
350361
351362
## Bonus
352363
353-
Try changing the personality of the AI assistant. 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:
354369
355370
```python
356371
call_llm(message, "You are Captain Picard")
357372
```
358373
374+
### Frontend
375+
359376
Change also the CSS and text to your liking, so do changes in *index.html* and *styles.css*.
360377
361378
## Summary

9-chat-project/solution/README.md

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,4 @@
1-
# Run code
1+
# Run solution
22

3-
## Set up
4-
5-
Create virtual environment
6-
7-
```sh
8-
cd backend
9-
python -m venv venv
10-
source ./venv/bin/activate
11-
```
12-
13-
## Install dependencies
14-
15-
```sh
16-
pip install openai flask flask-cors
17-
```
18-
19-
## Run API
20-
21-
```sh
22-
python api.py
23-
```
24-
25-
## Run frontend
26-
27-
Make sure you stand in the frontend folder
28-
29-
Locate *app.js*, change `BASE_URL` to that of your backend URL
30-
31-
Run it
32-
33-
```
34-
npx http-server -p 8000
35-
```
36-
37-
Try typing a message in the chat, you should see a response (providing you're running this in a Codespace or have set up a access token).
38-
39-
## Set up access token (if you don't run this in a Codespace)
40-
41-
See [Set up PAT](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)
3+
1. Start up the [backend](./backend/README.md)
4+
1. Now start the [fronten](./frontend/README.md)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Choose your runtime
2+
3+
- [Python](./python/README.md)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Run code
2+
3+
4+
5+
## Set up
6+
7+
Create virtual environment
8+
9+
```sh
10+
python -m venv venv
11+
source ./venv/bin/activate
12+
```
13+
14+
## Install dependencies
15+
16+
```sh
17+
pip install openai flask flask-cors
18+
```
19+
20+
## Run API
21+
22+
```sh
23+
python api.py
24+
```
25+
26+
## Run frontend
27+
28+
Make sure you stand in the frontend folder
29+
30+
Locate *app.js*, change `BASE_URL` to that of your backend URL
31+
32+
Run it
33+
34+
```
35+
npx http-server -p 8000
36+
```
37+
38+
Try typing a message in the chat, you should see a response (providing you're running this in a Codespace or have set up a access token).
39+
40+
## Set up access token (if you don't run this in a Codespace)
41+
42+
See [Set up PAT](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)
File renamed without changes.
File renamed without changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Run the code
2+
3+
```sh
4+
npx http-server -p 3000
5+
```
6+
7+
Locate the `BASE_URL` in `app.js` and change it match the URL of the backend.

0 commit comments

Comments
 (0)