-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: SageMaker customizable inputs and responses
- Loading branch information
Showing
10 changed files
with
202 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
70 changes: 0 additions & 70 deletions
70
src/Providers/Amazon.Sagemaker/src/Chat/SageMakerChatModel.cs
This file was deleted.
Oops, something went wrong.
54 changes: 0 additions & 54 deletions
54
src/Providers/Amazon.Sagemaker/src/Chat/SageMakerChatSettings.cs
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
src/Providers/Amazon.Sagemaker/src/Internal/BedrockExtensions.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.Diagnostics; | ||
using System.Text; | ||
using System.Text.Json; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace LangChain.Providers.Amazon.SageMaker; | ||
|
||
public class SageMakerModel( | ||
SageMakerProvider provider, | ||
string endpointName) | ||
: ChatModel(id: endpointName ?? throw new ArgumentNullException(nameof(endpointName), "SageMaker Endpoint Name is not defined")) | ||
{ | ||
public override async Task<ChatResponse> GenerateAsync( | ||
ChatRequest request, | ||
ChatSettings? settings = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
request = request ?? throw new ArgumentNullException(nameof(request)); | ||
|
||
var messages = request.Messages.ToList(); | ||
|
||
var watch = Stopwatch.StartNew(); | ||
|
||
var usedSettings = SageMakerSettings.Calculate( | ||
requestSettings: settings, | ||
modelSettings: Settings, | ||
providerSettings: provider.ChatSettings); | ||
usedSettings.InputParamers?.Add("endpointName", Id); | ||
|
||
using StringContent jsonContent = new( | ||
JsonSerializer.Serialize(usedSettings.InputParamers), | ||
Encoding.UTF8, | ||
usedSettings.ContentType!); | ||
|
||
using var response = await provider.HttpClient.PostAsync(provider.Uri, jsonContent, cancellationToken) | ||
.ConfigureAwait(false); | ||
|
||
response.EnsureSuccessStatusCode(); | ||
|
||
dynamic output = usedSettings.TransformOutput!(response); | ||
messages.Add(new Message(output.Result, MessageRole.Ai)); | ||
|
||
var usage = Usage.Empty with | ||
{ | ||
Time = watch.Elapsed, | ||
}; | ||
AddUsage(usage); | ||
provider.AddUsage(usage); | ||
|
||
return new ChatResponse | ||
{ | ||
Messages = messages, | ||
UsedSettings = usedSettings, | ||
Usage = usage, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.