Entity Extraction
The extract()
function can be used to extract any kind of textual information from a given source. As the LLM is the one performing the task,
extraction is semantically aware.
Using the extract()
function
API Reference
An LLM abstraction for extracting structured information from text.
Example
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target
|
Type[BaseModel]
|
The Pydantic model to extract information into. |
required |
text
|
Union[str, List[str]]
|
The text to extract information from. |
required |
client
|
Literal['litellm', 'openai']
|
The client to use for extraction. Defaults to "openai". |
'openai'
|
model
|
str
|
The model to use for extraction. Defaults to "gpt-4o-mini". |
'gpt-4o-mini'
|
api_key
|
Optional[str]
|
The API key to use for OpenAI. Defaults to None. |
None
|
base_url
|
Optional[str]
|
The base URL for the OpenAI API. Defaults to None. |
None
|
organization
|
Optional[str]
|
The organization to use for OpenAI. Defaults to None. |
None
|
max_tokens
|
Optional[int]
|
The maximum number of tokens to use for extraction. Defaults to None. |
None
|
max_retries
|
int
|
The maximum number of retries to attempt. Defaults to 3. |
3
|
temperature
|
float
|
The temperature to use for extraction. Defaults to 0. |
0
|
mode
|
InstructorMode
|
The mode to use for extraction. Defaults to "markdown_json_mode". |
'markdown_json_mode'
|
process
|
Literal['single', 'batch']
|
The process to use for extraction. Defaults to "single". |
'single'
|
batch_size
|
int
|
The number of texts to extract information from at a time. Defaults to 3. |
3
|
verbose
|
bool
|
Whether to print verbose output. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
Union[BaseModel, List[BaseModel]]
|
Union[BaseModel, List[BaseModel]]: The extracted information. |
Source code in zyx/resources/completions/base/extract.py
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 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 |
|