From 2f04c10ebcfc278c13fa651d3a3367b4e0132a14 Mon Sep 17 00:00:00 2001 From: Amazon GitHub Automation <54958958+amazon-auto@users.noreply.github.com> Date: Mon, 31 Jul 2023 05:56:11 -0700 Subject: [PATCH 1/4] Initial commit --- CODE_OF_CONDUCT.md | 2 +- CONTRIBUTING.md | 2 +- LICENSE | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 4524eb9..fd0ab0a 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,4 +1,4 @@ # Code of Conduct このプロジェクトは [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct) を採用しています。 詳細については、[Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) もしくは -opensource-codeofconduct@amazon.com にコメント下さい。 \ No newline at end of file +opensource-codeofconduct@amazon.com にコメント下さい。 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 74b6a5b..a23a30a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,4 +16,4 @@ [SECURITY](SECURITY.md) を参照して下さい。 ## Licensing -プロジェクトのライセンスについては、[LICENSE](LICENSE.txt) ファイルを参照してください。 \ No newline at end of file +プロジェクトのライセンスについては、[LICENSE](LICENSE.txt) ファイルを参照してください。 diff --git a/LICENSE b/LICENSE index e906085..6aa0c45 100644 --- a/LICENSE +++ b/LICENSE @@ -11,4 +11,4 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. From 9a413fa7ca3b0cc1f32bbb787c3a067ac0ac5c90 Mon Sep 17 00:00:00 2001 From: Taiki Maekawa Date: Tue, 3 Oct 2023 16:07:01 +0900 Subject: [PATCH 2/4] update rinna to jumpstart model --- .../fargate-cloudformation-template.json | 118 ++++-------------- amplify/backend/api/fargate/parameters.json | 2 +- .../fargate/src/langchain/app/chain/rinna.py | 11 +- llm/delete_llm.sh | 6 - llm/deploy_llm.sh | 47 ++----- 5 files changed, 37 insertions(+), 147 deletions(-) diff --git a/amplify/backend/api/fargate/fargate-cloudformation-template.json b/amplify/backend/api/fargate/fargate-cloudformation-template.json index 0f94416..d1b8dcc 100644 --- a/amplify/backend/api/fargate/fargate-cloudformation-template.json +++ b/amplify/backend/api/fargate/fargate-cloudformation-template.json @@ -156,47 +156,17 @@ "", [ { - "Fn::Select": [ - 4, - { - "Fn::Split": [ - ":", - { - "Fn::GetAtt": [ - "langchainRepository", - "Arn" - ] - } - ] - } - ] + "Ref": "AWS::AccountId" }, ".dkr.ecr.", { - "Fn::Select": [ - 3, - { - "Fn::Split": [ - ":", - { - "Fn::GetAtt": [ - "langchainRepository", - "Arn" - ] - } - ] - } - ] + "Ref": "AWS::Region" }, ".", { "Ref": "AWS::URLSuffix" }, - "/", - { - "Ref": "langchainRepository" - }, - ":latest" + "/amplify-rag-dev-102319-api-fargate-langchain:latest" ] ] }, @@ -299,9 +269,23 @@ ], "Effect": "Allow", "Resource": { - "Fn::GetAtt": [ - "langchainRepository", - "Arn" + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":ecr:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":repository/amplify-rag-dev-102319-api-fargate-langchain" + ] ] } }, @@ -391,27 +375,6 @@ "UpdateReplacePolicy": "Delete", "DeletionPolicy": "Delete" }, - "langchainRepository": { - "Type": "AWS::ECR::Repository", - "Properties": { - "LifecyclePolicy": { - "LifecyclePolicyText": "{\"rules\":[{\"rulePriority\":10,\"selection\":{\"tagStatus\":\"tagged\",\"tagPrefixList\":[\"latest\"],\"countType\":\"imageCountMoreThan\",\"countNumber\":1},\"action\":{\"type\":\"expire\"}},{\"rulePriority\":100,\"selection\":{\"tagStatus\":\"any\",\"countType\":\"sinceImagePushed\",\"countNumber\":7,\"countUnit\":\"days\"},\"action\":{\"type\":\"expire\"}}]}" - }, - "RepositoryName": { - "Fn::Join": [ - "", - [ - { - "Ref": "rootStackName" - }, - "-api-fargate-langchain" - ] - ] - } - }, - "UpdateReplacePolicy": "Retain", - "DeletionPolicy": "Retain" - }, "ServiceSG": { "Type": "AWS::EC2::SecurityGroup", "Properties": { @@ -444,7 +407,7 @@ "Cluster": { "Ref": "NetworkStackClusterName" }, - "DesiredCount": 0, + "DesiredCount": 1, "LaunchType": "FARGATE", "NetworkConfiguration": { "AwsvpcConfiguration": { @@ -980,47 +943,17 @@ }, "\"},{\"name\":\"langchain_REPOSITORY_URI\",\"type\":\"PLAINTEXT\",\"value\":\"", { - "Fn::Select": [ - 4, - { - "Fn::Split": [ - ":", - { - "Fn::GetAtt": [ - "langchainRepository", - "Arn" - ] - } - ] - } - ] + "Ref": "AWS::AccountId" }, ".dkr.ecr.", { - "Fn::Select": [ - 3, - { - "Fn::Split": [ - ":", - { - "Fn::GetAtt": [ - "langchainRepository", - "Arn" - ] - } - ] - } - ] + "Ref": "AWS::Region" }, ".", { "Ref": "AWS::URLSuffix" }, - "/", - { - "Ref": "langchainRepository" - }, - "\"}]" + "/amplify-rag-dev-102319-api-fargate-langchain\"}]" ] ] } @@ -2646,6 +2579,5 @@ "states": "states.us-west-2.amazonaws.com" } } - }, - "Description": "{\"createdOn\":\"Mac\",\"createdBy\":\"Amplify\",\"createdWith\":\"12.1.1\",\"stackType\":\"api-ElasticContainer\",\"metadata\":{}}" + } } \ No newline at end of file diff --git a/amplify/backend/api/fargate/parameters.json b/amplify/backend/api/fargate/parameters.json index 4f934eb..0c4edd0 100644 --- a/amplify/backend/api/fargate/parameters.json +++ b/amplify/backend/api/fargate/parameters.json @@ -1,3 +1,3 @@ { - "ParamZipPath": "amplify-builds/fargate-73386155644967766f52-build.zip" + "ParamZipPath": "amplify-builds/fargate-6572486d4e6155524f79-build.zip" } \ No newline at end of file diff --git a/amplify/backend/api/fargate/src/langchain/app/chain/rinna.py b/amplify/backend/api/fargate/src/langchain/app/chain/rinna.py index 550d664..e0c6c4f 100644 --- a/amplify/backend/api/fargate/src/langchain/app/chain/rinna.py +++ b/amplify/backend/api/fargate/src/langchain/app/chain/rinna.py @@ -20,9 +20,8 @@ class RinnaContentHandler(LLMContentHandler): def transform_input(self, prompt: str, model_kwargs: dict) -> bytes: input_str = json.dumps( { - "instruction": "", - "input": prompt.replace("\n", ""), - **model_kwargs, + "inputs": prompt.replace("\n", ""), + "parameters": model_kwargs } ) print("prompt: ", prompt) @@ -30,7 +29,8 @@ def transform_input(self, prompt: str, model_kwargs: dict) -> bytes: def transform_output(self, output: bytes) -> str: response_json = json.loads(output.read().decode("utf-8")) - return response_json.replace("", "\n") + response = response_json[0]['generated_text'] + return response.replace("", "\n") def build_rinna_chain(endpoint_name: str, aws_region: str) -> LLMChain: @@ -52,9 +52,6 @@ def build_rinna_chain(endpoint_name: str, aws_region: str) -> LLMChain: "max_new_tokens": 256, "temperature": 0.3, "do_sample": True, - "pad_token_id": 0, - "bos_token_id": 2, - "eos_token_id": 3, }, content_handler=content_handler, ) diff --git a/llm/delete_llm.sh b/llm/delete_llm.sh index 7b35766..d125568 100644 --- a/llm/delete_llm.sh +++ b/llm/delete_llm.sh @@ -7,18 +7,12 @@ pip3 install sagemaker python3 <=2.168.0" python3 < Date: Tue, 3 Oct 2023 16:07:25 +0900 Subject: [PATCH 3/4] change kendra data source to japanese --- kendra/kendra-docs-index.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/kendra/kendra-docs-index.yaml b/kendra/kendra-docs-index.yaml index e6cf932..185b582 100644 --- a/kendra/kendra-docs-index.yaml +++ b/kendra/kendra-docs-index.yaml @@ -122,6 +122,7 @@ Resources: Name: 'KendraDocsDS' RoleArn: !GetAtt KendraDSRole.Arn Type: 'WEBCRAWLER' + LanguageCode: ja DataSourceSyncLambdaRole: Type: AWS::IAM::Role From 95d908f5cadec3d1e6d0a98ca7d1cc77e99e5b06 Mon Sep 17 00:00:00 2001 From: Taiki Maekawa Date: Tue, 3 Oct 2023 16:07:36 +0900 Subject: [PATCH 4/4] shorten project name --- amplify/.config/project-config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amplify/.config/project-config.json b/amplify/.config/project-config.json index 30f4f49..9a262c5 100644 --- a/amplify/.config/project-config.json +++ b/amplify/.config/project-config.json @@ -1,5 +1,5 @@ { - "projectName": "jpragsampleamplify", + "projectName": "rag", "version": "3.1", "frontend": "javascript", "javascript": {