Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brave-countries-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@plutolang/pluto-infra": patch
---

enhance(sdk): remove the fuzzyArn, instead use the lazy value from pulumi.
5 changes: 5 additions & 0 deletions .changeset/breezy-cats-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@plutolang/pluto": patch
---

feat(sdk): export the table name and partition key of the created dynamodb instance to users
4 changes: 3 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"quickstart",
"gpt2-hf-sagemaker",
"langchain-llama2-sagemaker",
"quickstart-python"
"quickstart-python",
"langchain-llama2-chatbot-sagemaker",
"langchain-llama2-chatbot-sagemaker-python"
]
}
5 changes: 5 additions & 0 deletions .changeset/tough-swans-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@plutolang/static-deducer": patch
---

fix(deducer): incorrectly generate duplicate client statements when one code section accesses a single resource multiple times
6 changes: 5 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ jobs:
with:
node-version: 20.x

- uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Setup PNPM
uses: pnpm/action-setup@v2
with:
Expand All @@ -38,7 +42,7 @@ jobs:
run: bash scripts/prepare.sh

- name: Install Dependencies
run: pnpm install
run: pnpm install && pip install -r requirements.txt

- name: Creating .npmrc
run: |
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions components/deducers/static/src/closure/store-closure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ function generateSourceCode(
): string {
let cirCode = imports + "\n";

const resources = new Set<string>();
// Find the dependencies of this CIR and build corresponding instances.
for (const dependentRes of dependentResources) {
if (resources.has(dependentRes.name)) {
continue;
}
resources.add(dependentRes.name);

// TODO: verify if the buildClient function exists. If it does not, use the original statement.
cirCode += dependentRes.imports + "\n";
cirCode += `const ${dependentRes.name} = ${dependentRes.type}.buildClient(${dependentRes.parameters});\n`;
Expand Down
38 changes: 38 additions & 0 deletions examples/langchain-llama2-chatbot-sagemaker-python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
node_modules
.pnp
.pnp.js

# testing
coverage

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# turbo
.turbo

# vercel
.vercel

# compilation result
**/dist/

# pluto
.pluto/**/state/
.pluto/*.test.*/
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ current: aws
language: python
stacks:
- configs: {}
provisionType: Pulumi
name: aws
platformType: AWS
platformType: AWS
provisionType: Pulumi
6 changes: 6 additions & 0 deletions examples/langchain-llama2-chatbot-sagemaker-python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Building a Llama2 Conversational Chatbot with AWS and LangChain

The difference between this and the [TypeScript version of the Pluto example](../langchain-llama2-chatbot-sagemaker/) lies in its implementation in Python, which has not yet been successfully deployed. The issues encountered include:

1. When deploying across platforms, dependencies such as Numpy and Pydantic cannot be correctly installed on the target platform.
2. The size of the compressed package exceeds the AWS Lambda limit of 50MB.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 基于 AWS 和 LangChain 的 Llama2 会话聊天机器人

与 [TypeScript 版本的 Pluto 示例](../langchain-llama2-chatbot-sagemaker/)应用区别在于使用 Python 实现,尚未成功部署,存在的问题包括:

1. 跨平台部署时,Numpy、Pydantic 等依赖包无法在目标平台正确安装。
2. 压缩包大小超过 AWS Lambda 限制,50MB。
127 changes: 127 additions & 0 deletions examples/langchain-llama2-chatbot-sagemaker-python/app/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import os
import json
from typing import Dict

from pluto_client.sagemaker import SageMaker, SageMakerOptions
from pluto_client import Router, HttpRequest, HttpResponse, KVStore

from langchain.prompts import PromptTemplate
from langchain.memory.buffer import ConversationBufferMemory
from langchain.chains.conversation.base import ConversationChain
from langchain_community.chat_message_histories.dynamodb import (
DynamoDBChatMessageHistory,
)
from langchain_community.llms.sagemaker_endpoint import (
SagemakerEndpoint,
LLMContentHandler,
)

"""
Deploy the Llama2 model on AWS SageMaker using the Hugging Face Text Generation Inference (TGI)
container. If you're unable to deploy the model because of the instance type, consider using the
TinyLlama-1.1B-Chat-v1.0 model, which is compatible with the ml.m5.xlarge instance.

Below is a set up minimum requirements for each model size of Llama2 model:
```
Model Instance Type Quantization # of GPUs per replica
Llama 7B ml.g5.2xlarge - 1
Llama 13B ml.g5.12xlarge - 4
Llama 70B ml.g5.48xlarge bitsandbytes 8
Llama 70B ml.p4d.24xlarge - 8
```

The initial limit set for these instances is zero. If you need more, you can request an increase
in quota via the [AWS Management Console](https://console.aws.amazon.com/servicequotas/home).
"""
sagemaker = SageMaker(
"llama2",
"763104351884.dkr.ecr.us-east-1.amazonaws.com/huggingface-pytorch-tgi-inference:2.1.1-tgi1.4.0-gpu-py310-cu121-ubuntu20.04",
SageMakerOptions(
instanceType="ml.g5.2xlarge",
envs={
"HF_MODEL_ID": "meta-llama/Llama-2-7b-chat-hf",
"HF_TASK": "text-generation",
# If you want to deploy the Meta Llama2 model, you need to request a permission and
# prepare the token. You can get the token from https://huggingface.co/settings/tokens
"HUGGING_FACE_HUB_TOKEN": "hf_EmXPwpnyHoNrxxxxxxxxx",
},
),
)

router = Router("chatbot")
conversations = KVStore("conversations")


class ContentHandler(LLMContentHandler):
content_type = "application/json"
accepts = "application/json"

def transform_input(self, prompt: str, model_kwargs: Dict) -> bytes:
input_str = json.dumps({"inputs": prompt, "parameters": model_kwargs})
return input_str.encode("utf-8")

def transform_output(self, output: bytes) -> str:
response_json = json.loads(output.decode("utf-8"))
return response_json[0]["generated_text"]


def get_aws_region() -> str:
aws_region = os.environ.get("AWS_REGION")
if aws_region is None:
raise ValueError("AWS_REGION environment variable must be set")
return aws_region


llm = SagemakerEndpoint(
endpoint_name=sagemaker.endpoint_name, # SageMaker endpoint name
region_name=get_aws_region(),
content_handler=ContentHandler(),
)


def chat_handler(req: HttpRequest) -> HttpResponse:
query = req.query["query"]
sessionid = req.query["sessionid"]
if isinstance(sessionid, list):
sessionid = sessionid[0]

memory = ConversationBufferMemory(
chat_memory=DynamoDBChatMessageHistory(
table_name=conversations.aws_table_name, # DynamoDB table name
primary_key_name=conversations.aws_partition_key, # DynamoDB partition key
session_id=sessionid,
)
)

promptTemplate = PromptTemplate.from_template(
"""<|system|>
You are a cool and aloof robot, answering questions very briefly and directly.

Context:
{history}</s>
<|user|>
{query}</s>
<|assistant|>"""
)

chain = ConversationChain(
llm=llm,
memory=memory,
prompt=promptTemplate,
)

result = chain({"query": query})
print(result)

return HttpResponse(status_code=200, body="hello world")

# TODO: Use the following statement to help the deducer identify the right relationship between
# Lambda and other resources. This will be used to grant permission for the Lambda instance to
# access the SageMaker endpoint and the DynamoDB. This code should be removed after the deducer
# supports the analysis of libraries.
conversations.get("")
conversations.set("", "")
sagemaker.invoke("")


router.get("/chatbot", chat_handler)
20 changes: 20 additions & 0 deletions examples/langchain-llama2-chatbot-sagemaker-python/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "langchain-llama2-chatbot-sagemaker-python",
"private": true,
"version": "0.0.1",
"scripts": {
"test:dev": "pluto test --sim",
"test:prod": "pluto test",
"deploy": "pluto deploy",
"destroy": "pluto destroy"
},
"dependencies": {},
"devDependencies": {
"@types/node": "^20",
"typescript": "^5.2.2",
"@plutolang/base": "latest",
"@plutolang/pluto-infra": "latest",
"@pulumi/pulumi": "^3.88.0"
},
"main": "dist/index.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pluto_client
38 changes: 38 additions & 0 deletions examples/langchain-llama2-chatbot-sagemaker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
node_modules
.pnp
.pnp.js

# testing
coverage

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# turbo
.turbo

# vercel
.vercel

# compilation result
**/dist/

# pluto
.pluto/**/state/
.pluto/*.test.*/
7 changes: 7 additions & 0 deletions examples/langchain-llama2-chatbot-sagemaker/.pluto/pluto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
current: dev
language: typescript
stacks:
- configs: {}
name: dev
platformType: AWS
provisionType: Pulumi
Loading