Skip to content

Commit d28843f

Browse files
authored
Merge pull request #86 from Senparc/Developer
v0.15.4.5 添加RunSynct<T>() 方法
2 parents 6c8769a + 734c780 commit d28843f

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/Senparc.AI.Kernel/KernelConfigExtensions/KernelConfigExtensions.cs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static IWantToConfig ConfigModel(this IWantToConfig iWantToConfig, Config
6868
{
6969
return deploymentName;
7070
}
71-
else if(!senparcAiSetting.DeploymentName.IsNullOrEmpty())
71+
else if (!senparcAiSetting.DeploymentName.IsNullOrEmpty())
7272
{
7373
return senparcAiSetting.DeploymentName;
7474
}
@@ -321,7 +321,21 @@ public static bool GetStoredArguments(this SenparcAiRequest request, string key,
321321
/// <param name="request"></param>
322322
/// <param name="inStreamItemProceessing">启用流,并指定遍历异步流每一步需要执行的委托。注意:只要此项不为 null,则会触发流式的请求。</param>
323323
/// <returns></returns>
324-
public static async Task<SenparcKernelAiResult> RunAsync(this IWantToRun iWanToRun, SenparcAiRequest request, Action<StreamingKernelContent> inStreamItemProceessing = null)
324+
public static Task<SenparcKernelAiResult> RunAsync(this IWantToRun iWanToRun, SenparcAiRequest request, Action<StreamingKernelContent> inStreamItemProceessing = null)
325+
{
326+
return RunAsync<string>(iWanToRun, request, inStreamItemProceessing);
327+
}
328+
329+
/// <summary>
330+
/// 运行
331+
/// </summary>
332+
/// <param name="iWanToRun"></param>
333+
/// <param name="request"></param>
334+
/// <param name="inStreamItemProceessing">启用流,并指定遍历异步流每一步需要执行的委托。注意:只要此项不为 null,则会触发流式的请求。</param>
335+
/// <typeparam name="T">指定返回结果类型</typeparam>
336+
/// <returns></returns>
337+
338+
public static async Task<SenparcKernelAiResult> RunAsync<T>(this IWantToRun iWanToRun, SenparcAiRequest request, Action<StreamingKernelContent> inStreamItemProceessing = null)
325339
{
326340
var iWantTo = iWanToRun.IWantToBuild.IWantToConfig.IWantTo;
327341
var helper = iWanToRun.SemanticKernelHelper;
@@ -412,7 +426,23 @@ public static async Task<SenparcKernelAiResult> RunAsync(this IWantToRun iWanToR
412426

413427
if (!useStream)
414428
{
415-
result.Output = functionResult.GetValue<string>()?.TrimStart('\n') ?? "";
429+
try
430+
{
431+
result.Output = functionResult.GetValue<string>()?.TrimStart('\n') ?? "";
432+
433+
}
434+
catch (Exception)
435+
{
436+
//TODO: 提供 Output 的泛型
437+
try
438+
{
439+
result.Output = functionResult.GetValue<T>()?.ToJson()?.TrimStart('\n') ?? "";
440+
}
441+
catch (Exception)
442+
{
443+
result.Output = functionResult.GetValue<object>()?.ToJson()?.TrimStart('\n') ?? "";
444+
}
445+
}
416446
result.Result = functionResult;
417447
}
418448
else

src/Senparc.AI.Kernel/Senparc.AI.Kernel.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFramework>netstandard2.1</TargetFramework>
4-
<Version>0.15.4.3</Version>
4+
<Version>0.15.4.5</Version>
55
<Nullable>enable</Nullable>
66
<LangVersion>10.0</LangVersion>
77
<AssemblyName>Senparc.AI.Kernel</AssemblyName>

0 commit comments

Comments
 (0)