-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Fody.ConfigureAwait to modules; Fix Disposable pattern in OpenAiC…
…lient; Update to 2.7.1
- Loading branch information
Showing
18 changed files
with
341 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<Version>2.7.1</Version> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
</PropertyGroup> | ||
</Project> |
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
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,3 @@ | ||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> | ||
<ConfigureAwait /> | ||
</Weavers> |
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
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,3 @@ | ||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> | ||
<ConfigureAwait /> | ||
</Weavers> |
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
79 changes: 79 additions & 0 deletions
79
OpenAI.ChatGpt.Modules.Translator/OpenAiClientExtensions.cs
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,79 @@ | ||
using System.Text.Json; | ||
using OpenAI.ChatGpt.Models.ChatCompletion; | ||
|
||
namespace OpenAI.ChatGpt.Modules.Translator; | ||
|
||
[Fody.ConfigureAwait(false)] | ||
public static class OpenAiClientExtensions | ||
{ | ||
public static Task<string> TranslateText( | ||
this IOpenAiClient client, | ||
string text, | ||
string sourceLanguage, | ||
string targetLanguage, | ||
string? extraPrompt = null, | ||
int? maxTokens = null, | ||
string? model = null, | ||
float temperature = ChatCompletionTemperatures.Default, | ||
string? user = null, | ||
Action<ChatCompletionRequest>? requestModifier = null, | ||
Action<ChatCompletionResponse>? rawResponseGetter = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
ArgumentNullException.ThrowIfNull(client); | ||
ArgumentNullException.ThrowIfNull(text); | ||
ArgumentNullException.ThrowIfNull(sourceLanguage); | ||
ArgumentNullException.ThrowIfNull(targetLanguage); | ||
|
||
var translator = new ChatGPTTranslatorService(client, extraPrompt: extraPrompt); | ||
return translator.TranslateText( | ||
text, | ||
sourceLanguage, | ||
targetLanguage, | ||
maxTokens, | ||
model, | ||
temperature, | ||
user, | ||
requestModifier, | ||
rawResponseGetter, | ||
cancellationToken); | ||
} | ||
|
||
public static Task<TObject> TranslateObject<TObject>( | ||
this IOpenAiClient client, | ||
TObject objectToTranslate, | ||
string sourceLanguage, | ||
string targetLanguage, | ||
string? extraPrompt = null, | ||
int? maxTokens = null, | ||
string? model = null, | ||
float temperature = ChatCompletionTemperatures.Default, | ||
string? user = null, | ||
Action<ChatCompletionRequest>? requestModifier = null, | ||
Action<ChatCompletionResponse>? rawResponseGetter = null, | ||
JsonSerializerOptions? jsonSerializerOptions = null, | ||
JsonSerializerOptions? jsonDeserializerOptions = null, | ||
CancellationToken cancellationToken = default) where TObject: class | ||
{ | ||
ArgumentNullException.ThrowIfNull(client); | ||
ArgumentNullException.ThrowIfNull(objectToTranslate); | ||
ArgumentNullException.ThrowIfNull(sourceLanguage); | ||
ArgumentNullException.ThrowIfNull(targetLanguage); | ||
|
||
var translator = new ChatGPTTranslatorService(client, extraPrompt: extraPrompt); | ||
return translator.TranslateObject( | ||
objectToTranslate, | ||
sourceLanguage, | ||
targetLanguage, | ||
maxTokens, | ||
model, | ||
temperature, | ||
user, | ||
requestModifier, | ||
rawResponseGetter, | ||
jsonSerializerOptions, | ||
jsonDeserializerOptions, | ||
cancellationToken | ||
); | ||
} | ||
} |
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
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.