Skip to content

Commit

Permalink
include prgr text in product object
Browse files Browse the repository at this point in the history
  • Loading branch information
doncamilom committed Nov 27, 2023
1 parent bdad464 commit cefe0e9
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/jasyntho/extract/rxn_setup/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Product(Substance):

role: str = "product" # type: ignore
children: List[Substance]
text: Optional[str] = None
note: Optional[str] = None

@classmethod
Expand Down Expand Up @@ -130,12 +131,15 @@ def from_paragraph(cls, prgr: str, client: instructor.patch, llm: str):
max_retries=config.max_retries,
timeout=config.timeout,
)
return cls.from_substancelist(subs_list)
prd = cls.from_substancelist(subs_list)
except (openai.APITimeoutError, ValidationError) as e: # type: ignore
if isinstance(e, openai.APITimeoutError): # type: ignore
return cls.empty(note=e.message)
prd = cls.empty(note=e.message)
else:
return cls.empty(note="Validation error.")
prd = cls.empty(note="Validation error.")

prd.text = prgr
return prd

@classmethod
async def async_from_paragraph(
Expand All @@ -153,12 +157,15 @@ async def async_from_paragraph(
max_retries=config.max_retries,
timeout=config.timeout,
)
return cls.from_substancelist(subs_list)
prd = cls.from_substancelist(subs_list)
except (openai.APITimeoutError, ValidationError) as e: # type: ignore
if isinstance(e, openai.APITimeoutError): # type: ignore
return cls.empty(note=e.message)
prd = cls.empty(note=e.message)
else:
return cls.empty(note="Validation error.")
prd = cls.empty(note="Validation error.")

prd.text = prgr
return prd

@classmethod
def empty(cls, note):
Expand Down

0 comments on commit cefe0e9

Please sign in to comment.