-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
.Net: add amazon nova support (text) only #10021
base: main
Are you sure you want to change the base?
Conversation
@microsoft-github-policy-service agree
@microsoft-github-policy-service agree |
@@ -76,7 +77,7 @@ internal async Task<IReadOnlyList<TextContent>> InvokeBedrockModelAsync( | |||
try | |||
{ | |||
var requestBody = this._ioTextService.GetInvokeModelRequestBody(this._modelId, prompt, executionSettings); | |||
using var requestBodyStream = new MemoryStream(JsonSerializer.SerializeToUtf8Bytes(requestBody)); | |||
using var requestBodyStream = new MemoryStream(JsonSerializer.SerializeToUtf8Bytes(requestBody, new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommend using the options serializer as a static instance, avoiding instantiation each request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
/// <summary> | ||
/// Converts the streaming JSON into <see cref="IEnumerable{String}"/> for output. | ||
/// </summary> | ||
/// <param name="chunk">The payloadPart bytes provided from the streaming response.</param> | ||
/// <returns><see cref="IEnumerable{String}"/> output strings.</returns> | ||
internal IEnumerable<string> GetTextStreamOutput(JsonNode chunk); | ||
internal IEnumerable<string> GetTextStreamOutput(string modelId, JsonNode chunk); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the latest merge from my changes this signature needs to be updated to return StreamingChatMessageContent
instead of string
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
var requestBody = new TitanRequest.TitanTextGenerationRequest() | ||
if (modelId.StartsWith("amazon.nova-", StringComparison.OrdinalIgnoreCase)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strongly suggest to move this service to AmazonNovaService
and not mix this with titan as the models (API contracts) are also different.
When moving to AmazonNovaService
implementation, revert the extra modalId
from the interface and feel free to rename the existing AmazonService
to titan specific AmazonTitanService
.
It's clear that the responsibility to know with model should be only in the factory for this perspective, avoiding bringing extra complexity to the service level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -75,7 +75,7 @@ public ConverseRequest GetConverseRequest(string modelId, ChatHistory chatHistor | |||
} | |||
|
|||
/// <inheritdoc/> | |||
public IEnumerable<string> GetTextStreamOutput(JsonNode chunk) | |||
public IEnumerable<string> GetTextStreamOutput(string modelId, JsonNode chunk) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note
Apply to all services
Revert this change as all the services were designed to not use the modelId
information, worth having a specific service to handle the different Nova
requests.
public IEnumerable<string> GetTextStreamOutput(string modelId, JsonNode chunk) | |
public IEnumerable<string> GetTextStreamOutput(JsonNode chunk) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
/// Prompt execution settings for Nova Text Generation | ||
/// </summary> | ||
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)] | ||
public class AmazonNovaExecutionSettings : PromptExecutionSettings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing this specific Nova
execution settings feels even stronger the need to have a dedicated concrete service for Nova models within Amazon
's folder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, I re-organized stuff.
@EriksonBahr Thanks for the amazing contribution, some extra conflicts needs to be addressed. Happy new year! 🎉 |
@EriksonBahr, let me know if you plan on applying the suggestions above. |
Should get this moving next week |
7a2e36d
to
0d1bee7
Compare
I synced with main and re-done my commit following the updated interfaces. Also, updated the structure, indeed looks much better now. |
Motivation and Context
Add support for amazon nova.
Description
This PR adds amazon nova support. Also re-structures existing Titan files.
Contribution Checklist