You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

103 lines
4.3 KiB

# Script pour un usage avec libreoffice CALC
#
# Generation_Appreciations :
# génère les appréciations à partir d'une série de paramètres (voir fichier sample_appreciations.ods)
# Generation_Appreciations_Generales :
# génère la synthèse des appréciations des disciplines
import uno
from openai import OpenAI
client = OpenAI(api_key="sk-proj-hrV9Se3D3Vn6ro66AoMFT3BlbkFJ3kgB6P9xQFpcaymQQHFI")
def Generation_Appreciations():
promptCol = -1
answerCol = 9
oDoc = XSCRIPTCONTEXT.getDocument()
sheet = oDoc.getCurrentController().getActiveSheet()
row = 1
content = "rédige un commentaire de bulletin de fin d'année scolaire, maximum 300 caractères, tutoiement de l'élève, commentaire sur la moyenne trimestrielle et éventuellement sur la moyenne annuelle, ne pas indiquer de valeur chiffrée."
while sheet[row,0].String!="":
prompt = sheet[row,0].String+", moyenne du trimestre "+sheet[row,2].String+"/20, moyenne annuelle "+sheet[row,1].String+"/20, comportement en classe niveau "+sheet[row,7].String+"/5, participation orale niveau "+sheet[row,8].String+"/3"
if sheet[row,5].String!="":
if int(sheet[row,5].String)>2:
prompt += ", nombre oublis de matériel "+sheet[row,5].String
if sheet[row,6].String!="":
if int(sheet[row,6].String)>2:
prompt += ", nombre exercices non faits "+sheet[row,6].String
if sheet[row,3].String!="":
if int(sheet[row,3].String)>2:
prompt += ", nombre absences "+sheet[row,3].String
if sheet[row,4].String!="":
if int(sheet[row,4].String)>2:
prompt += ", nombre de retards "+sheet[row,4].String
if promptCol != -1:
sheet[row,promptCol].String = prompt
if answerCol != -1:
chat_completion = client.chat.completions.create(
messages=[
{"role": "system","content": content},
{"role": "user","content": prompt}],
model="ft:gpt-3.5-turbo-1106:personal:bulletins2:9S8U7KuE",
temperature=0.6,
presence_penalty=0.6,
frequency_penalty=0.6,
top_p=0.5);
sheet[row,answerCol].String = chat_completion.choices[0].message.content
row = row+1
return None
def Generation_Appreciations_Generales():
#Préparation du document
oDoc = XSCRIPTCONTEXT.getDocument()
if oDoc.Sheets.Count== 1:
oDoc.Sheets.insertNewByName('SYNTHESES', 1)
sheet_syntheses = oDoc.Sheets[1]
sheet_syntheses.Name = "SYNTHESES"
sheet_syntheses['A1'].String="NOM"
sheet_syntheses['B1'].String="PRENOM"
sheet_syntheses['C1'].String="APPRECIATION"
else:
sheet_syntheses = oDoc.Sheets[1]
sheet_data = oDoc.Sheets[0]
sheet_data.Name = "APPRECIATIONS"
prompt=""
row=1
row_answer=1
progress=True
eleve=sheet_data[row,0].String
sheet_syntheses[row_answer,0].String = sheet_data[row,0].String
sheet_syntheses[row_answer,1].String = sheet_data[row,1].String
content = "Rédige une appréciation générale (500 caractères max) en utilisant la liste suivante qui contient une apprécation par ligne au format 'MATIERE':'APPRECIATION'"
while progress:
if sheet_data[row,0].String==eleve:
prompt += "\'"+sheet_data[row,2].String+"\':\'"+sheet_data[row,4].String+"\'\r\n"
else:
if sheet_data[row,0].String=="":
progress=False
else:
eleve=sheet_data[row,0].String
sheet_syntheses[row_answer+1,0].String = sheet_data[row,0].String
sheet_syntheses[row_answer+1,1].String = sheet_data[row,1].String
chat_completion = client.chat.completions.create(
messages=[
{"role": "system","content": content},
{"role": "user","content": prompt}],
model="ft:gpt-3.5-turbo-1106:personal:app-gen-gangneux:9TaoLDSI",
temperature=0.6,
presence_penalty=0.6,
frequency_penalty=0.6,
top_p=0.5);
sheet_syntheses[row_answer,2].String = chat_completion.choices[0].message.content
row_answer+=1
prompt = ""
row+=1
return None