Skip to content

Commit

Permalink
Merge pull request #71 from Encamina/@lmarcos/translate_prompt_function
Browse files Browse the repository at this point in the history
Added translate prompt function
  • Loading branch information
LuisM000 authored Feb 7, 2024
2 parents 2eeba37 + 8c11b07 commit 2e1c2e9
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Previous classification is not required if changes are simple or all belong to t
- Added `Description` property in `VersionSwaggerGenOptions`.
- New text prompt function for extract KeyPhrases with specified locale, `KeyPhrasesLocaled`.
- Added an example of using `KeyPhrasesLocaled` in `Encamina.Enmarcha.Samples.SemanticKernel.Text`.
- New text prompt function for translate texts, `Translate`.
- Added an example of using `Translate` in `Encamina.Enmarcha.Samples.SemanticKernel.Text`.

## [8.1.2]

Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<PropertyGroup>
<VersionPrefix>8.1.3</VersionPrefix>
<VersionSuffix>preview-02</VersionSuffix>
<VersionSuffix>preview-03</VersionSuffix>
</PropertyGroup>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,19 @@ public async Task TextKeyPhrasesLocaledAsync()

Console.WriteLine($"# Key Phrases Localed: {result} \n");
}

public async Task TextTranslateAsync()
{
var translateArguments = new KernelArguments()
{
[PluginsInfo.TextPlugin.Functions.Translate.Parameters.Input] = input,
[PluginsInfo.TextPlugin.Functions.Translate.Parameters.Locale] = "Spanish",
};

var functionTranslate = kernel.Plugins.GetFunction(PluginsInfo.TextPlugin.Name, PluginsInfo.TextPlugin.Functions.Translate.Name);

var result = await kernel.InvokeAsync<string>(functionTranslate, translateArguments);

Console.WriteLine($"# Translation: {result} \n");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@ private static async Task Main(string[] _)
await example.TextKeyPhrasesAsync();

await example.TextKeyPhrasesLocaledAsync();

await example.TextTranslateAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<EmbeddedResource Include="Plugins\TextPlugin\KeyPhrases\skprompt.txt" />
<EmbeddedResource Include="Plugins\TextPlugin\Summarize\config.json" />
<EmbeddedResource Include="Plugins\TextPlugin\Summarize\skprompt.txt" />
<EmbeddedResource Include="Plugins\TextPlugin\Translate\config.json" />
<EmbeddedResource Include="Plugins\TextPlugin\Translate\skprompt.txt" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"schema": 1,
"description": "Translate a given input text",
"execution_settings": {
"default": {
"max_tokens": 2000,
"temperature": 0.1,
"top_p": 1.0,
"presence_penalty": 0.0,
"frequency_penalty": 0.0
}
},
"input_variables": [
{
"name": "input",
"description": "The input text to translate",
"is_required": true
},
{
"name": "locale",
"description": "Language in which the translation will be generated",
"is_required": true
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Your task is TO TRANSLATE the INPUT text into the '{{$locale}}' language.
If the INPUT text is already in the '{{$locale}}' language, you must return the INPUT text without altering it.
MAKE SURE YOU ONLY USE '{{$locale}}' language.


[INPUT]

{{$input}}

[TRANSLATION]

27 changes: 27 additions & 0 deletions src/Encamina.Enmarcha.SemanticKernel.Plugins.Text/PluginsInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,33 @@ public static class Parameters
public static readonly string Locale = nameof(Locale).ToLowerInvariant();
}
}

/// <summary>
/// Information about the «Translate» function.
/// </summary>
public static class Translate
{
/// <summary>
/// The name of the function.
/// </summary>
public static readonly string Name = nameof(Translate);

/// <summary>
/// Information about the function's parameters.
/// </summary>
public static class Parameters
{
/// <summary>
/// The name of the «input» parameter, which represents the text to translate.
/// </summary>
public static readonly string Input = nameof(Input).ToLowerInvariant();

/// <summary>
/// The name of the «locale» parameter, which represents the language in which the translation will be generated.
/// </summary>
public static readonly string Locale = nameof(Locale).ToLowerInvariant();
}
}
}
}
}

0 comments on commit 2e1c2e9

Please sign in to comment.