# 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" sheet_data = oDoc.Sheets[0] sheet_data.Name = "APPRECIATIONS" return None