Comments (4)
@JulesMBooth Good morning. Thanks for opening the issue. Could you please enable verbose logging using code below and share the detailed logs:
Amazon.AWSConfigs.LoggingConfig.LogResponses = Amazon.ResponseLoggingOption.Always;
Amazon.AWSConfigs.LoggingConfig.LogTo = Amazon.LoggingOptions.Console;
Amazon.AWSConfigs.AddTraceListener("Amazon", new System.Diagnostics.ConsoleTraceListener());
Also, could you examine the behavior of the similar API call made using AWS CLI (preferably with --debug
switch to examine detailed logs)?
Thanks,
Ashish
from aws-sdk-net.
Hi,
I noticed when attempting the request by CLI that I had missed a parameter in the RetrieveAndGenerateConfiguration object: "Type" I set that to "KNOWLEDGE_BASE". Having examined the error response to that I realised I could only pass in a Session Id once I had got a response. So my code now looks like:
....
Console.WriteLine("Please enter the Knowledge Base Id");
string? kbId = Console.ReadLine();
Console.WriteLine("Please enter your first prompt, after this type exit to stop prompting bedrock.");
var input = Console.ReadLine();
var sessionId = "";
while (input?.ToUpperInvariant() != "EXIT")
{
var response = await InvokeBedrockRetrieveAndGenerateKnowledgeBaseAsync(kbId, input, sessionId);
if (response != null)
{
Console.WriteLine(response.Output.Text);
sessionId = response.SessionId;
}
else
{
Console.WriteLine("Error Occurred");
}
Console.WriteLine("Please write your next prompt or type exit to leave.");
input = Console.ReadLine();
}
.....
public static async Task<RetrieveAndGenerateResponse> InvokeBedrockRetrieveAndGenerateKnowledgeBaseAsync(string knowledgeBaseId, string prompt, string sessionId = "")
{
RetrieveAndGenerateResponse? result = null;
try
{
AmazonBedrockAgentRuntimeClient client = new(RegionEndpoint.USEast1);
Console.WriteLine($"Calling bedrock with Knowledge Base Id: {knowledgeBaseId}, prompt: {prompt} and {(String.IsNullOrWhiteSpace(sessionId) ? "No session Id" : $"Session Id: {sessionId}")}.");
var request = new RetrieveAndGenerateRequest
{
Input = new RetrieveAndGenerateInput
{
Text = prompt
},
RetrieveAndGenerateConfiguration = new RetrieveAndGenerateConfiguration
{
Type = "KNOWLEDGE_BASE",
KnowledgeBaseConfiguration = new KnowledgeBaseRetrieveAndGenerateConfiguration
{
KnowledgeBaseId = knowledgeBaseId,
ModelArn = "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-v2",
}
},
};
if (!String.IsNullOrWhiteSpace(sessionId))
request.SessionId = sessionId;
RetrieveAndGenerateResponse response = await client.RetrieveAndGenerateAsync(request);
if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
{
result = response;
}
else
{
Console.WriteLine("InvokeModelAsync failed with status code " + response.HttpStatusCode);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
return result;
}
And this works as expected. Not clear from the .Net docs how RetrieveAndGenerateConfiguration.Type should be set however so that could be improved.
I also found that I coudn't get requests to work on the CLI I have attached output.
BedrockCLI.txt
from aws-sdk-net.
@JulesMBooth Thanks for the update and glad that it works for you now. AWS CLI appears to be failing with error Could not connect to the endpoint URL.
. Unsure about the root cause of the error.
Regarding documentation:
- Agents for Amazon Bedrock Runtime RetrieveAndGenerateConfiguration API reference does specify valid values (currently only
KNOWLEDGE_BASE
) fortype
property. - The AWS .NET SDK API reference for RetrieveAndGenerateConfiguration does not appear to specify list of valid values. This would be the case with any property, not just this property.
- This is also the case with Java SDK API reference here.
- The API reference for SDK(s) are generated from the models shared by service team, for AWS .NET SDK it's here. These are same across all SDK(s).
- I would advise you to submit the feedback request by clicking link. It would be routed through appropriate channels.
Closing this ticket for now since this is no longer an issue.
Thanks,
Ashish
from aws-sdk-net.
Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
from aws-sdk-net.
Related Issues (20)
- DynamoDB AttributeValue roundtrip of empty number or string sets HOT 13
- V4 Development: General strategy on how to fill in missing APIs HOT 5
- TransferUtility does not support downloading objects in Requester Pays buckets. HOT 10
- DisableFetchingTableMetadata leads to key exception if PropertyConverter is used HOT 3
- `region` set in profile in `$HOME/.aws/config` is ignored HOT 11
- TransferUtilityUploadRequest.UploadProgressEvent event not firing HOT 10
- V4 Development: TargetFrameworks HOT 2
- V4 Development: Sensible LangVersion
- Record Support in DynamoDBContext HOT 3
- Null QueueUrl when using LocalStack HOT 3
- DisableFetchingTableMetadata leads to InvalidOperationException if PropertyConverter is used HOT 6
- AWSSDK.S3 ListObjectsV2 API returns Size incorrectly every other request for some subset of files +/- 2 bytes HOT 6
- V4 Development: DefineConstants requires an overhaul HOT 1
- AmazonS3Client.PutObjectAsync does not retry with HttpClient HttpCompletionOption.ResponseHeadersRead when using devproxy HOT 3
- Amazon.CloudWatch.Model.MetricDatum timestamp is not set correctly HOT 3
- connectCases:Add retry if created customer or case is not immediately available HOT 6
- Unable to use S3 Path Style Access S3 URL HOT 3
- Cannot Get DynamoDB record when model inherits from base class with member with the same name HOT 8
- Unable to connect to Timestream from using endpoint (.Net) HOT 1
- DynamoDB SDK convert Nullable DateTime to Local HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-sdk-net.