Browse Source

Merge branch 'develop' of http://132.232.92.186:3000/XinXiBu/OA2023 into develop

Lyyyi 1 week ago
parent
commit
820bb726ac

+ 40 - 107
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -24000,7 +24000,8 @@ And (UnitName != '' Or UnitName != null) {sqlWhere}");
                     group.TeamName,
                     group.Id,
                     visitStartDate = group.VisitStartDate.ToString("yyyy-MM-dd"),
-                    visitEndDate = group.VisitEndDate.ToString("yyyy-MM-dd")
+                    visitEndDate = group.VisitEndDate.ToString("yyyy-MM-dd"),
+                    group.ClientUnit
                 },
                 blackCodeList = blackCodeList.Select(x => new
                 {
@@ -25009,118 +25010,50 @@ And (UnitName != '' Or UnitName != null) {sqlWhere}");
             }
         }
 
-        //[HttpPost]
-        //public async Task<IActionResult> ServerHttp(string paramStr)
-        //{
-        //    paramStr = paramStr.TrimEnd('\'');
-        //    paramStr = paramStr.TrimStart('\'');
-        //    JsonView jw = JsonView(false);
-        //    JObject param = JObject.Parse(paramStr);
-        //    if (!param.ContainsKey("url"))
-        //    {
-        //        jw.Msg = "url null";
-        //        return Ok(jw);
-        //    }
-
-        //    string url = param["url"]!.ToString();
-        //    var methon = "get";
-
-        //    Dictionary<string, string> headValues = null;
-        //    string bodyStr = string.Empty;
-
-        //    if (param.ContainsKey("methon"))
-        //    {
-        //        methon = param["methon"]!.ToString().ToLower();
-        //    }
-
-        //    if (param.ContainsKey("header"))
-        //    {
-        //        var header = param["header"]!.ToString();
-        //        JObject headerJobject = JObject.Parse(header);
-        //        headValues = new Dictionary<string, string>();
-        //        foreach (JProperty item in headerJobject.Properties())
-        //        {
-        //            var value = item.Value.ToString();
-        //            var head = item.Path;
-        //            headValues.Add(head, value);
-        //        }
-        //    }
-
-        //    HttpClient client = new HttpClient();
-        //    string responseString = string.Empty;
-        //    StringContent content = null;
-
-        //    if (headValues != null)
-        //    {
-        //        foreach (var item in headValues.Keys)
-        //        {
-        //            if (item.ToLower().Contains("content") && item.ToLower().Contains("type"))
-        //            {
-        //                if (param.ContainsKey("body"))
-        //                {
-        //                    bodyStr = param["body"]!.ToString();
-        //                }
-        //                content = new StringContent(bodyStr, Encoding.UTF8, headValues[item]);
-        //            }
-        //            else
-        //            {
-        //                client.DefaultRequestHeaders.Add(item, headValues[item]);
-        //            }
-        //        }
-        //    }
-
-        //    try
-        //    {
-        //        if (methon == "get")
-        //        {
-        //            responseString = await client.GetStringAsync(url);
+        /// <summary>
+        /// 报批行程AI续写
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost]
+        public async Task<IActionResult> ApprovalJourneyAiWrite(ApprovalJourneyAiWriteDto dto)
+        {
+            var jw = JsonView(false);
 
-        //        }
-        //        else if (methon == "post")
-        //        {
-        //            var request = new HttpRequestMessage(HttpMethod.Post, url)
-        //            {
-        //                Content = content
-        //            };
-        //            var response = await client.SendAsync(request);
+            if (dto.ClientPurpose.IsNullOrWhiteSpace() || dto.ClientName.IsNullOrWhiteSpace())
+            {
+                jw.Msg = "参数有误!";
+                return Ok(jw);
+            }
 
-        //            try
-        //            {
-        //                Stream responseStream = await response.Content.ReadAsStreamAsync();
+            KiMiApiClient kiMi = new KiMiApiClient();
 
-        //                using (GZipStream gzipStream = new GZipStream(responseStream, CompressionMode.Decompress))
-        //                {
-        //                    using (StreamReader reader = new StreamReader(gzipStream))
-        //                    {
-        //                        responseString = await reader.ReadToEndAsync();
-        //                    }
-        //                }
-        //            }
-        //            catch (Exception)
-        //            {
-        //                responseString = await response.Content.ReadAsStringAsync();
-        //            }
+            List<SeedMessages> messages = new List<SeedMessages>() {
+                 new SeedMessages
+                    {
+                        Role = KimiRole.system,
+                        Content = "你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长中文和英文的对话。你会为用户提供安全,有帮助,准确的回答。"
+                    },
+                new SeedMessages
+                    {
+                         Role = KimiRole.user,
+                         Content = $@"参考这个模板格式来编写一份{dto.ClientName}拜访{dto.ClientPurpose},结合{dto.ClientName}的业务,描述拜访目的,字数在200字内(直接给出拜访目的,不输出其他内容)"
+                    }
+            };
 
-        //        }
-        //        else
-        //        {
-        //            responseString = "methon error";
-        //        }
+            var kimi_result = await kiMi.SeedMessageByFullConterObject(messages);
+            string data = kimi_result.Choices[0]?.Message.Content;
 
-        //        jw = JsonView(true, "success", responseString);
-        //    }
-        //    catch (Exception ex)
-        //    {
-        //        jw.Msg = "error " + ex.Message;
-        //        jw.Data = ex.StackTrace;
-        //    }
-        //    finally
-        //    {
-        //        client.Dispose();
-        //    }
+            if (string.IsNullOrWhiteSpace(data))
+            {
+                jw.Data = "Ai续写失败!";
+            }
+            else
+            {
+                jw = JsonView(true, "success!", data);
+            }
 
-        //    return Ok(jw);
-        //}
+            return Ok(jw);
+        }
 
         #endregion
 

+ 49 - 7
OASystem/OASystem.Api/OAMethodLib/KiMiApi/KiMiApi.cs

@@ -1,5 +1,4 @@
-
-using OASystem.Domain.Dtos.Groups;
+using OASystem.Domain.Dtos.Groups;
 using OASystem.Domain.Dtos.KiMi;
 using System.Net.Http.Headers;
 
@@ -87,11 +86,26 @@ namespace OASystem.API.OAMethodLib.KiMiApi
         }
 
         public async Task<string> SeedMessage(List<SeedMessages> messages)
+        {
+            string completionResponseContent = await SeedAsync(messages);
+             // 解析返回的完成结果
+            var completion = JObject.Parse(completionResponseContent);
+            string reply = completion["choices"][0]["message"].ToString();
+            return reply;
+        }
+
+        public async Task<KiMiRoot> SeedMessageByFullConterObject(List<SeedMessages> messages)
+        {
+            var respStr =  await SeedAsync(messages);
+            return JsonConvert.DeserializeObject<KiMiRoot>(respStr);
+        }
+
+        private async Task<string> SeedAsync(List<SeedMessages> messages)
         {
             var completionRequest = new
             {
                 model = _kimiSetting.Model,
-                messages = messages.Select(x=> new
+                messages = messages.Select(x => new
                 {
                     Role = StringEnumHelper.ToStringValue(x.Role),
                     x.Content
@@ -110,10 +124,7 @@ namespace OASystem.API.OAMethodLib.KiMiApi
                 throw new Exception($"Failed to seed message: {completionResponseContent}");
             }
 
-            // 解析返回的完成结果
-            var completion = JObject.Parse(completionResponseContent);
-            string reply = completion["choices"][0]["message"].ToString();
-            return reply;
+            return completionResponseContent;
         }
     }
 
@@ -124,6 +135,37 @@ namespace OASystem.API.OAMethodLib.KiMiApi
         public string Content { get; set; }
     }
 
+
+    public class KiMiRoot
+    {
+        public string Id { get; set; }
+        public string Object { get; set; }
+        public long Created { get; set; }
+        public string Model { get; set; }
+        public List<Choice> Choices { get; set; }
+        public Usage Usage { get; set; }
+    }
+
+    public class Choice
+    {
+        public int Index { get; set; }
+        public ReturnMessage Message { get; set; }
+        public string FinishReason { get; set; }
+    }
+
+    public class Usage
+    {
+        public int PromptTokens { get; set; }
+        public int CompletionTokens { get; set; }
+        public int TotalTokens { get; set; }
+    }
+
+    public class ReturnMessage
+    {
+        public string Role { get; set; }
+        public string Content { get; set; }
+    }
+
     public enum KimiRole
     {
         system,

+ 13 - 5
OASystem/OASystem.Domain/Dtos/Groups/ApprovalJourneyDto.cs

@@ -15,8 +15,8 @@ namespace OASystem.Domain.Dtos.Groups
     public class CreateApprovalJourneyDto
     {
         public int Diid { get; set; }
-        
-        public int Userid { get; set;}
+
+        public int Userid { get; set; }
 
         public int BlackCodeId { get; set; }
     }
@@ -32,6 +32,14 @@ namespace OASystem.Domain.Dtos.Groups
         public int FileIndex { get; set; } = 1;
     }
 
+    public class ApprovalJourneyAiWriteDto
+    {
+        public string ClientName { get; set; }
+
+        public string ClientPurpose { get; set; }
+    }
+
+
     public class SaveApprovalJourney
     {
         public List<ApprovalJourneyItem> Arr { get; set; }
@@ -51,16 +59,16 @@ namespace OASystem.Domain.Dtos.Groups
         /// 时间区间
         /// </summary>
         public List<string> timeInterval { get; set; }
-        
+
         /// <summary>
         /// 详细信息
         /// </summary>
         public string details { get; set; }
-        
+
         /// <summary>
         /// 父级Id
         /// </summary>
-        
+
         public int parentId { get; set; }
         /// <summary>
         /// id