You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2024/04/04 11:30:14 UTC
(camel-kamelets-examples) 01/01: Added AWS Bedrock Session with Bedrock agent runtime Sink
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch bedrock-knowledgebase
in repository https://gitbox.apache.org/repos/asf/camel-kamelets-examples.git
commit 01074b61d7ade959583e93e2c616c68fc6069aab
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Apr 4 13:29:14 2024 +0200
Added AWS Bedrock Session with Bedrock agent runtime Sink
Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
jbang/aws-bedrock-ingestion/README.adoc | 44 ++++++++++++++++++++++
jbang/aws-bedrock-ingestion/application.properties | 1 +
.../aws-bedrock-knowledgebase-session.camel.yaml | 43 +++++++++++++++++++++
3 files changed, 88 insertions(+)
diff --git a/jbang/aws-bedrock-ingestion/README.adoc b/jbang/aws-bedrock-ingestion/README.adoc
index 9b28d82..f9d678b 100644
--- a/jbang/aws-bedrock-ingestion/README.adoc
+++ b/jbang/aws-bedrock-ingestion/README.adoc
@@ -166,6 +166,50 @@ curl http://0.0.0.0:8080/bedrock/prompt/
The average price of natural gas between 2010 and 2011 was $3.93 per unit.
----
+=== Running a full session with the Knowledge Base
+
+It's interesting to use the ability to create a session with the Knowledge Base.
+
+To do this there is a route you can run, composed of Kamelets, named `aws-bedrock-knowledgebase-session.camel.yaml`
+
+This route will will be triggered by a timer and then it will loop, asking random range average value for natural gas prices, re-using the same Session id.
+
+You can run
+
+[source,sh]
+----
+jbang -Dcamel.jbang.version=4.6.0-SNAPSHOT camel@apache/camel run --properties=application.properties aws-bedrock-knowledgebase-session.camel.yaml
+----
+
+This will give the following output
+
+[source,sh]
+----
+2024-04-04 12:53:31.341 INFO 47329 --- [ main] el.impl.engine.AbstractCamelContext : Routes startup (total:1 started:1 kamelets:3)
+2024-04-04 12:53:31.341 INFO 47329 --- [ main] el.impl.engine.AbstractCamelContext : Started route1 (kamelet://timer-source)
+2024-04-04 12:53:31.341 INFO 47329 --- [ main] el.impl.engine.AbstractCamelContext : Apache Camel 4.6.0-SNAPSHOT (aws-bedrock-knowledgebase-session) started in 501ms (build:0ms init:0ms start:501ms)
+2024-04-04 12:53:32.350 INFO 47329 --- [ - timer://tick] knowledgebase-session.camel.yaml:27 : New Request to Knowledge Base What is the average natural gas price between 1998 and 1999?
+2024-04-04 12:53:35.620 INFO 47329 --- [ - timer://tick] log-sink : Exchange[ExchangePattern: InOnly, Headers: {CamelAwsBedrockAgentRuntimeCitations=[Citation(GeneratedResponsePart=GeneratedResponsePart(TextResponsePart=*** Sensitive Data Redacted ***), RetrievedReferences=[RetrievedReference(Content=*** Sensitive Data Redacted ***, Location=*** Sensitive Data Redacted ***, Metadata=*** Sensitive Data Redacted ***)])], CamelAwsBedrockAgentRuntimeSessionId=dd18 [...]
+2024-04-04 12:53:35.621 INFO 47329 --- [ - timer://tick] knowledgebase-session.camel.yaml:39 : SessionId is dd187271-cff8-4730-a6a7-42136120eac7
+2024-04-04 12:53:35.621 INFO 47329 --- [ - timer://tick] knowledgebase-session.camel.yaml:27 : New Request to Knowledge Base What is the average natural gas price between 2005 and 2013?
+2024-04-04 12:53:39.428 INFO 47329 --- [ - timer://tick] log-sink : Exchange[ExchangePattern: InOnly, Headers: {CamelAwsBedrockAgentRuntimeCitations=[Citation(GeneratedResponsePart=GeneratedResponsePart(TextResponsePart=*** Sensitive Data Redacted ***), RetrievedReferences=[RetrievedReference(Content=*** Sensitive Data Redacted ***, Location=*** Sensitive Data Redacted ***, Metadata=*** Sensitive Data Redacted ***), RetrievedReference(Content=*** Sensitive Dat [...]
+2024-04-04 12:53:39.431 INFO 47329 --- [ - timer://tick] knowledgebase-session.camel.yaml:39 : SessionId is dd187271-cff8-4730-a6a7-42136120eac7
+2024-04-04 12:53:39.433 INFO 47329 --- [ - timer://tick] knowledgebase-session.camel.yaml:27 : New Request to Knowledge Base What is the average natural gas price between 2017 and 2017?
+2024-04-04 12:53:43.244 INFO 47329 --- [ - timer://tick] log-sink : Exchange[ExchangePattern: InOnly, Headers: {CamelAwsBedrockAgentRuntimeCitations=[Citation(GeneratedResponsePart=GeneratedResponsePart(TextResponsePart=*** Sensitive Data Redacted ***), RetrievedReferences=[RetrievedReference(Content=*** Sensitive Data Redacted ***, Location=*** Sensitive Data Redacted ***, Metadata=*** Sensitive Data Redacted ***)])], CamelAwsBedrockAgentRuntimeSessionId=dd18 [...]
+2024-04-04 12:53:43.245 INFO 47329 --- [ - timer://tick] knowledgebase-session.camel.yaml:39 : SessionId is dd187271-cff8-4730-a6a7-42136120eac7
+2024-04-04 12:53:43.245 INFO 47329 --- [ - timer://tick] knowledgebase-session.camel.yaml:27 : New Request to Knowledge Base What is the average natural gas price between 2015 and 2011?
+2024-04-04 12:53:47.803 INFO 47329 --- [ - timer://tick] log-sink : Exchange[ExchangePattern: InOnly, Headers: {CamelAwsBedrockAgentRuntimeCitations=[Citation(GeneratedResponsePart=GeneratedResponsePart(TextResponsePart=*** Sensitive Data Redacted ***), RetrievedReferences=[RetrievedReference(Content=*** Sensitive Data Redacted ***, Location=*** Sensitive Data Redacted ***, Metadata=*** Sensitive Data Redacted ***), RetrievedReference(Content=*** Sensitive Dat [...]
+2024-04-04 12:53:47.804 INFO 47329 --- [ - timer://tick] knowledgebase-session.camel.yaml:39 : SessionId is dd187271-cff8-4730-a6a7-42136120eac7
+2024-04-04 12:53:47.805 INFO 47329 --- [ - timer://tick] knowledgebase-session.camel.yaml:27 : New Request to Knowledge Base What is the average natural gas price between 2018 and 2017?
+2024-04-04 12:53:51.479 INFO 47329 --- [ - timer://tick] log-sink : Exchange[ExchangePattern: InOnly, Headers: {CamelAwsBedrockAgentRuntimeCitations=[Citation(GeneratedResponsePart=GeneratedResponsePart(TextResponsePart=*** Sensitive Data Redacted ***), RetrievedReferences=[RetrievedReference(Content=*** Sensitive Data Redacted ***, Location=*** Sensitive Data Redacted ***, Metadata=*** Sensitive Data Redacted ***)])], CamelAwsBedrockAgentRuntimeSessionId=dd18 [...]
+2024-04-04 12:53:51.481 INFO 47329 --- [ - timer://tick] knowledgebase-session.camel.yaml:39 : SessionId is dd187271-cff8-4730-a6a7-42136120eac7
+^C2024-04-04 12:54:01.296 INFO 47329 --- [ main] el.impl.engine.AbstractCamelContext : Apache Camel 4.6.0-SNAPSHOT (aws-bedrock-knowledgebase-session) is shutting down (timeout:10s)
+2024-04-04 12:54:01.307 INFO 47329 --- [ main] el.impl.engine.AbstractCamelContext : Routes stopped (total:1 stopped:1 kamelets:3)
+2024-04-04 12:54:01.307 INFO 47329 --- [ main] el.impl.engine.AbstractCamelContext : Stopped route1 (kamelet://timer-source)
+2024-04-04 12:54:01.313 INFO 47329 --- [ main] el.impl.engine.AbstractCamelContext : Apache Camel 4.6.0-SNAPSHOT (aws-bedrock-knowledgebase-session) shutdown in 17ms (uptime:30s)
+2024-04-04 12:54:01.314 INFO 47329 --- [ main] org.apache.camel.main.MainSupport : Apache Camel (JBang) 4.6.0-SNAPSHOT shutdown
+----
+
=== Cleanup AWS S3 bucket, SQS Queue and EventBridge Rule through Terraform
You'll need to cleanup everything from AWS console or CLI.
diff --git a/jbang/aws-bedrock-ingestion/application.properties b/jbang/aws-bedrock-ingestion/application.properties
index 54c9ae2..d0c7034 100644
--- a/jbang/aws-bedrock-ingestion/application.properties
+++ b/jbang/aws-bedrock-ingestion/application.properties
@@ -2,3 +2,4 @@ prompt=What is the average price of natural gas between 2010 and 2011?
sqsArn=<sqsArn>
knowledgeBaseId=<knowledge_base_id>
dataSourceId=<data_source_id>
+modelId=anthropic.claude-instant-v1
diff --git a/jbang/aws-bedrock-ingestion/aws-bedrock-knowledgebase-session.camel.yaml b/jbang/aws-bedrock-ingestion/aws-bedrock-knowledgebase-session.camel.yaml
new file mode 100644
index 0000000..54ae051
--- /dev/null
+++ b/jbang/aws-bedrock-ingestion/aws-bedrock-knowledgebase-session.camel.yaml
@@ -0,0 +1,43 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+- route:
+ from:
+ uri: "kamelet:timer-source"
+ parameters:
+ message: "What is the average natural gas price between 1998 and 1999?"
+ repeatCount: 1
+ steps:
+ - loop:
+ constant: 5
+ - log: "New Request to Knowledge Base ${body}"
+ - to:
+ uri: "kamelet:aws-bedrock-agent-runtime-sink"
+ parameters:
+ useDefaultCredentialsProvider: true
+ region: us-east-1
+ knowledgeBaseId: "{{knowledgeBaseId}}"
+ modelId: "{{modelId}}"
+ - to:
+ uri: "kamelet:log-sink"
+ parameters:
+ showHeaders: true
+ - log: "SessionId is ${headers.CamelAwsBedrockAgentRuntimeSessionId}"
+ - setBody:
+ simple: "What is the average natural gas price between ${random(2005,2020)} and ${random(2010,2020)}?"
+
+