npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

langchain-llama2-chatbot-sagemaker

v0.0.0

Published

In this guide, you'll discover how to create a simple conversational chatbot by integrating Pluto, AWS services, LangChain, and Llama2. We’ll walk you through the architecture components of our example application and how to deploy and operate it using Pl

Downloads

4

Readme

Building a Llama2 Conversational Chatbot with AWS and LangChain

In this guide, you'll discover how to create a simple conversational chatbot by integrating Pluto, AWS services, LangChain, and Llama2. We’ll walk you through the architecture components of our example application and how to deploy and operate it using Pluto.

Architecture Overview

Chatbot Architecture Diagram

As illustrated above, our example application relies on the following AWS services and resources:

  • Amazon SageMaker: Deploying the Llama2 model
    • Model, EndpointConfiguration, Endpoint, Role
  • Amazon DynamoDB: Persisting session messages
    • Table
  • AWS Lambda: Executing backend business logic
    • Function, Role, Policy
  • Amazon API Gateway: Providing an HTTP API endpoint for user access
    • Api, Route, Integration, Deployment, Stage

Comparison

The table below shows a comparison between Pluto and other tools regarding the amount and type of code:

| | Code Type | Lines of Code | Code Location | | ------------------------------------------------------- | ---------------------------------- | -------------------- | ---------------------------------------------------- | | Application - TypeScript | Business Logic | 83(.ts) | Code | | Terraform | Infrastructure Configuration | 201(.tf) | Code | | Pulumi | Infrastructure Configuration | 157(.ts) | Code | | Pulumi Serverless | Business Logic + Configuration | 256(.ts) | Code | | Winglang - TS | Business Logic + Configuration | 100(.ts) | Code | | Winglang - Wing | Business Logic + Configuration | 71(.w) + 47(.ts) | Code | | Serverless | Business Logic + Configuration | 79(.ts) + 120(.yaml) | Code | | Pluto - TypeScript | Business Logic + Configuration | 100(.ts) | Code | | Application - Python | Business Logic | 60(.py) | Code | | Lepton | Business Logic + Configuration | 116(.py) | Code | | Pluto - Python | Business Logic + Configuration | **74(.py) ** | Code |

By examining the table data, the TypeScript and Python versions of the Pluto application add 17 and 14 lines of code, respectively, in contrast to pure business logic code. This includes code related to cloud resource creation and permission configuration. When infrastructure setup is handled using provisioning tools like Pulumi or Terraform, the combined code for business logic and infrastructure configuration exceeds twice the size of Pluto's code. Compared to tools such as Pulumi's Serverless feature, Winglang, Lepton, and Serverless, which streamline cloud usage, Pluto demands lower cloud and AI background knowledge and entails less code.

While using other tools, we faced several issues that ultimately hindered the deployment of this code. For instance, Winglang lacks support for SageMaker Model and EndpointConfig resource types, Pulumi runtime errors, and intricate resource configuration. If you're interested, feel free to lend a hand with the fixes.

Deployment Steps

To deploy this chatbot, please follow the steps below:

  1. Install Pluto and configure AWS access credentials. Detailed instructions can be found in the Pluto Quick Start Guide.

  2. Run the following commands in the root directory of the example application to initialize:

    npm install
    pip install -r requirements.txt
  3. Replace HUGGING_FACE_HUB_TOKEN in the src/index.ts file with your Hugging Face Hub Token. If you don’t have a token yet, generate one here.

  4. Deploy the application:

    pluto deploy

Be patient, as deploying the model in SageMaker can take some time. Once the deployment is complete, the console will display the URL for ApiGateway, which you can access via a browser or a curl command. Here is a simple test command:

CHATBOT_API_URL=your ApiGateway URL
time curl --get "$CHATBOT_API_URL/chat" \
  --data-urlencode "sessionid=session_1" \
  --data-urlencode "query='What is the capital of China?'"

By using the same sessionid, you can conduct multiple rounds of conversation testing.

To clean up resources, simply run the pluto destroy command in the root directory of the example application.

Extending the Example Application

This example application serves as a basic chatbot, but you can expand it based on your needs to make it more powerful and practical. For instance, you could:

  • Add custom business logic: Write more Lambda functions to execute more complex business logic tailored to specific business needs.
  • Integrate additional AWS services: Take advantage of the wide array of services provided by AWS, such as Amazon SNS as a message queue for asynchronous message processing.
  • Enhance user experience: Develop a frontend user interface to allow users to interact with the chatbot through a web page or mobile app, rather than solely through API requests.