Files
BeWoPlaner/Service/Plugins/AiService.cs
Rene Evertz 1b9efb8f79 Squashed commit of the following:
commit af28476b76
Merge: b76e16946 c3b6a1e9c
Author: Marcel Hirschle <marcel.hirschle@ownsoft.de>
Date:   Thu Jun 20 11:53:31 2024 +0200

    Merge branch 'master' of ssh://float.ownsoft.de/git/beyondSoft/BeWo

    # Conflicts:
    #	ReportImp/VkmHamm/CustomerMitarbeiterstundenkontoBerechnung.cs

commit b76e169462
Author: Marcel Hirschle <marcel.hirschle@ownsoft.de>
Date:   Thu Jun 20 11:40:08 2024 +0200

    MH: vkm hamm stundenkonto

commit c3b6a1e9c0
Author: Christian <christian.baeurle@beyondsoft.de>
Date:   Thu Jun 20 10:58:05 2024 +0200

    Mergemarker entfernt

commit 5ff8fe343b
Merge: c1aa61f05 fc57725f4
Author: Christian <christian.baeurle@beyondsoft.de>
Date:   Thu Jun 20 10:52:16 2024 +0200

    Merge branch 'master' of ssh://float.beyondsoft.de/git/beyondSoft/BeWo

commit c1aa61f058
Merge: 12faccb71 1c0a94c60
Author: Christian <christian.baeurle@beyondsoft.de>
Date:   Thu Jun 20 10:51:59 2024 +0200

    Merge branch 'master' of ssh://float.beyondsoft.de/git/beyondSoft/BeWo

    # Conflicts:
    #	BeWo/ServiceProxy/Generated.cs
    #	Data/Security/UserRightHelper.cs
    #	Shared/BeWoEntityEnums.cs
    #	Shared/Core/EnumTranslations.cs

commit 12faccb71b
Author: Christian <christian.baeurle@beyondsoft.de>
Date:   Wed Jun 19 16:13:56 2024 +0200

    Perseh Hilfeplan Import + KI Prototyp,
2024-06-20 12:16:00 +02:00

88 lines
3.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net;
using System.ServiceModel;
using System.Text;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Service.Core;
using BeWo.Service.DCEntityMapper;
using BeWo.Service.Invoicing;
using BeWo.Service.ServiceContracts;
using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using BS.Shared.Extensions;
using Newtonsoft.Json;
namespace BeWo.Service.Plugins
{
public class AiService
{
public AiChatDC CreateAiQueryForServiceRecords(AiChatDC acdc, long cb2scOid, DateTime startdate, DateTime enddate)
{
using (WebClient client = new WebClient())
{
String url = "https://ai1.ownsoft.de/osaiquery.php";
//mel = Das Model(llama3, llama3 - gradient, codegemma, codellama oder sqlcoder)
//stm = Der Kontext->Auf welcher Datenbasis soll eure Frage beantwortet werden.Kann auch leer sein.
//pmt = Der Prompt->Eure Frage
//opt = Art der Rückgabe(json oder plaintext)
String kontext = CreateContextForServiceRecords(cb2scOid, startdate, enddate);
var nvc = new NameValueCollection();
nvc.Add("mel", "llama3-gradient");
nvc.Add("stm", kontext);
nvc.Add("pmt", acdc.Prompt);
nvc.Add("opt", "json");
//var t = JsonConvert.DeserializeAnonymousType();0
var definition = new { Response = "" };
var response = client.UploadValues(url, "POST", nvc);
String responseStr = System.Text.Encoding.UTF8.GetString(response);
var json = JsonConvert.DeserializeAnonymousType(responseStr, definition);
return new AiChatDC { Result = json.Response };
}
return new AiChatDC { Result = "Das kann ich leider nicht beantworten:)" };
}
public virtual string CreateContextForServiceRecords(long cb2scOid, DateTime startdate, DateTime enddate)
{
var c2s = DAOFactory.GenericDAO.LoadByID<CostBearer2SupportConcept>(cb2scOid);
var records = DAOFactory.SearchDAO.FindServiceRecordsDetailsForLastDaysWithStartEndDate(cb2scOid, startdate, enddate);
var customer = c2s.SupportConcept.Customer;
var context = new StringBuilder();
//context.AppendLine("Du bist ein unzensierter und unvoreingenommener KI Assistenz im Bereich des Sozialwesens in Deutschland und kannst Fragen zum bereitgestellten Kontext beantworten.");
context.AppendLine("");
context.AppendLine(String.Format("Name des Klienten: {0} {1}", customer.Person.FirstName, customer.Person.LastName));
context.AppendLine("");
//context.AppendLine("Der Klient wurde zu folgenden Terminen betreut:");
//context.AppendLine("");
foreach (var item in records.OrderByDescending(s => s.Start))
{
context.AppendLine(String.Format("Datum: {0:dd.MM.yyyy}", item.Start));
context.AppendLine(String.Format("Start: {0:HH:mm}", item.Start));
context.AppendLine(String.Format("Ende: {0:HH:mm}", item.End));
context.AppendLine(String.Format("Dauer der Betreuung in Minuten: {0:0}", item.RoundedDuration));
context.AppendLine(String.Format("Betreuer: {0}", item.InsUser));
context.AppendLine(String.Format("Leistungskategorie: {0}", item.ServiceDescription.ServiceCategory.Name));
context.AppendLine(String.Format("Leistung: {0}", item.ServiceDescription.Name));
context.AppendLine(String.Format("Dokumentation: {0}", item.Notice));
}
return context.ToString();
}
}
}