Skip to content

Commit

Permalink
Merge pull request #80 from Encamina/@lmarcos/sk_question_function_im…
Browse files Browse the repository at this point in the history
…provements

@lmarcos/sk question function improvements
  • Loading branch information
LuisM000 authored Feb 19, 2024
2 parents 08cf111 + 1c4df58 commit f12d534
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ Also, any bug fix must start with the prefix �Bug fix:� followed by the desc

Previous classification is not required if changes are simple or all belong to the same category.

## [8.1.5]

### Breaking Changes
In the `QuestionAnsweringFromMemoryQuery` function of the `QuestionAnsweringPlugin`, null is no longer returned when there are no relevant memory results. Instead, the execution flow continues, prompting a message with an empty context information, ultimately resulting in a response such as "I don't know" or a similar message.

### Minor Changes
- Changes in the prompt of `QuestionAnsweringPlugin` to enhance language detection in the response.

## [8.1.4]

### Major Changes
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>8.1.4</VersionPrefix>
<VersionPrefix>8.1.5-preview-01</VersionPrefix>
</PropertyGroup>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,36 @@ namespace Encamina.Enmarcha.SemanticKernel.Plugins.QuestionAnswering.Plugins;
public class QuestionAnsweringPlugin
{
private const string QuestionAnsweringFromContextFunctionPrompt = @"
You ANSWER questions with information from the CONTEXT.
ONLY USE information from CONTEXT
The ANSWER MUST BE ALWAYS in {{$locale}}.
If you are unable to find the answer or do not know it, simply say ""I don't know"".
The ""I don't know"" response MUST BE TRANSLATED ALWAYS to {{$locale}}.
If presented with a logic question about the CONTEXT, attempt to calculate the answer.
ALWAYS RESPOND with a FINAL ANSWER, DO NOT CONTINUE the conversation.
[CONTEXT]
{{$context}}
[END CONTEXT]
[INSTRUCTIONS]
1. You ANSWER questions with information from the [CONTEXT].
2. ONLY USE information from [CONTEXT].
3. If you are unable to find the answer or do not know it, simply say ""I don't know"".
4. The ""I don't know"" response MUST BE TRANSLATED ALWAYS to {{$locale}}.
5. If presented with a logic question about the [CONTEXT], attempt to calculate the answer.
6. ALWAYS RESPOND with a FINAL ANSWER, DO NOT CONTINUE the conversation.
7. The [ANSWER] MUST BE ALWAYS in {{$locale}}.
[END INSTRUCTIONS]
[QUESTION]
{{$input}}
[END QUESTION]
[IMPORTANT]
- Remember, your [ANSWER] MUST ALWAYS BE in {{$locale}}.
[END IMPORTANT]
[ANSWER]
";
Expand Down Expand Up @@ -106,12 +122,6 @@ public virtual async Task<string> QuestionAnsweringFromMemoryQueryAsync(

var memoryQueryResult = memoryQueryFunctionResult.GetValue<string>();

// If the «QueryMemory» function from the «MemoryQueryPlugin» does not return any result, there is no point in trying to answering the question. In such a case, `null` is returned.
if (string.IsNullOrWhiteSpace(memoryQueryResult))
{
return null;
}

// Return to the context of the response function and set the result of the memory query.
var questionAnsweringVariables = new KernelArguments()
{
Expand Down Expand Up @@ -157,7 +167,7 @@ private static string GetAnswerLocale(string locale)
{
return string.IsNullOrWhiteSpace(locale)
? "the SAME LANGUAGE as the QUESTION"
: $"{locale} LANGUAGE";
: $"\"{locale}\" LANGUAGE";
}

private Task<int> GetQuestionAnsweringFromContextFunctionUsedTokensAsync(KernelFunction questionAnsweringFromContextFunction, string input, string locale, CancellationToken cancellationToken)
Expand Down

0 comments on commit f12d534

Please sign in to comment.