Skip to content

Commit 9d379d4

Browse files
Correction amani/llm_json
1 parent fadaf5f commit 9d379d4

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

app/processor/analyze_content.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,31 +159,31 @@ def parse_json_response(response_text):
159159
return None, f"Erreur d'analyse: {str(e)}"
160160

161161
# Fonction pour générer le prompt à partir des attributs à chercher
162-
def get_prompt_from_attributes(dfAttributes: pd.DataFrame ):
162+
def get_prompt_from_attributes(df_attributes: pd.DataFrame ):
163163
question = """Extrait les informations clés et renvoie-les uniquement au format JSON spécifié, sans texte supplémentaire.
164164
165165
Format de réponse (commence par "{" et termine par "}") :
166166
{
167167
"""
168-
for idx, row in dfAttributes.iterrows():
168+
for idx, row in df_attributes.iterrows():
169169
attr = row["attribut"]
170-
if idx != dfAttributes.index[-1]:
170+
if idx != df_attributes.index[-1]:
171171
question+=f""" "{attr}": "", \n"""
172172
else:
173173
question+=f""" "{attr}": "" \n"""
174174
question+="""}
175175
176176
Instructions d'extraction :\n\n"""
177-
for idx, row in dfAttributes.iterrows():
177+
for idx, row in df_attributes.iterrows():
178178
consigne = row["consigne"]
179-
if idx != dfAttributes.index[-1]:
179+
if idx != df_attributes.index[-1]:
180180
question+=f"""{consigne}\n"""
181181
else:
182182
question+=f"""{consigne}"""
183183
return question
184184

185-
def create_response_format(dfAttributes, classification):
186-
l_output_field = select_attr(dfAttributes, classification).output_field.tolist()
185+
def create_response_format(df_attributes, classification):
186+
l_output_field = select_attr(df_attributes, classification).output_field.tolist()
187187
response_format = {
188188
"type": "json_schema",
189189
"json_schema": {
@@ -192,7 +192,7 @@ def create_response_format(dfAttributes, classification):
192192
"schema": {
193193
"type": "object",
194194
"properties": {output_field: {"type": "string"} for output_field in l_output_field},
195-
"required": list(dfAttributes.output_field)
195+
"required": list(df_attributes.output_field)
196196
}
197197
}
198198
}
@@ -202,7 +202,7 @@ def df_analyze_content(api_key,
202202
base_url,
203203
llm_model,
204204
df: pd.DataFrame,
205-
dfAttributes: pd.DataFrame,
205+
df_attributes: pd.DataFrame,
206206
temperature: float = 0.0,
207207
max_workers: int = 4,
208208
save_path: str = None,
@@ -224,7 +224,7 @@ def df_analyze_content(api_key,
224224
dfResult['llm_response'] = None
225225
dfResult['json_error'] = None
226226

227-
for attr in dfAttributes.attribut:
227+
for attr in df_attributes.attribut:
228228
dfResult[attr] = None
229229

230230
llm_env = LLMEnvironment(
@@ -238,8 +238,8 @@ def process_row(idx):
238238
row = df.loc[idx]
239239
classification = row['classification']
240240
try:
241-
question = get_prompt_from_attributes(select_attr(dfAttributes, classification))
242-
response_format = create_response_format(dfAttributes, classification)
241+
question = get_prompt_from_attributes(select_attr(df_attributes, classification))
242+
response_format = create_response_format(df_attributes, classification)
243243
context = row['relevant_content']
244244

245245
if(context == ""):
@@ -250,7 +250,6 @@ def process_row(idx):
250250
question=question,
251251
response_format=response_format,
252252
temperature=temperature)
253-
print(response)
254253
data, error = parse_json_response(response)
255254

256255
result = {
@@ -259,7 +258,7 @@ def process_row(idx):
259258
}
260259

261260
if not error:
262-
for attr in dfAttributes.attribut:
261+
for attr in df_attributes.attribut:
263262
result.update({f'{attr}': data.get(attr, '')})
264263
else:
265264
print(f"Erreur lors de l'analyse du fichier {row["filename"]}: {error}")

0 commit comments

Comments
 (0)