API Reference
Classes
Base extractor
BaseExtractior
A class to handle any extraction using OpenAI's GPT models.
Source code in code/NLI_base_extractor.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
__init__(openai_client)
Initializes the BaseExtractior with an OpenAI client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
openai_client
|
OpenAI | AsyncOpenAI
|
An instance of OpenAI or AsyncOpenAI client to interact with the API. |
required |
Source code in code/NLI_base_extractor.py
11 12 13 14 15 16 17 18 19 20 21 | |
Node extractor
NodeExtractor
Bases: BaseExtractior
A class to handle node extraction from a given text description using OpenAI's GPT models.
Source code in code/NLI_node_extraction.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
__init__(openai_client)
Initializes the NodeExtractor with an OpenAI client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
openai_client
|
OpenAI | AsyncOpenAI
|
An instance of OpenAI or AsyncOpenAI client to interact with the API. |
required |
Source code in code/NLI_node_extraction.py
17 18 19 20 21 22 23 24 | |
extract_nodes_gpt(description, gpt_model='gpt-4o-mini', temperature=0.0)
Extracts nodes from a given description using a specified GPT model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
description
|
str
|
The text description from which nodes need to be extracted. |
required |
gpt_model
|
str
|
The GPT model to use for extraction. Defaults to 'gpt-4o-mini'. |
'gpt-4o-mini'
|
temperature
|
float
|
The randomness of the model's output. Defaults to 0.0. |
0.0
|
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: A list of extracted nodes from the description. |
Source code in code/NLI_node_extraction.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
Edge extrctor
Code for vertices extraction.
This module provides functionality to extract edges between nodes in a graph using OpenAI's GPT models. It includes methods to determine the existence and direction of edges based on a textual description.
The module contains the following functions:
- _extract_one_edge_gpt: Determines the existence and direction of an edge between a pair of nodes.
- extract_all_edges: Extracts all possible edges from a set of nodes based on a given description.
ArrowEnum
Bases: str, Enum
Enumeration for arrow direction types in a graph.
Source code in code/NLI_extract_edges.py
18 19 20 21 22 23 24 25 | |
ArrowType
Bases: BaseModel
Model representing the type of arrow direction for an edge.
Source code in code/NLI_extract_edges.py
28 29 30 31 32 33 | |
EdgeExtractor
Bases: BaseExtractior
Class to handle edge extraction from a description using OpenAI's GPT models.
Source code in code/NLI_extract_edges.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
__init__(openai_client)
Initializes the NodeExtraction with an OpenAI client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
openai_client
|
OpenAI | AsyncOpenAI
|
An instance of OpenAI or AsyncOpenAI client to interact with the API. |
required |
Source code in code/NLI_extract_edges.py
41 42 43 44 45 46 47 48 | |
extract_all_edges(description, set_of_nodes, gpt_model='gpt-4o-mini', temperature=0, verbose=False)
Extracts all possible edges from a set of nodes based on a given description.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
description
|
str
|
The description text to be processed. |
required |
set_of_nodes
|
list[str]
|
The nodes of the graph. |
required |
gpt_model
|
str
|
The GPT model to use for extraction. Defaults to 'gpt-4o-mini'. |
'gpt-4o-mini'
|
temperature
|
float
|
The randomness of the model's output. Defaults to 0. |
0
|
verbose
|
bool
|
If True, provides detailed logging. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
list[tuple[str | None, str | None]]
|
list[tuple[str | None, str | None]]: A list of tuples representing edges with identified directions. |
Source code in code/NLI_extract_edges.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
Node distribution extractor
This module contains the NodeDistributer class, which is designed to suggest distribution types for nodes based on textual descriptions using OpenAI's GPT models. It leverages natural language processing to infer whether a node's distribution should be binary, categorical, or continuous.
NodeDistributer
Bases: BaseExtractior
A class for distributing nodes based on text descriptions using OpenAI's GPT models.
Source code in code/NLI_suggest_node_distribution.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
__init__(openai_client)
Initializes the NodeDistributer with an OpenAI client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
openai_client
|
OpenAI | AsyncOpenAI
|
An instance of OpenAI or AsyncOpenAI client to interact with the API. |
required |
Source code in code/NLI_suggest_node_distribution.py
17 18 19 20 21 22 23 24 25 | |
suggest_vertex_distributions(description, node_names, gpt_model='gpt-4o-mini', temperature=0)
Suggests distribution types for multiple nodes based on their descriptions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
description
|
str
|
The text description from which to infer node distributions. |
required |
node_names
|
list[str]
|
A list of node names for which to suggest distributions. |
required |
gpt_model
|
str
|
The GPT model to use for suggestions. Defaults to 'gpt-4o-mini'. |
'gpt-4o-mini'
|
temperature
|
float
|
The randomness of the model's output. Defaults to 0. |
0
|
Returns:
| Type | Description |
|---|---|
str
|
dict[str, str]: A dictionary mapping each node name to its suggested distribution type. |
Source code in code/NLI_suggest_node_distribution.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
Functions
Graph utils
Asynchronous Operations
The library supports asynchronous operations to improve efficiency when processing multiple requests. Ensure your environment supports asynchronous programming if you choose to use these features.