Skip to content

Commit

Permalink
增加切片参数
Browse files Browse the repository at this point in the history
  • Loading branch information
239573049 committed Apr 15, 2024
1 parent 6dd8174 commit f65b01c
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/Service/FastWiki.Service/Service/OpenAIService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Azure.AI.OpenAI;
using DocumentFormat.OpenXml.Office2013.PowerPoint.Roaming;
using FastWiki.Service.Application.Function.Queries;
using Microsoft.KernelMemory.DataFormats.Text;
using Microsoft.SemanticKernel;
using TokenApi.Service.Exceptions;

Expand Down Expand Up @@ -499,21 +500,29 @@ await context.WriteOpenAiResultAsync(message, module.model, requestId,
}
}

public static async ValueTask<string> QAAsync(string prompt, string value, string model, string apiKey, string url,
public static async IAsyncEnumerable<string> QAAsync(string prompt, string value, string model, string apiKey,
string url,
WikiMemoryService memoryService)
{
var kernel = memoryService.CreateFunctionKernel(apiKey, model, url);

var qaFunction = kernel.CreateFunctionFromPrompt(prompt, functionName: "QA", description: "QA问答");

var result = await kernel.InvokeAsync(qaFunction, new KernelArguments()

var lines = TextChunker.SplitPlainTextLines(value, 299);
var paragraphs = TextChunker.SplitPlainTextParagraphs(lines, 4000);

foreach (var paragraph in paragraphs)
{
var result = await kernel.InvokeAsync(qaFunction, new KernelArguments()
{
"input", value
}
});
{
"input", paragraph
}
});

return result.GetValue<string>();
yield return result.GetValue<string>();
}
}

private static bool IsVision(string model)
Expand Down

0 comments on commit f65b01c

Please sign in to comment.