Skip to content

Commit 181a3fb

Browse files
committed
Merge branch 'pia-changes2' of https://github.com/pia-papanna/llama-recipes into pia-changes2
2 parents 8dc0578 + c41709a commit 181a3fb

File tree

3 files changed

+28
-30
lines changed

3 files changed

+28
-30
lines changed

recipes/quickstart/finetuning/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ python -m llama_recipes.finetuning --use_peft --peft_method lora --quantization
105105
```
106106
You'll be able to access a dedicated project or run link on [wandb.ai](https://wandb.ai) and see your dashboard like the one below.
107107
<div style="display: flex;">
108-
<img src="../../../docs/img/wandb_screenshot.png" alt="wandb screenshot" width="500" />
108+
<img src="../../../docs/images/wandb_screenshot.png" alt="wandb screenshot" width="500" />
109109
</div>
110110

111111
## FLOPS Counting and Pytorch Profiling

recipes/use_cases/chatbots/messenger_llama/messenger_llama3.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ Messenger from Meta is a messaging service that allows a Facebook business page
1010

1111
The diagram below shows the components and overall data flow of the Llama 3 enabled Messenger chatbot demo we built, using an Amazon EC2 instance as an example for running the web server.
1212

13-
![](../../../../docs/images/messenger_llama_arch.jpg)
13+
![](../../../../docs/img/messenger_llama_arch.jpg)
1414

1515
## Getting Started with Messenger Platform
1616

17-
1. A Facebook Page is required to send and receive messages using the Messenger Platform - see [here](https://www.facebook.com/business/help/461775097570076?id=939256796236247) for details about Facebook Pages and how to create a new page.
17+
1. A Facebook Page is required to send and receive messages using the Messenger Platform - see [here](https://www.facebook.com/business/help/461775097570076?id=939256796236247) for details about Facebook Pages and how to create a new page.
1818

1919
2. If you have followed the [Llama WhatsApp chatbot tutorial](../whatsapp_llama/whatsapp_llama3.md), or if you already have a Meta developer account and a business app, then you can skip this step. Otherwise, you need to first [create a Meta developer account](https://developers.facebook.com/) and then [create a business app](https://developers.facebook.com/docs/development/create-an-app/).
2020

@@ -24,7 +24,7 @@ The diagram below shows the components and overall data flow of the Llama 3 enab
2424

2525
5. Open Messenger's API Settings, as shown in the screenshot below, then in "1. Configure webhooks", set the Callback URL and Verify Token set up in the previous step, and subscribe all message related fields for "Webhook Fields". Finally, in "2. Generate access tokens", connect your Facebook page (see step 1) and copy your page access token for later use.
2626

27-
![](../../../../docs/images/messenger_api_settings.png)
27+
![](../../../../docs/img/messenger_api_settings.png)
2828

2929
## Writing Llama 3 Enabled Web App
3030

@@ -54,7 +54,7 @@ import os
5454
import requests
5555
import json
5656
57-
os.environ["REPLICATE_API_TOKEN"] = "<your replicate api token"
57+
os.environ["REPLICATE_API_TOKEN"] = "<your replicate api token"
5858
llama3_8b_chat = "meta/meta-llama-3-8b-instruct"
5959
6060
llm = Replicate(
@@ -65,7 +65,7 @@ llm = Replicate(
6565
app = Flask(__name__)
6666
6767
@app.route('/msgrcvd_page', methods=['POST', 'GET'])
68-
def msgrcvd_page():
68+
def msgrcvd_page():
6969
message = request.args.get('message')
7070
sender = request.args.get('sender')
7171
recipient = request.args.get('recipient')
@@ -89,7 +89,7 @@ def msgrcvd_page():
8989

9090
Replace <page_access_token> with the access token copied in step 5 "Open Messenger's API Settings" of the previous section. Now it's time to modify the webhook to complete the whole app.
9191

92-
## Modifying the Webhook
92+
## Modifying the Webhook
9393

9494
Open your glitch.com webhook URL created earlier, and change your `app.js` to simply forward the user message and the user and page ids sent by the Messenger Platform to the Llama 3 enabled web app `llama_messenger.py` described in the previous section:
9595

@@ -110,7 +110,7 @@ app.listen(process.env.PORT || 1337, () => console.log("webhook is listening"));
110110
app.post("/webhook", (req, res) => {
111111
// Parse the request body from the POST
112112
let body = req.body;
113-
113+
114114
let sender = req.body["entry"][0]["messaging"][0]['sender']['id']
115115
let recipient = req.body["entry"][0]["messaging"][0]['recipient']['id']
116116
let message = req.body["entry"][0]["messaging"][0]['message']['text']
@@ -119,10 +119,10 @@ app.post("/webhook", (req, res) => {
119119
if (body.object === "page") {
120120
// Returns a '200 OK' response to all requests
121121
res.status(200).send("EVENT_RECEIVED");
122-
122+
123123
let url = "http://<web server public IP>:5000/msgrcvd_page?sender=" + sender + "&recipient=" + recipient + "&message=" + encodeURIComponent(message)
124124
console.log(url)
125-
125+
126126
axios.get(url)
127127
.then(response => {
128128
// Handle the response data
@@ -131,15 +131,15 @@ app.post("/webhook", (req, res) => {
131131
.catch(error => {
132132
// Handle errors
133133
console.error('Axios error:', error);
134-
});
134+
});
135135
} else {
136136
// Return a '404 Not Found' if event is not from a page subscription
137137
res.sendStatus(404);
138138
}
139139
});
140140
141141
// Accepts GET requests at the /webhook endpoint. You need this URL to setup webhook initially.
142-
// info on verification request payload: https://developers.facebook.com/docs/graph-api/webhooks/getting-started#verification-requests
142+
// info on verification request payload: https://developers.facebook.com/docs/graph-api/webhooks/getting-started#verification-requests
143143
app.get("/webhook", (req, res) => {
144144
/**
145145
* UPDATE YOUR VERIFY TOKEN
@@ -179,7 +179,7 @@ On your web server, run the following command on a Terminal (see [here](https://
179179
gunicorn -b 0.0.0.0:5000 llama_messenger:app
180180
```
181181

182-
If you use Amazon EC2 as your web server, make sure you have port 5000 added to your EC2 instance's security group's inbound rules.
182+
If you use Amazon EC2 as your web server, make sure you have port 5000 added to your EC2 instance's security group's inbound rules.
183183

184184
Now you can open your Messenger app, select the Facebook page you connected in Messenger's API Settings, enter a message and receive the Llama 3's answer shortly, as shown in the demo video in the beginning of this post.
185185

@@ -190,5 +190,3 @@ http://<web server public IP>:5000/msgrcvd_page?sender=<user id>&recipient=<page
190190
```
191191

192192
Then open the URL in a browser to verify your web server can receive the message and the two ids, and generate a Llama answer before sending the answer back to Messenger.
193-
194-

recipes/use_cases/chatbots/whatsapp_llama/whatsapp_llama3.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Businesses of all sizes can use the [WhatsApp Business API](https://developers.f
1010

1111
The diagram below shows the components and overall data flow of the Llama 3 enabled WhatsApp chatbot demo we built, using Amazon EC2 instance as an example for running the web server.
1212

13-
![](../../../../docs/images/whatsapp_llama_arch.jpg)
13+
![](../../../../docs/img/whatsapp_llama_arch.jpg)
1414

1515
## Getting Started with WhatsApp Business Cloud API
1616

@@ -19,13 +19,13 @@ First, open the [WhatsApp Business Platform Cloud API Get Started Guide](https:/
1919
1. Add the WhatsApp product to your business app;
2020
2. Add a recipient number;
2121
3. Send a test message;
22-
4. Configure a webhook to receive real time HTTP notifications.
22+
4. Configure a webhook to receive real time HTTP notifications.
2323

2424
For the last step, you need to further follow the [Sample Callback URL for Webhooks Testing Guide](https://developers.facebook.com/docs/whatsapp/sample-app-endpoints) to create a free account on glitch.com to get your webhook's callback URL.
2525

26-
Now open the [Meta for Develops Apps](https://developers.facebook.com/apps/) page and select the WhatsApp business app and you should be able to copy the curl command (as shown in the App Dashboard - WhatsApp - API Setup - Step 2 below) and run the command on a Terminal to send a test message to your WhatsApp.
26+
Now open the [Meta for Develops Apps](https://developers.facebook.com/apps/) page and select the WhatsApp business app and you should be able to copy the curl command (as shown in the App Dashboard - WhatsApp - API Setup - Step 2 below) and run the command on a Terminal to send a test message to your WhatsApp.
2727

28-
![](../../../../docs/images/whatsapp_dashboard.jpg)
28+
![](../../../../docs/img/whatsapp_dashboard.jpg)
2929

3030
Note down the "Temporary access token", "Phone number ID", and "a recipient phone number" in the API Setup page above, which will be used later.
3131

@@ -63,7 +63,7 @@ class WhatsAppClient:
6363
"Content-Type": "application/json",
6464
}
6565
self.API_URL = self.API_URL + self.WHATSAPP_CLOUD_NUMBER_ID
66-
66+
6767
def send_text_message(self, message, phone_number):
6868
payload = {
6969
"messaging_product": 'whatsapp',
@@ -82,9 +82,9 @@ Finally, add the code below to llama_chatbot.py, which creates a Llama 3 instanc
8282
1. receive the user message forwarded by the webhook;
8383
2. ask Llama 3 for the answer;
8484
3. call the `WhatsAppClient`'s `send_text_message`` with a recipient's phone number.
85-
86-
```
87-
os.environ["REPLICATE_API_TOKEN"] = "<your replicate api token>"
85+
86+
```
87+
os.environ["REPLICATE_API_TOKEN"] = "<your replicate api token>"
8888
llama3_8b_chat = "meta/meta-llama-3-8b-instruct"
8989
9090
llm = Replicate(
@@ -99,7 +99,7 @@ def hello_llama():
9999
return "<p>Hello Llama 3</p>"
100100
101101
@app.route('/msgrcvd', methods=['POST', 'GET'])
102-
def msgrcvd():
102+
def msgrcvd():
103103
message = request.args.get('message')
104104
answer = llm(message)
105105
client.send_text_message(answer, "<a recipient phone number from your WhatsApp API Setup>")
@@ -110,19 +110,19 @@ The complete script of llama_chatbot.py is [here](llama_chatbot.py).
110110

111111
Now it's time to modify the webhook to complete the whole app.
112112

113-
## Modifying the Webhook
113+
## Modifying the Webhook
114114

115115
Open your glitch.com webhook URL created earlier, and after the code snippet in app.js:
116116

117117
```
118-
// message received!
118+
// message received!
119119
console.log(req.body["entry"][0]["changes"][0]["value"]["messages"][0]["text"]["body"]);
120120
```
121121

122122
add the code below - remember to change <web server public IP>, which needs to be publicly visible, to the IP of the server where your Llama 3 enabled web app in the previous section runs:
123123

124124
```
125-
let url = "http://<web server public IP>:5000/msgrcvd?message=" +
125+
let url = "http://<web server public IP>:5000/msgrcvd?message=" +
126126
req.body["entry"][0]["changes"][0]["value"]["messages"][0]["text"]["body"]
127127
128128
axios.get(url)
@@ -140,7 +140,7 @@ The code simply forwards the user message received by the WhatsApp Cloud Platfor
140140
'// info on WhatsApp text message payload: https://developers.facebook.com/docs/whatsapp/cloud-api/webhooks/payload-examples#text-messages
141141
if (req.body.object) {
142142
...
143-
}
143+
}
144144
```
145145

146146
Note: It's possible and even recommended to implement a webhook in Python and call Llama 3 directly inside the webhook, instead of making an HTTP request, as the JavaScript code above does, to a Python app which calls Llama 3 and sends the answer to WhatsApp.
@@ -153,10 +153,10 @@ On your web server, run the following command on a Terminal:
153153
gunicorn -b 0.0.0.0:5000 llama_chatbot:app
154154
```
155155

156-
If you use Amazon EC2 as your web server, make sure you have port 5000 added to your EC2 instance's security group's inbound rules. Write down your web server's public IP, update the URL below with it, then open the URL in a browser to verify you can see the answer sent to your WhatsApp app, as well as shown in the browser:
156+
If you use Amazon EC2 as your web server, make sure you have port 5000 added to your EC2 instance's security group's inbound rules. Write down your web server's public IP, update the URL below with it, then open the URL in a browser to verify you can see the answer sent to your WhatsApp app, as well as shown in the browser:
157157

158158
```
159159
http://<web server public IP>:5000/msgrcvd?message=who%20wrote%20the%20book%20godfather
160160
```
161161

162-
Now you can open your WhatsApp app, enter a question and receive the Llama 3's answer shortly, as shown in the demo video in the beginning of this post.
162+
Now you can open your WhatsApp app, enter a question and receive the Llama 3's answer shortly, as shown in the demo video in the beginning of this post.

0 commit comments

Comments
 (0)