Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Messenger Llama2 Chatbot Tutorial #311

Merged
merged 10 commits into from
Dec 15, 2023
Merged

Conversation

jeffxtang
Copy link
Contributor

What does this PR do?

This step-by-step tutorial shows the complete process of building a Llama-enabled Messenger chatbot. A demo video of using the iOS Messenger app to send a question to a Facebook page and receive the Llama 2 generated answer is here.

Fixes # (issue)

Feature/Issue validation/testing

Please describe the tests that you ran to verify your changes and relevant result summary. Provide instructions so it can be reproduced.
Please also list any relevant details for your test configuration.

  • Test A
    Logs for Test A

  • Test B
    Logs for Test B

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

Thanks for contributing 🎉!

@jeffxtang jeffxtang marked this pull request as draft December 6, 2023 01:38
@jeffxtang jeffxtang marked this pull request as ready for review December 6, 2023 19:40
Copy link
Contributor

@mreso mreso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great example, left some inline comments

demo_apps/llama_messenger.py Outdated Show resolved Hide resolved
demo_apps/llama_messenger.py Outdated Show resolved Hide resolved
@@ -0,0 +1,192 @@
# Building a Llama-enabled Messenger Chatbot

This step-by-step tutorial shows the complete process of building a Llama-enabled Messenger chatbot. A demo video of using the iOS Messenger app to send a question to a Facebook business page and receive the Llama 2 generated answer is [here](https://drive.google.com/file/d/1B4ijFH4X3jEHZfkGdTPmdsgpUes_RNud/view).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is google drive the best way to share this video?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the easiest for me and I've been using gdrive mainly. Any suggestion on a better way?

demo_apps/messenger_llama2.md Outdated Show resolved Hide resolved
demo_apps/messenger_llama2.md Outdated Show resolved Hide resolved

## 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 2 enabled web app `llama_messenger.py` described in the previous section:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of the web hook needed if it just forwards the message? Can the messenger platform not be used to send the message directly to the web app?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally the webhook should do what the web app does, or the other way around. But I haven't simplified this yet, and am just using the WhatsApp/Messenger doc to set up a JS based webhook, which then calls the Python web app to invoke Llama. I did mention this in https://github.com/facebookresearch/llama-recipes/blob/main/demo_apps/whatsapp_llama2.md:

Note: It's possible and even recommended to implement a webhook in Python and call the Llama directly inside the webhook, instead of making an HTTP request, as the JavaScript code above does, to a Python app which calls Llama and sends the answer to WhatsApp.

I'll try to improve this in a future PR update?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, making the call without the intermediate stage of the webhook will make your system less complex and when its recommended it probably the way to go. You think its a lot of work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed in general but in this case (and the WhatsApp Llama2 tutorial too) the JS based Glitch is the recommended webhook provider - I'd need to port it to Python and test with the webhook configuration in the API setting which would take at least half a day, so will leave it for a future update.

demo_apps/messenger_llama2.md Show resolved Hide resolved
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the scope of access be narrowed to improve security? ip range or similar? Is there a tutorial we can reference for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure but added the Gunicorn doc.

demo_apps/messenger_llama2.md Outdated Show resolved Hide resolved
scripts/spellcheck_conf/wordlist.txt Outdated Show resolved Hide resolved
@jeffxtang
Copy link
Contributor Author

@mreso thanks for the great review! i addressed all your comments and made some code and doc changes. please see if it looks good now.

Copy link
Contributor

@mreso mreso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the comments, LGTM

@jeffxtang jeffxtang merged commit 79bd012 into meta-llama:main Dec 15, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants