Find answers from the community

Updated 7 months ago

Hi! I am using `TreeSummarize` class:

Hi! I am using TreeSummarize class:

Plain Text
class Data(BaseModel):
  summary: str
  themes: List[str]

summarizer = TreeSummarize(output_cls=Data)
response summarizer.get_response(...my_data_list[:300]...)


and getting this error:

Plain Text
ValidationError: 2 validation errors for SummaryAndThemes
summary
  field required (type=value_error.missing)
themes
  field required (type=value_error.missing)


but when I send the whole dataset:

Plain Text
...
response summarizer.get_response(...my_data_list...)
...


it works fine.


I understand that this type of errors are coming from OpenAI and there is not much what LlamaIndex can do, but how can we handle such errors? What can we do from our side?
L
p
2 comments
Its better practice to give some more info in an output cls

Plain Text
from pydantic.v1 import BaseModel, Field

class Data(BaseModel):
  """Represents a summary and themes extracted from text."""
  summary: str = Field(description="A summary of some text.")
  themes: List[str] = Field(description="Themes extracted from the text.")


Beyond that, its mostly just a matter of try/except πŸ˜…
currently I'm using the power of try except hahaha:

Plain Text
RETRIES = 5

for i in range(RETRIES):
  try:
    ...
    break
  except Exception as e:
     if i == RETRIES - 1:
       raise e
     pass

πŸ˜‚


thank you for reminding me that I can use Field in class parameters tho πŸ‘
Hope that will help
Add a reply
Sign up and join the conversation on Discord