aoptk.text_generation_api
Attributes
Exceptions
Base class for capturing LLM failures. |
Classes
Text generation API using OpenAI. |
Module Contents
- exception aoptk.text_generation_api.LLMFailureError[source]
Bases:
ExceptionBase class for capturing LLM failures.
- class aoptk.text_generation_api.TextGenerationAPI(model: str = 'gpt-oss-120b', url: str = 'https://llm.ai.e-infra.cz/v1', api_key: str = os.environ.get('CERIT_API_KEY'))[source]
Bases:
aoptk.find_chemical.FindChemical,aoptk.relationships.find_relationship.FindRelationship,aoptk.normalization.normalize_chemical.NormalizeChemical,aoptk.literature.convert_pdf_scan.ConvertPDFScan,aoptk.literature.convert_image.ConvertImage,aoptk.literature.find_relevant_publication.FindRelevantPublicationText generation API using OpenAI.
- prompts_dir: pathlib.Path[source]
- find_relationships_in_text(text: str, chemicals: list[aoptk.chemical.Chemical], effects: list[aoptk.effect.Effect], relationship_type: aoptk.relationship_type.RelationshipType) list[aoptk.relationships.relationship.Relationship][source]
Find relationships between chemicals and effects.
- _relationship_prompt(text: str, chemical: aoptk.chemical.Chemical, effect: aoptk.effect.Effect, relationship_type: aoptk.relationship_type.RelationshipType) str[source]
Classify the relationship between a chemical and an effect.
- Parameters:
text (str) – The input text.
chemical (Chemical) – The chemical entity.
effect (Effect) – The effect entity.
relationship_type (RelationshipType) – The relationship type to classify.
- _select_relationship_type(response: str, relationship_type: aoptk.relationship_type.RelationshipType) str | None[source]
Select the relationship type based on the response.
- Parameters:
response (str) – The response from the model indicating the relationship type.
relationship_type (RelationshipType) – The relationship type to classify.
- find_chemicals(text: str) list[aoptk.chemical.Chemical][source]
Find chemicals in the given text.
- Parameters:
text (str) – The input text to search for chemicals.
- _encode_image(image_path: str) tuple[str, str][source]
Encode the image at the given path to a base64 string and return MIME type.
- _process_colon_separated_response(response: str, effect: aoptk.effect.Effect, relationship_type: aoptk.relationship_type.RelationshipType, image_path: str) list[aoptk.relationships.relationship.Relationship][source]
Process the response from the model that is colon seperated.
- Parameters:
response (str) – The response from the model.
effect (Effect) – The effect entity.
relationship_type (RelationshipType) – The relationship type to classify.
context (str) – The path to the image, used for context in the relationship.
image_path (str) – The path to the image, used for context in the relationship.
- find_relationships_in_table(table_df: pandas.DataFrame, effects: list[aoptk.effect.Effect], relationship_type: aoptk.relationship_type.RelationshipType) list[aoptk.relationships.relationship.Relationship][source]
Find relationships between chemicals and effects in a table.
- Parameters:
table_df (pd.DataFrame) – Pandas DataFrame.
relationship_type (RelationshipType) – The relationship type to classify.
- _classify_relationships_in_table(table_df: pandas.DataFrame, effect: aoptk.effect.Effect, relationship_type: aoptk.relationship_type.RelationshipType) list[aoptk.relationships.relationship.Relationship][source]
Classify relationships between chemicals and an effect in a table.
- Parameters:
table_df (pd.DataFrame) – Pandas DataFrame.
effect (Effect) – The effect entity.
relationship_type (RelationshipType) – The relationship type to classify.
- Returns:
List of relationships found in the table.
- Return type:
- normalize_chemical(chemical: aoptk.chemical.Chemical, chemical_list: list[aoptk.chemical.Chemical]) aoptk.chemical.Chemical[source]
Normalize the chemical name by finding a matching name in the chemical list.
- _find_matching_name(chemical: aoptk.chemical.Chemical, chemical_list: list[aoptk.chemical.Chemical]) aoptk.chemical.Chemical | None[source]
Find a matching chemical name in the chemical list.
- convert_pdf_scan(img_base64: str, mime_type: str) str[source]
Extract text from a base64-encoded image.
- find_relationships_in_text_and_images(text: str, image_paths: list[str], relationship_type: aoptk.relationship_type.RelationshipType, effects: list[aoptk.effect.Effect]) list[aoptk.relationships.relationship.Relationship][source]
Find relationships between chemicals and effects in the given text and images combined.
- _classify_relationships_in_text_and_images(text: str, image_paths: list[str], effect: aoptk.effect.Effect, relationship_type: aoptk.relationship_type.RelationshipType) list[aoptk.relationships.relationship.Relationship][source]
Classify relationships between chemicals and an effect in the given text and images combined.
- Parameters:
text (str) – The input text.
effect (Effect) – The effect entity.
relationship_type (RelationshipType) – The relationship type to classify.