Skip to content

Commit

Permalink
修复已知错误
Browse files Browse the repository at this point in the history
  • Loading branch information
@kk502 committed May 26, 2024
1 parent 6c74fc7 commit 83acf69
Show file tree
Hide file tree
Showing 22 changed files with 262 additions and 121 deletions.
12 changes: 0 additions & 12 deletions aibotPro/aibotPro/.config/dotnet-tools.json

This file was deleted.

51 changes: 46 additions & 5 deletions aibotPro/aibotPro/AppCode/WorkflowEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Spire.Presentation;
using Spire.Presentation.Charts;
using StackExchange.Redis;
using System;
using System.Diagnostics;
using System.Security.AccessControl;
using System.Security.Principal;
Expand Down Expand Up @@ -42,7 +43,8 @@ public class WorkflowEngine
private readonly IServiceProvider _serviceProvider;
private readonly IHubContext<ChatHub> _hubContext;
private readonly IRedisService _redisService;
public WorkflowEngine(WorkFlowNodeData workflowData, IAiServer aiServer, ISystemService systemService, IFinanceService financeService, AIBotProContext context, string account, IServiceProvider serviceProvider, IHubContext<ChatHub> hubContext, string chatId, string senMethod, IRedisService redisService)
private readonly IMilvusService _milvusService;
public WorkflowEngine(WorkFlowNodeData workflowData, IAiServer aiServer, ISystemService systemService, IFinanceService financeService, AIBotProContext context, string account, IServiceProvider serviceProvider, IHubContext<ChatHub> hubContext, string chatId, string senMethod, IRedisService redisService, IMilvusService milvusService)
{
_workflowData = workflowData;
_aiServer = aiServer;
Expand All @@ -55,6 +57,7 @@ public WorkflowEngine(WorkFlowNodeData workflowData, IAiServer aiServer, ISystem
_chatId = chatId;
_senMethod = senMethod;
_redisService = redisService;
_milvusService = milvusService;
}
public async Task<List<NodeOutput>> Execute(string startNodeOutput)
{
Expand Down Expand Up @@ -194,7 +197,20 @@ private async Task<List<NodeOutput>> ExecuteFlow(string startNodeOutput)
{
if (!string.IsNullOrEmpty(nodeOutput.OutputData))
{
result.Add(nodeOutput);
// 查找是否已经有相同NodeName的NodeOutput
var existingItem = result.FirstOrDefault(no => no.NodeName == nodeOutput.NodeName);

if (existingItem != null)
{
// 如果存在,替换旧的NodeOutput
int index = result.IndexOf(existingItem);
result[index] = nodeOutput;
}
else
{
// 如果不存在,添加新的NodeOutput到列表
result.Add(nodeOutput);
}
}
}
}
Expand Down Expand Up @@ -659,7 +675,7 @@ private async Task<NodeOutput> ProcessDALLNode(NodeData node, List<NodeOutput> r
string savePath = Path.Combine("wwwroot", "files/dallres", _account);
await _aiServer.DownloadImageAsync(airesult, savePath, newFileName);
var aiSaveService = scope.ServiceProvider.GetRequiredService<IAiServer>(); // 假设保存记录方法在IAiSaveService中。
await aiSaveService.SaveAiDrawResult(_account, "DALLE3", imgResPath, "workflow_Engine", "workflow_Engine");
await aiSaveService.SaveAiDrawResult(_account, "DALLE3", imgResPath, prompt, "workflow_Engine");
}
});
nodeOutput.NodeName = nodeName + nodeId;
Expand Down Expand Up @@ -734,7 +750,7 @@ private async Task<NodeOutput> ProcessDALLsmNode(NodeData node, List<NodeOutput>
string savePath = Path.Combine("wwwroot", "files/dallres", _account);
await _aiServer.DownloadImageAsync(airesult, savePath, newFileName);
var aiSaveService = scope.ServiceProvider.GetRequiredService<IAiServer>(); // 假设保存记录方法在IAiSaveService中。
await aiSaveService.SaveAiDrawResult(_account, "DALLE2", imgResPath, "workflow_Engine", "workflow_Engine");
await aiSaveService.SaveAiDrawResult(_account, "DALLE2", imgResPath, prompt, "workflow_Engine");
}
});
nodeOutput.NodeName = nodeName + nodeId;
Expand Down Expand Up @@ -882,7 +898,32 @@ private async Task<NodeOutput> ProcessKonwledgeNode(NodeData node, List<NodeOutp
searchVectorPr.filter = $"account = '{_account}'";
searchVectorPr.topk = knowledgeData.Output.TopK;
searchVectorPr.vector = vectorList[0];
SearchVectorResult searchVectorResult = vectorHelper.SearchVector(searchVectorPr);
List<string> typeCode = knowledgeData.Output.TypeCode;
//SearchVectorResult searchVectorResult = vectorHelper.SearchVector(searchVectorPr);
SearchVectorResult searchVectorResult = new SearchVectorResult();
if (typeCode != null && typeCode.Count > 0)
{
List<float> vectorByMilvus = searchVectorPr.vector.ConvertAll(x => (float)x);
var resultByMilvus = await _milvusService.SearchVector(vectorByMilvus, _account, typeCode, searchVectorPr.topk);
searchVectorResult = new SearchVectorResult
{
code = resultByMilvus.Code,
request_id = Guid.NewGuid().ToString(),
message = string.Empty,
output = resultByMilvus.Data.Select(data => new Output
{
id = data.Id,
fields = new Fields
{
account = string.Empty,
knowledge = data.VectorContent
},
score = (double)data.Distance
}).ToList()
};
}
else
searchVectorResult = vectorHelper.SearchVector(searchVectorPr);
string data = string.Empty;
if (searchVectorResult.output != null)
{
Expand Down
23 changes: 15 additions & 8 deletions aibotPro/aibotPro/Controllers/OpenAPIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,25 @@ public async Task<IActionResult> Completions()
//不是会员且余额为0时不提供服务
if (!isVip && user.Mcoin <= 0)
{
throw new Exception("本站已停止向【非会员且余额为0】的用户提供服务,您可以前往充值1元及以上,长期使用本站的免费服务");
return Ok("本站已停止向【非会员且余额为0】的用户提供服务,您可以前往充值1元及以上,长期使用本站的免费服务");
}

// 检查用户余额是否不足,只有在需要收费时检查
if (shouldCharge && user.Mcoin <= 0)
{
throw new Exception("余额不足,请充值后再使用,您可以前往充值");
return Ok("余额不足,请充值后再使用,您可以前往充值");
}
//记录系统使用日志
await _systemService.WriteLog($"用户调用API:{chatSession.Model}", Dtos.LogLevel.Info, Account);
List<WorkShopAIModel> aImodels = new List<WorkShopAIModel>();
aImodels = _systemService.GetWorkShopAImodel();
if (aImodels == null || aImodels.Count == 0)
{
throw new Exception("模型不存在");
return Ok("模型不存在");
}
if (aImodels.Where(x => x.ModelName == chatSession.Model).FirstOrDefault() == null)
{
throw new Exception("模型不存在");
return Ok("模型不存在");
}
OpenAiOptions openAiOptions = new OpenAiOptions();
openAiOptions.BaseDomain = aImodels.Where(x => x.ModelName == chatSession.Model).FirstOrDefault().BaseUrl;
Expand Down Expand Up @@ -330,6 +330,10 @@ await response.Body.WriteAsync(msgBytes,
await response.Body.FlushAsync();// 确保立即发送消息
output += chatCompletionResponse.Choices[0].delta.Content;
}
else
{
return Ok("模型未回复,请重试");
}
var tools = choice.Message.ToolCalls;
if (tools != null)
{
Expand All @@ -348,7 +352,7 @@ await response.Body.WriteAsync(msgBytes,
case "dalle3":
if (!string.IsNullOrEmpty(pluginResDto.errormsg) || string.IsNullOrEmpty(pluginResDto.result))
{
throw new Exception("Draw Fail");
return Ok("Draw Fail");
}
res = $"绘制完成 图片地址:{pluginResDto.result}";
break;
Expand Down Expand Up @@ -465,6 +469,8 @@ await response.Body.WriteAsync(msgBytes,
if (completionResult.Successful)
{
var choice = completionResult.Choices.First();
if (choice == null || choice.Message == null)
return Ok("模型未回复,请重试");
if (choice.Message.ToolCalls != null && choice.Message.ToolCalls[0].FunctionCall != null)
{
var fn = choice.Message.ToolCalls[0].FunctionCall;
Expand All @@ -479,7 +485,7 @@ await response.Body.WriteAsync(msgBytes,
case "dalle3":
if (!string.IsNullOrEmpty(pluginResDto.errormsg) || string.IsNullOrEmpty(pluginResDto.result))
{
throw new Exception("Draw Fail");
return Ok("Draw Fail");
}
res = $"绘制完成 图片地址:{pluginResDto.result}";
break;
Expand Down Expand Up @@ -579,11 +585,12 @@ await response.Body.WriteAsync(msgBytes,
}
}
}
throw new Exception("Error");
return Ok("error");
}
catch (Exception e)
{
throw e;
await _systemService.WriteLog(e.Message, Dtos.LogLevel.Error, "system");
return Ok(e.Message);
}

}
Expand Down
2 changes: 2 additions & 0 deletions aibotPro/aibotPro/Dtos/WorkFlowNodeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ public class Konwledge
public int Retry { get; set; }
[JsonProperty("topk")]
public int TopK { get; set; }
[JsonProperty("typecode")]
public List<string> TypeCode { get; set; }
}
public class EndOutput
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<DeleteExistingFiles>false</DeleteExistingFiles>
<DeleteExistingFiles>true</DeleteExistingFiles>
<ExcludeApp_Data>false</ExcludeApp_Data>
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<Project>
<PropertyGroup>
<_PublishTargetUrl>D:\VSdemoPush\AIBotPRO</_PublishTargetUrl>
<History>True|2024-05-21T02:16:47.1933621Z;True|2024-05-18T02:23:05.6515039+08:00;True|2024-05-18T00:33:34.5095168+08:00;True|2024-05-14T23:45:15.9030381+08:00;True|2024-05-14T19:00:55.6341074+08:00;True|2024-05-14T17:13:52.5478701+08:00;True|2024-05-13T04:25:12.5467049+08:00;True|2024-05-13T01:44:02.2096068+08:00;True|2024-05-13T01:41:40.6658374+08:00;True|2024-05-13T01:22:05.9513321+08:00;True|2024-05-13T01:21:47.0411709+08:00;True|2024-05-12T20:41:21.4625449+08:00;True|2024-05-12T01:25:49.3741757+08:00;True|2024-05-11T00:36:33.6900336+08:00;True|2024-05-11T00:35:42.7046391+08:00;True|2024-05-10T00:20:15.0395526+08:00;True|2024-05-09T01:24:19.0631611+08:00;True|2024-05-09T00:43:51.4199517+08:00;True|2024-05-08T00:28:09.9518881+08:00;True|2024-05-08T00:23:13.4558043+08:00;True|2024-05-08T00:07:59.7680181+08:00;True|2024-05-02T01:03:14.6311716+08:00;True|2024-04-29T02:22:08.4746665+08:00;True|2024-04-29T00:17:38.5035250+08:00;True|2024-04-28T23:59:28.9917647+08:00;True|2024-04-26T00:10:27.7445249+08:00;True|2024-04-23T01:30:37.6768866+08:00;True|2024-04-23T00:48:14.5734865+08:00;True|2024-04-23T00:11:21.2642059+08:00;True|2024-04-17T22:03:14.0209432+08:00;True|2024-04-16T23:31:45.4904127+08:00;True|2024-04-13T19:21:59.0302533+08:00;True|2024-04-13T18:58:28.9264697+08:00;True|2024-04-13T05:33:26.4813048+08:00;True|2024-04-13T05:13:20.9770193+08:00;True|2024-04-10T02:24:18.6295740+08:00;True|2024-04-10T00:39:48.6198222+08:00;True|2024-04-08T00:24:19.4359801+08:00;True|2024-04-07T23:50:43.6071658+08:00;True|2024-04-07T01:12:26.5533469+08:00;True|2024-04-07T00:43:56.5552998+08:00;True|2024-04-07T00:39:21.3379439+08:00;True|2024-04-06T17:21:04.3043952+08:00;True|2024-04-05T02:55:32.9429986+08:00;True|2024-04-04T04:07:41.2501774+08:00;True|2024-04-04T03:53:10.8291446+08:00;True|2024-04-03T22:43:45.5710990+08:00;True|2024-04-03T00:10:26.4855901+08:00;True|2024-04-02T23:33:44.5375815+08:00;True|2024-04-02T02:07:31.8671366+08:00;True|2024-04-02T01:57:06.9534372+08:00;True|2024-04-02T00:36:02.0548374+08:00;True|2024-04-02T00:15:55.8075496+08:00;True|2024-04-01T23:57:31.1397373+08:00;True|2024-04-01T23:52:36.9511083+08:00;True|2024-04-01T23:40:50.9679343+08:00;True|2024-03-25T22:59:45.7135876+08:00;True|2024-03-25T01:37:33.2347496+08:00;True|2024-03-21T01:10:45.8809381+08:00;True|2024-03-20T23:42:34.4221941+08:00;True|2024-03-19T22:19:17.3268675+08:00;True|2024-03-19T22:15:25.0722518+08:00;True|2024-03-19T22:08:15.4905716+08:00;True|2024-03-19T01:04:44.9760500+08:00;True|2024-03-17T23:39:34.0352088+08:00;True|2024-03-17T08:31:23.5063725+08:00;True|2024-03-17T06:37:59.4183114+08:00;True|2024-03-17T06:37:27.0050941+08:00;True|2024-03-17T06:32:51.6628157+08:00;True|2024-03-17T06:03:58.9767100+08:00;True|2024-03-17T05:09:18.9285417+08:00;True|2024-03-17T05:03:51.1403040+08:00;True|2024-03-15T21:54:20.7306218+08:00;True|2024-03-15T02:27:06.3007171+08:00;True|2024-03-15T02:18:16.5382941+08:00;True|2024-03-15T02:16:34.5159231+08:00;True|2024-03-15T01:47:40.6505319+08:00;True|2024-03-15T01:38:52.4149526+08:00;True|2024-03-13T22:26:16.3031907+08:00;True|2024-03-13T17:22:18.3512709+08:00;True|2024-03-13T10:21:25.5131621+08:00;True|2024-03-11T17:34:04.8687102+08:00;True|2024-03-11T17:26:27.3873869+08:00;True|2024-03-08T17:17:06.8450054+08:00;True|2024-03-08T11:37:37.1180423+08:00;True|2024-03-07T15:56:21.1999674+08:00;True|2024-03-05T01:10:10.0710862+08:00;True|2024-03-04T14:01:44.6177022+08:00;True|2024-03-03T19:55:06.1013727+08:00;True|2024-03-03T18:15:37.8484692+08:00;True|2024-03-03T12:21:48.1679155+08:00;True|2024-03-03T00:16:48.7641081+08:00;True|2024-03-02T04:52:08.4562277+08:00;True|2024-03-02T04:40:24.4469334+08:00;True|2024-03-02T04:19:45.9907382+08:00;True|2024-03-02T03:44:02.2101754+08:00;True|2024-03-02T03:41:50.6931359+08:00;True|2024-03-02T02:25:10.1162115+08:00;True|2024-03-02T02:21:16.3141505+08:00;True|2024-03-01T19:01:47.7699379+08:00;</History>
<History>True|2024-05-25T18:46:44.7140982Z;True|2024-05-26T02:46:14.2619095+08:00;True|2024-05-24T18:14:25.7273450+08:00;True|2024-05-24T17:20:32.0801007+08:00;True|2024-05-24T01:43:51.2645313+08:00;True|2024-05-23T18:52:51.9569553+08:00;True|2024-05-23T18:52:23.8576708+08:00;True|2024-05-23T18:49:36.0410836+08:00;True|2024-05-23T17:57:52.3867879+08:00;True|2024-05-23T17:33:35.3307943+08:00;True|2024-05-21T10:16:47.1933621+08:00;True|2024-05-18T02:23:05.6515039+08:00;True|2024-05-18T00:33:34.5095168+08:00;True|2024-05-14T23:45:15.9030381+08:00;True|2024-05-14T19:00:55.6341074+08:00;True|2024-05-14T17:13:52.5478701+08:00;True|2024-05-13T04:25:12.5467049+08:00;True|2024-05-13T01:44:02.2096068+08:00;True|2024-05-13T01:41:40.6658374+08:00;True|2024-05-13T01:22:05.9513321+08:00;True|2024-05-13T01:21:47.0411709+08:00;True|2024-05-12T20:41:21.4625449+08:00;True|2024-05-12T01:25:49.3741757+08:00;True|2024-05-11T00:36:33.6900336+08:00;True|2024-05-11T00:35:42.7046391+08:00;True|2024-05-10T00:20:15.0395526+08:00;True|2024-05-09T01:24:19.0631611+08:00;True|2024-05-09T00:43:51.4199517+08:00;True|2024-05-08T00:28:09.9518881+08:00;True|2024-05-08T00:23:13.4558043+08:00;True|2024-05-08T00:07:59.7680181+08:00;True|2024-05-02T01:03:14.6311716+08:00;True|2024-04-29T02:22:08.4746665+08:00;True|2024-04-29T00:17:38.5035250+08:00;True|2024-04-28T23:59:28.9917647+08:00;True|2024-04-26T00:10:27.7445249+08:00;True|2024-04-23T01:30:37.6768866+08:00;True|2024-04-23T00:48:14.5734865+08:00;True|2024-04-23T00:11:21.2642059+08:00;True|2024-04-17T22:03:14.0209432+08:00;True|2024-04-16T23:31:45.4904127+08:00;True|2024-04-13T19:21:59.0302533+08:00;True|2024-04-13T18:58:28.9264697+08:00;True|2024-04-13T05:33:26.4813048+08:00;True|2024-04-13T05:13:20.9770193+08:00;True|2024-04-10T02:24:18.6295740+08:00;True|2024-04-10T00:39:48.6198222+08:00;True|2024-04-08T00:24:19.4359801+08:00;True|2024-04-07T23:50:43.6071658+08:00;True|2024-04-07T01:12:26.5533469+08:00;True|2024-04-07T00:43:56.5552998+08:00;True|2024-04-07T00:39:21.3379439+08:00;True|2024-04-06T17:21:04.3043952+08:00;True|2024-04-05T02:55:32.9429986+08:00;True|2024-04-04T04:07:41.2501774+08:00;True|2024-04-04T03:53:10.8291446+08:00;True|2024-04-03T22:43:45.5710990+08:00;True|2024-04-03T00:10:26.4855901+08:00;True|2024-04-02T23:33:44.5375815+08:00;True|2024-04-02T02:07:31.8671366+08:00;True|2024-04-02T01:57:06.9534372+08:00;True|2024-04-02T00:36:02.0548374+08:00;True|2024-04-02T00:15:55.8075496+08:00;True|2024-04-01T23:57:31.1397373+08:00;True|2024-04-01T23:52:36.9511083+08:00;True|2024-04-01T23:40:50.9679343+08:00;True|2024-03-25T22:59:45.7135876+08:00;True|2024-03-25T01:37:33.2347496+08:00;True|2024-03-21T01:10:45.8809381+08:00;True|2024-03-20T23:42:34.4221941+08:00;True|2024-03-19T22:19:17.3268675+08:00;True|2024-03-19T22:15:25.0722518+08:00;True|2024-03-19T22:08:15.4905716+08:00;True|2024-03-19T01:04:44.9760500+08:00;True|2024-03-17T23:39:34.0352088+08:00;True|2024-03-17T08:31:23.5063725+08:00;True|2024-03-17T06:37:59.4183114+08:00;True|2024-03-17T06:37:27.0050941+08:00;True|2024-03-17T06:32:51.6628157+08:00;True|2024-03-17T06:03:58.9767100+08:00;True|2024-03-17T05:09:18.9285417+08:00;True|2024-03-17T05:03:51.1403040+08:00;True|2024-03-15T21:54:20.7306218+08:00;True|2024-03-15T02:27:06.3007171+08:00;True|2024-03-15T02:18:16.5382941+08:00;True|2024-03-15T02:16:34.5159231+08:00;True|2024-03-15T01:47:40.6505319+08:00;True|2024-03-15T01:38:52.4149526+08:00;True|2024-03-13T22:26:16.3031907+08:00;True|2024-03-13T17:22:18.3512709+08:00;True|2024-03-13T10:21:25.5131621+08:00;True|2024-03-11T17:34:04.8687102+08:00;True|2024-03-11T17:26:27.3873869+08:00;True|2024-03-08T17:17:06.8450054+08:00;True|2024-03-08T11:37:37.1180423+08:00;True|2024-03-07T15:56:21.1999674+08:00;True|2024-03-05T01:10:10.0710862+08:00;True|2024-03-04T14:01:44.6177022+08:00;True|2024-03-03T19:55:06.1013727+08:00;True|2024-03-03T18:15:37.8484692+08:00;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>
Loading

0 comments on commit 83acf69

Please sign in to comment.