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

Fix prompt passing for Bedrock by passing a single string prompt for … #1490

Merged
merged 4 commits into from
Oct 11, 2023

Conversation

austintlee
Copy link
Collaborator

…Bedrock models. (#1476)

Description

#1476

Issues Resolved

#1476

Check List

  • [x ] New functionality includes testing.
    • [x ] All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • [ x] Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@austintlee
Copy link
Collaborator Author

austintlee commented Oct 11, 2023

Tested this locally on Docker.

This is the "input" part of the prompt RAG is sending to Bedrock:

LLM input parameters: {inputs=You are a helpful assistant\nnull\nSEARCH RESULT 1: Abraham Lincoln was born on February 12, 1809, the second child of Thomas Lincoln and Nancy Hanks Lincoln, in a log cabin on Sinking Spring Farm near Hodgenville, Kentucky.[2] He was a descendant of Samuel Lincoln, an Englishman who migrated from Hingham, Norfolk, to its namesake, Hingham, Massachusetts, in 1638. The family then migrated west, passing through New Jersey, Pennsylvania, and Virginia.[3] Lincoln was also a descendant of the Harrison family of Virginia; his paternal grandfather and namesake, Captain Abraham Lincoln and wife Bathsheba (née Herring) moved the family from Virginia to Jefferson County, Kentucky.[b] The captain was killed in an Indian raid in 1786.[5] His children, including eight-year-old Thomas, Abraham's father, witnessed the attack.[6][c] Thomas then worked at odd jobs in Kentucky and Tennessee before the family settled in Hardin County, Kentucky, in the early 1800s.[6]

 \nSEARCH RESULT 2: Abraham Lincoln (/ˈlɪŋkən/ LINK-ən; February 12, 1809 – April 15, 1865) was an American lawyer, politician, and statesman who served as the 16th president of the United States from 1861 until his assassination in 1865. Lincoln led the Union through the American Civil War to defend the nation as a constitutional union and succeeded in abolishing slavery, bolstering the federal government, and modernizing the U.S. economy.

 \nSEARCH RESULT 3: Lincoln was born into poverty in a log cabin in Kentucky and was raised on the frontier, primarily in Indiana. He was self-educated and became a lawyer, Whig Party leader, Illinois state legislator, and U.S. Congressman from Illinois. In 1849, he returned to his successful law practice in central Illinois. In 1854, he was angered by the Kansas–Nebraska Act, which opened the territories to slavery, and he re-entered politics. He soon became a leader of the new Republican Party. He reached a national audience in the 1858 Senate campaign debates against Stephen A. Douglas. Lincoln ran for president in 1860, sweeping the North to gain victory. Pro-slavery elements in the South viewed his election as a threat to slavery, and Southern states began seceding from the nation. During this time, the newly formed Confederate States of America began seizing federal military bases in the south. Just over one month after Lincoln assumed the presidency, the Confederate States attacked Fort Sumter, a U.S. fort in South Carolina. Following the bombardment, Lincoln mobilized forces to suppress the rebellion and restore the union.
\nQUESTION: Was Abraham Lincoln a good politician\n}

This is what's coming back from Bedrock

dataAsMap: {completion= Based on the search results, I would say that Abraham Lincoln was considered a very good politician:

- He was a leader of the new Republican Party in the 1850s. 

 - He gained national prominence through his debates against Stephen Douglas during the 1858 Senate campaign. 

 - He was elected President in 1860, sweeping the Northern states. 

 - As President during the Civil War, he succeeded in preserving the Union, abolishing slavery, strengthening the federal government, and modernizing the economy. 
 
 - He led the country through an extremely difficult period and is considered one of the greatest Presidents in U.S. history. 

 So yes, the evidence indicates Abraham Lincoln was an extremely skilled politician who used his abilities to positively transform the nation during a time of crisis. His political acumen and leadership qualities allowed him to advance morally just causes like ending slavery, despite strong opposition., stop_reason=stop_sequence}

@austintlee
Copy link
Collaborator Author

Using this blueprint:

{
  "name": "Bedrock Connector: claude2",
  "description": "The connector to bedrock claude2 model",
  "version": 1,
  "protocol": "aws_sigv4",
  "parameters": {
    "region": "us-east-1",
    "service_name": "bedrock"
  },
  "credential": {
    "access_key": "...",
    "secret_key": "...",
    "session_token": "..."
  },
  "actions": [
        {
            "action_type": "predict",
            "method": "POST",
            "headers": {
                "content-type": "application/json"
            },
            "url": "https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-v2/invoke",
            "request_body": "{\"prompt\":\"\\n\\nHuman: ${parameters.inputs}\\n\\nAssistant:\",\"max_tokens_to_sample\":300,\"temperature\":0.5,\"top_k\":250,\"top_p\":1,\"stop_sequences\":[\"\\\\n\\\\nHuman:\"]}"
        }
    ]
}

@austintlee
Copy link
Collaborator Author

CloudTrail event for the above call:

{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "IAMUser",
        "principalId": "AIDATOTZBMMGRGHDAMBA5",
        "arn": "arn:aws:iam::237550789389:user/austin",
        "accountId": "237550789389",
        "accessKeyId": "ASIATOTZBMMG2ZDJA5V5",
        "userName": "austin",
        "sessionContext": {
            "sessionIssuer": {},
            "webIdFederationData": {},
            "attributes": {
                "creationDate": "2023-10-11T20:16:16Z",
                "mfaAuthenticated": "false"
            }
        }
    },
    "eventTime": "2023-10-11T20:28:22Z",
    "eventSource": "bedrock.amazonaws.com",
    "eventName": "InvokeModel",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "50.47.212.241",
    "requestParameters": {
        "modelId": "anthropic.claude-v2"
    },
    "responseElements": null,
    "requestID": "76d4c0f5-559e-40e1-94e2-70011cc1fe5c",
    "eventID": "f6736a78-b1de-4dad-9382-768631da081b",
    "readOnly": false,
    "eventType": "AwsApiCall",
    "managementEvent": true,
    "recipientAccountId": "237550789389",
    "eventCategory": "Management",
    "tlsDetails": {
        "tlsVersion": "TLSv1.3",
        "cipherSuite": "TLS_AES_128_GCM_SHA256",
        "clientProvidedHostHeader": "bedrock-runtime.us-east-1.amazonaws.com"
    }
}

@austintlee
Copy link
Collaborator Author

@austintlee austintlee temporarily deployed to ml-commons-cicd-env October 11, 2023 21:38 — with GitHub Actions Inactive
@austintlee austintlee temporarily deployed to ml-commons-cicd-env October 11, 2023 21:38 — with GitHub Actions Inactive
@austintlee austintlee temporarily deployed to ml-commons-cicd-env October 11, 2023 21:38 — with GitHub Actions Inactive
@austintlee
Copy link
Collaborator Author

Also tested with the conversation enabled.

@austintlee austintlee temporarily deployed to ml-commons-cicd-env October 11, 2023 21:52 — with GitHub Actions Inactive
@austintlee austintlee temporarily deployed to ml-commons-cicd-env October 11, 2023 21:52 — with GitHub Actions Inactive
@codecov
Copy link

codecov bot commented Oct 11, 2023

Codecov Report

Merging #1490 (bdebe65) into 2.11 (5544681) will increase coverage by 0.20%.
Report is 2 commits behind head on 2.11.
The diff coverage is 87.50%.

❗ Current head bdebe65 differs from pull request most recent head a598e5e. Consider uploading reports for the commit a598e5e to get more accurate results

@@             Coverage Diff              @@
##               2.11    #1490      +/-   ##
============================================
+ Coverage     79.77%   79.98%   +0.20%     
- Complexity     2440     2452      +12     
============================================
  Files           196      197       +1     
  Lines          9740     9796      +56     
  Branches        975      985      +10     
============================================
+ Hits           7770     7835      +65     
+ Misses         1508     1492      -16     
- Partials        462      469       +7     
Flag Coverage Δ
ml-commons 79.98% <87.50%> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...tion/prediction/TransportPredictionTaskAction.java 79.66% <ø> (+17.36%) ⬆️
...nanswering/generative/llm/ChatCompletionInput.java 100.00% <ø> (ø)
...ipelines/questionanswering/generative/llm/Llm.java 100.00% <100.00%> (ø)
...es/questionanswering/generative/llm/LlmIOUtil.java 83.33% <75.00%> (-16.67%) ⬇️
...uestionanswering/generative/prompt/PromptUtil.java 93.82% <87.50%> (-2.67%) ⬇️
...estionanswering/generative/llm/DefaultLlmImpl.java 90.90% <87.75%> (-9.10%) ⬇️

... and 6 files with indirect coverage changes

b4sjoo
b4sjoo previously approved these changes Oct 11, 2023
@austintlee
Copy link
Collaborator Author

@dhrubo-os anything else?

Signed-off-by: Austin Lee <[email protected]>
@austintlee austintlee temporarily deployed to ml-commons-cicd-env October 11, 2023 23:11 — with GitHub Actions Inactive
@austintlee austintlee temporarily deployed to ml-commons-cicd-env October 11, 2023 23:11 — with GitHub Actions Inactive
@austintlee austintlee temporarily deployed to ml-commons-cicd-env October 11, 2023 23:11 — with GitHub Actions Inactive
@austintlee austintlee temporarily deployed to ml-commons-cicd-env October 11, 2023 23:11 — with GitHub Actions Inactive
@austintlee austintlee requested a review from b4sjoo October 11, 2023 23:12
@dhrubo-os dhrubo-os merged commit e18f249 into opensearch-project:2.11 Oct 11, 2023
8 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Oct 11, 2023
#1490)

* Fix prompt passing for Bedrock by passing a single string prompt for Bedrock models. (#1476)

Signed-off-by: Austin Lee <[email protected]>

* Add unit tests, apply Spotless.

Signed-off-by: Austin Lee <[email protected]>

* Check if systemPrompt is null.

Signed-off-by: Austin Lee <[email protected]>

* Address review comments.

Signed-off-by: Austin Lee <[email protected]>

---------

Signed-off-by: Austin Lee <[email protected]>
(cherry picked from commit e18f249)
opensearch-trigger-bot bot pushed a commit that referenced this pull request Oct 11, 2023
#1490)

* Fix prompt passing for Bedrock by passing a single string prompt for Bedrock models. (#1476)

Signed-off-by: Austin Lee <[email protected]>

* Add unit tests, apply Spotless.

Signed-off-by: Austin Lee <[email protected]>

* Check if systemPrompt is null.

Signed-off-by: Austin Lee <[email protected]>

* Address review comments.

Signed-off-by: Austin Lee <[email protected]>

---------

Signed-off-by: Austin Lee <[email protected]>
(cherry picked from commit e18f249)
dhrubo-os pushed a commit that referenced this pull request Oct 11, 2023
#1490) (#1496)

* Fix prompt passing for Bedrock by passing a single string prompt for Bedrock models. (#1476)

Signed-off-by: Austin Lee <[email protected]>

* Add unit tests, apply Spotless.

Signed-off-by: Austin Lee <[email protected]>

* Check if systemPrompt is null.

Signed-off-by: Austin Lee <[email protected]>

* Address review comments.

Signed-off-by: Austin Lee <[email protected]>

---------

Signed-off-by: Austin Lee <[email protected]>
(cherry picked from commit e18f249)

Co-authored-by: Austin Lee <[email protected]>
dhrubo-os pushed a commit that referenced this pull request Oct 11, 2023
#1490) (#1497)

* Fix prompt passing for Bedrock by passing a single string prompt for Bedrock models. (#1476)

Signed-off-by: Austin Lee <[email protected]>

* Add unit tests, apply Spotless.

Signed-off-by: Austin Lee <[email protected]>

* Check if systemPrompt is null.

Signed-off-by: Austin Lee <[email protected]>

* Address review comments.

Signed-off-by: Austin Lee <[email protected]>

---------

Signed-off-by: Austin Lee <[email protected]>
(cherry picked from commit e18f249)

Co-authored-by: Austin Lee <[email protected]>
TrungBui59 pushed a commit to TrungBui59/ml-commons that referenced this pull request Nov 21, 2023
opensearch-project#1490) (opensearch-project#1497)

* Fix prompt passing for Bedrock by passing a single string prompt for Bedrock models. (opensearch-project#1476)

Signed-off-by: Austin Lee <[email protected]>

* Add unit tests, apply Spotless.

Signed-off-by: Austin Lee <[email protected]>

* Check if systemPrompt is null.

Signed-off-by: Austin Lee <[email protected]>

* Address review comments.

Signed-off-by: Austin Lee <[email protected]>

---------

Signed-off-by: Austin Lee <[email protected]>
(cherry picked from commit e18f249)

Co-authored-by: Austin Lee <[email protected]>
Signed-off-by: TrungBui59 <[email protected]>
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.

5 participants