Explorar o código

Merge branch 'pia-changes2' of https://github.com/pia-papanna/llama-recipes into pia-changes2

Pia Papanna hai 9 meses
pai
achega
181a3fb68e

+ 1 - 1
recipes/quickstart/finetuning/README.md

@@ -105,7 +105,7 @@ python -m llama_recipes.finetuning --use_peft --peft_method lora --quantization
 ```
 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.
 <div style="display: flex;">
-    <img src="../../../docs/img/wandb_screenshot.png" alt="wandb screenshot" width="500" />
+    <img src="../../../docs/images/wandb_screenshot.png" alt="wandb screenshot" width="500" />
 </div>
 
 ## FLOPS Counting and Pytorch Profiling

+ 12 - 14
recipes/use_cases/chatbots/messenger_llama/messenger_llama3.md

@@ -10,11 +10,11 @@ Messenger from Meta is a messaging service that allows a Facebook business page
 
 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.
 
-![](../../../../docs/images/messenger_llama_arch.jpg)
+![](../../../../docs/img/messenger_llama_arch.jpg)
 
 ## Getting Started with Messenger Platform
 
-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. 
+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.
 
 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/).
 
@@ -24,7 +24,7 @@ The diagram below shows the components and overall data flow of the Llama 3 enab
 
 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.
 
-![](../../../../docs/images/messenger_api_settings.png)
+![](../../../../docs/img/messenger_api_settings.png)
 
 ## Writing Llama 3 Enabled Web App
 
@@ -54,7 +54,7 @@ import os
 import requests
 import json
 
-os.environ["REPLICATE_API_TOKEN"] = "<your replicate api token"    
+os.environ["REPLICATE_API_TOKEN"] = "<your replicate api token"
 llama3_8b_chat = "meta/meta-llama-3-8b-instruct"
 
 llm = Replicate(
@@ -65,7 +65,7 @@ llm = Replicate(
 app = Flask(__name__)
 
 @app.route('/msgrcvd_page', methods=['POST', 'GET'])
-def msgrcvd_page():    
+def msgrcvd_page():
     message = request.args.get('message')
     sender = request.args.get('sender')
     recipient = request.args.get('recipient')
@@ -89,7 +89,7 @@ def msgrcvd_page():
 
 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.
 
-## Modifying the Webhook 
+## Modifying the Webhook
 
 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:
 
@@ -110,7 +110,7 @@ app.listen(process.env.PORT || 1337, () => console.log("webhook is listening"));
 app.post("/webhook", (req, res) => {
   // Parse the request body from the POST
   let body = req.body;
-  
+
   let sender = req.body["entry"][0]["messaging"][0]['sender']['id']
   let recipient = req.body["entry"][0]["messaging"][0]['recipient']['id']
   let message = req.body["entry"][0]["messaging"][0]['message']['text']
@@ -119,10 +119,10 @@ app.post("/webhook", (req, res) => {
   if (body.object === "page") {
     // Returns a '200 OK' response to all requests
     res.status(200).send("EVENT_RECEIVED");
-    
+
     let url = "http://<web server public IP>:5000/msgrcvd_page?sender=" + sender + "&recipient=" + recipient + "&message=" + encodeURIComponent(message)
     console.log(url)
-  
+
     axios.get(url)
       .then(response => {
         // Handle the response data
@@ -131,7 +131,7 @@ app.post("/webhook", (req, res) => {
       .catch(error => {
         // Handle errors
         console.error('Axios error:', error);
-      });    
+      });
     } else {
       // Return a '404 Not Found' if event is not from a page subscription
       res.sendStatus(404);
@@ -139,7 +139,7 @@ app.post("/webhook", (req, res) => {
   });
 
 // Accepts GET requests at the /webhook endpoint. You need this URL to setup webhook initially.
-// info on verification request payload: https://developers.facebook.com/docs/graph-api/webhooks/getting-started#verification-requests 
+// info on verification request payload: https://developers.facebook.com/docs/graph-api/webhooks/getting-started#verification-requests
 app.get("/webhook", (req, res) => {
   /**
    * UPDATE YOUR VERIFY TOKEN
@@ -179,7 +179,7 @@ On your web server, run the following command on a Terminal (see [here](https://
 gunicorn -b 0.0.0.0:5000 llama_messenger:app
 ```
 
-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. 
+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.
 
 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.
 
@@ -190,5 +190,3 @@ http://<web server public IP>:5000/msgrcvd_page?sender=<user id>&recipient=<page
 ```
 
 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.
-
-

+ 15 - 15
recipes/use_cases/chatbots/whatsapp_llama/whatsapp_llama3.md

@@ -10,7 +10,7 @@ Businesses of all sizes can use the [WhatsApp Business API](https://developers.f
 
 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.
 
-![](../../../../docs/images/whatsapp_llama_arch.jpg)
+![](../../../../docs/img/whatsapp_llama_arch.jpg)
 
 ## Getting Started with WhatsApp Business Cloud API
 
@@ -19,13 +19,13 @@ First, open the [WhatsApp Business Platform Cloud API Get Started Guide](https:/
 1. Add the WhatsApp product to your business app;
 2. Add a recipient number;
 3. Send a test message;
-4. Configure a webhook to receive real time HTTP notifications. 
+4. Configure a webhook to receive real time HTTP notifications.
 
 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.
 
-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. 
+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.
 
-![](../../../../docs/images/whatsapp_dashboard.jpg)
+![](../../../../docs/img/whatsapp_dashboard.jpg)
 
 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.
 
@@ -63,7 +63,7 @@ class WhatsAppClient:
             "Content-Type": "application/json",
         }
         self.API_URL = self.API_URL + self.WHATSAPP_CLOUD_NUMBER_ID
-        
+
     def send_text_message(self, message, phone_number):
         payload = {
             "messaging_product": 'whatsapp',
@@ -82,9 +82,9 @@ Finally, add the code below to llama_chatbot.py, which creates a Llama 3 instanc
 1. receive the user message forwarded by the webhook;
 2. ask Llama 3 for the answer;
 3. call the `WhatsAppClient`'s `send_text_message`` with a recipient's phone number.
-   
-```   
-os.environ["REPLICATE_API_TOKEN"] = "<your replicate api token>"    
+
+```
+os.environ["REPLICATE_API_TOKEN"] = "<your replicate api token>"
 llama3_8b_chat = "meta/meta-llama-3-8b-instruct"
 
 llm = Replicate(
@@ -99,7 +99,7 @@ def hello_llama():
     return "<p>Hello Llama 3</p>"
 
 @app.route('/msgrcvd', methods=['POST', 'GET'])
-def msgrcvd():    
+def msgrcvd():
     message = request.args.get('message')
     answer = llm(message)
     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).
 
 Now it's time to modify the webhook to complete the whole app.
 
-## Modifying the Webhook 
+## Modifying the Webhook
 
 Open your glitch.com webhook URL created earlier, and after the code snippet in app.js:
 
 ```
-// message received! 
+// message received!
 console.log(req.body["entry"][0]["changes"][0]["value"]["messages"][0]["text"]["body"]);
 ```
 
 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:
 
 ```
-  let url = "http://<web server public IP>:5000/msgrcvd?message=" + 
+  let url = "http://<web server public IP>:5000/msgrcvd?message=" +
     req.body["entry"][0]["changes"][0]["value"]["messages"][0]["text"]["body"]
 
   axios.get(url)
@@ -140,7 +140,7 @@ The code simply forwards the user message received by the WhatsApp Cloud Platfor
   '// info on WhatsApp text message payload: https://developers.facebook.com/docs/whatsapp/cloud-api/webhooks/payload-examples#text-messages
   if (req.body.object) {
     ...
-  }    
+  }
 ```
 
 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:
 gunicorn -b 0.0.0.0:5000 llama_chatbot:app
 ```
 
-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: 
+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:
 
 ```
 http://<web server public IP>:5000/msgrcvd?message=who%20wrote%20the%20book%20godfather
 ```
 
-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.
+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.