@@ -56,7 +56,7 @@ class ParsedResult:
56
56
57
57
58
58
__ID_COLUMN__ = Column (
59
- name = "id " ,
59
+ name = "[[@item_id]] " ,
60
60
type = "text" ,
61
61
description = "Unique identifier for each item" ,
62
62
prompt = "Fill in the unique identifier for the corresponding <section> that represents the item" ,
@@ -561,17 +561,20 @@ async def _llm_summarize(
561
561
The summarized items as a list of dictionaries.
562
562
"""
563
563
564
- if scraping_type == "list-like" :
565
- prompt = MULTI_COLUMN_SCRAPING_PROMPT
566
- output_columns = [__ID_COLUMN__ , * output_columns ]
567
- else :
568
- prompt = SINGLE_COLUMN_SCRAPING_PROMPT
564
+ prompt = (
565
+ MULTI_COLUMN_SCRAPING_PROMPT
566
+ if scraping_type == "list-like"
567
+ else SINGLE_COLUMN_SCRAPING_PROMPT
568
+ )
569
+
570
+ # add id column to the output columns
571
+ output_columns_with_id = [__ID_COLUMN__ , * output_columns ]
569
572
570
573
messages = [
571
574
ChatCompletionSystemMessageParam (
572
575
role = "system" ,
573
576
content = prompt .format (
574
- column_defs = json .dumps (output_columns , ensure_ascii = False )
577
+ column_defs = json .dumps (output_columns_with_id , ensure_ascii = False )
575
578
),
576
579
),
577
580
ChatCompletionUserMessageParam (
@@ -619,9 +622,19 @@ async def _llm_summarize(
619
622
620
623
results = []
621
624
622
- for row in csv .DictReader (final_response_content .splitlines ()):
623
- index = int (row .pop ("id" ))
624
- results .append (SummaryItem (hash = parsed_result .hashes [index ], values = row ))
625
+ try :
626
+ for row in csv .DictReader (final_response_content .splitlines ()):
627
+ index = int (row .pop (__ID_COLUMN__ ["name" ]))
628
+ results .append (
629
+ SummaryItem (
630
+ hash = parsed_result .hashes [index ],
631
+ values = row ,
632
+ )
633
+ )
634
+ except Exception as e :
635
+ await ctx .send_error_message (
636
+ f"[{ self .name } ] Error parsing the response: { str (e )} "
637
+ )
625
638
626
639
return results
627
640
0 commit comments