FCLT#80553 OpenAI gebruiken voor het genereren van afmeldteksten en kennisbankitems

svn path=/Website/trunk/; revision=64724
This commit is contained in:
2024-05-17 10:44:09 +00:00
parent cc64e6b9f3
commit df33edc0c4
2 changed files with 43 additions and 17 deletions

View File

@@ -8,12 +8,13 @@
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/disciplineselector.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/xml_converter.inc" -->
<%
FCLTHeader.Requires({ plugins: ["jQuery"],
js: [] });
var urole = getQParamSafe("urole");
var mld_key = getQParamInt('mld_key');
var mld_key = getQParamInt("mld_key");
var faq_key = -1;
//var faq_question = unescape(getQParam("faq_question"));
//var faq_answer = unescape(getQParam("faq_answer"));
@@ -63,20 +64,37 @@ var authparams = user.checkAutorisation("WEB_FAQFOF");
<body class="modal" id="mod_mldcontinue">
<% MODAL_START();
sql = "SELECT mld_melding_omschrijving"
+ " , mld_melding_opmerking"
+ " FROM mld_melding mm"
+ " , mld_stdmelding std"
+ " , mld_discipline md"
+ " , ins_srtdiscipline sd"
+ " WHERE mld_melding_key = " + mld_key
+ " AND mm.mld_stdmelding_key = std.mld_stdmelding_key"
+ " AND std.mld_ins_discipline_key = md.ins_discipline_key"
+ " AND md.ins_srtdiscipline_key = sd.ins_srtdiscipline_key";
oRs = Oracle.Execute(sql);
mld_omsc = oRs("mld_melding_omschrijving").value || "";
mld_opmr = oRs("mld_melding_opmerking").value || "";
oRs.close();
var sgQuestion = "";
var sgAnswer = "";
if (S("ai_enabled") & 4) {
var xml = make_xml({ xmlnode: "melding", key: mld_key });
var result = shared.promptAI(xml, { "instructions": L("lcl_mld_ai_faq_instructions"), "response_format": "json_object" });
if (result.success) {
try {
var content = JSON.parse(result.content);
sgQuestion = content.question;
sgAnswer = content.answer;
} catch (e) {
// Dan hieronder de ouderwetse manier
}
}
}
if (sgQuestion == "" || sgAnswer == "") {
sql = "SELECT mld_melding_omschrijving"
+ " , mld_melding_opmerking"
+ " FROM mld_melding mm"
+ " , mld_stdmelding std"
+ " , mld_discipline md"
+ " , ins_srtdiscipline sd"
+ " WHERE mld_melding_key = " + mld_key
+ " AND mm.mld_stdmelding_key = std.mld_stdmelding_key"
+ " AND std.mld_ins_discipline_key = md.ins_discipline_key"
+ " AND md.ins_srtdiscipline_key = sd.ins_srtdiscipline_key";
oRs = Oracle.Execute(sql);
sgQuestion = (oRs("mld_melding_omschrijving").value || "").substring(0, 400);
sgAnswer = oRs("mld_melding_opmerking").value || "";
oRs.close();
}
%>
<form id="faqform" name="faqform" action="mld_2faq_save.asp?mld_key=<%=mld_key%>&urole=<%=urole%>" method="post">
<%
@@ -92,8 +110,8 @@ var authparams = user.checkAutorisation("WEB_FAQFOF");
required: true,
autfunctionKey: authparams.autfunctionkeys
});
RWTEXTAREATR("fac_question", "fldtxt required", L("lcl_faq_question"), String(mld_omsc).substring(0, 200), {html: "rows='6'"});
RWTEXTAREATR("fac_answer", "fldtxt required", L("lcl_faq_answer"), mld_opmr, {html: "rows='6' maxlength='4000'"});
RWTEXTAREATR("fac_question", "fldtxt required", L("lcl_faq_question"), sgQuestion, {html: "rows='6'"});
RWTEXTAREATR("fac_answer", "fldtxt required", L("lcl_faq_answer"), sgAnswer, {html: "rows='6' maxlength='4000'"});
RWTEXTAREATR("fac_answer2", "fldtxt", L("lcl_faq_answer2"), "", {html: "rows='3' maxlength='4000'"});
var sql= " SELECT 1, " + safe.quoted_sql(L("lcl_faq_level1")) + " FROM DUAL"
+ " UNION ALL SELECT 2, " + safe.quoted_sql(L("lcl_faq_level2")) + " FROM DUAL"

View File

@@ -605,6 +605,9 @@ var shared = {
content: params.instructions
});
}
if ("response_format" in params) {
body.response_format = { "type": params.response_format };
}
body.messages.push({
role: "user",
content: msg
@@ -662,6 +665,11 @@ var shared = {
} else {
try {
var openAIresponse = JSON.parse(http.responseText);
if (openAIresponse.error.code === "context_length_exceeded" && S("openai_model_large_context")) {
__DoLog("Prompt-context te groot voor " + body.model + ", probeer opnieuw met " + S("openai_model_large_context"), "#FFFF00");
params.model = S("openai_model_large_context");
return shared.promptAI(msg, params);
}
result.warning = "[" + http.status + "] - OpenAI [" + openAIresponse.error.code + "] - " + openAIresponse.error.message;
__DoLog(result.warning, "#FF0000");
__DoLog(body);