event-extraction-agent 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- event_extraction_agent-1.0.0/LICENSE +21 -0
- event_extraction_agent-1.0.0/PKG-INFO +244 -0
- event_extraction_agent-1.0.0/README.md +195 -0
- event_extraction_agent-1.0.0/pyproject.toml +50 -0
- event_extraction_agent-1.0.0/setup.cfg +4 -0
- event_extraction_agent-1.0.0/src/event_extraction_agent/__init__.py +55 -0
- event_extraction_agent-1.0.0/src/event_extraction_agent/agent.py +813 -0
- event_extraction_agent-1.0.0/src/event_extraction_agent/models.py +357 -0
- event_extraction_agent-1.0.0/src/event_extraction_agent/pipeline.py +102 -0
- event_extraction_agent-1.0.0/src/event_extraction_agent/prompts.py +254 -0
- event_extraction_agent-1.0.0/src/event_extraction_agent/py.typed +1 -0
- event_extraction_agent-1.0.0/src/event_extraction_agent/sources.py +13 -0
- event_extraction_agent-1.0.0/src/event_extraction_agent/validator.py +95 -0
- event_extraction_agent-1.0.0/src/event_extraction_agent/vk.py +552 -0
- event_extraction_agent-1.0.0/src/event_extraction_agent.egg-info/PKG-INFO +244 -0
- event_extraction_agent-1.0.0/src/event_extraction_agent.egg-info/SOURCES.txt +23 -0
- event_extraction_agent-1.0.0/src/event_extraction_agent.egg-info/dependency_links.txt +1 -0
- event_extraction_agent-1.0.0/src/event_extraction_agent.egg-info/requires.txt +4 -0
- event_extraction_agent-1.0.0/src/event_extraction_agent.egg-info/top_level.txt +1 -0
- event_extraction_agent-1.0.0/tests/test_agent.py +508 -0
- event_extraction_agent-1.0.0/tests/test_clients.py +86 -0
- event_extraction_agent-1.0.0/tests/test_models.py +111 -0
- event_extraction_agent-1.0.0/tests/test_no_env_config.py +9 -0
- event_extraction_agent-1.0.0/tests/test_pipeline.py +179 -0
- event_extraction_agent-1.0.0/tests/test_vk_source.py +289 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Slava Tyutyunov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: event-extraction-agent
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Python library for extracting structured event data from text posts with LLM agents.
|
|
5
|
+
Author: event-extraction-agent contributors
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Slava Tyutyunov
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/olivoreo/event-extraction-agent
|
|
29
|
+
Project-URL: Repository, https://github.com/olivoreo/event-extraction-agent
|
|
30
|
+
Project-URL: Issues, https://github.com/olivoreo/event-extraction-agent/issues
|
|
31
|
+
Project-URL: Source, https://github.com/olivoreo/event-ai-agent
|
|
32
|
+
Keywords: event extraction,llm,structured data,vk,pipeline
|
|
33
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
34
|
+
Classifier: Intended Audience :: Developers
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Programming Language :: Python :: 3
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
40
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
41
|
+
Classifier: Typing :: Typed
|
|
42
|
+
Requires-Python: >=3.11
|
|
43
|
+
Description-Content-Type: text/markdown
|
|
44
|
+
License-File: LICENSE
|
|
45
|
+
Requires-Dist: pydantic<3,>=2
|
|
46
|
+
Provides-Extra: dev
|
|
47
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
48
|
+
Dynamic: license-file
|
|
49
|
+
|
|
50
|
+
# event_extraction_agent
|
|
51
|
+
|
|
52
|
+
`event_extraction_agent` - Python-библиотека для извлечения структурированных данных о мероприятиях из текстовых постов с помощью LLM.
|
|
53
|
+
|
|
54
|
+
Главный и стабильный способ использования - `ExtractionPipeline`: вы передаете источник постов и `ExtractionAgentConfig`, а на выходе получаете `BatchExtractionResult` со всеми событиями, статусами, ошибками и методами сохранения результата.
|
|
55
|
+
|
|
56
|
+
## Установка
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install event-extraction-agent
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Для локальной разработки из репозитория:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
python -m pip install -e ".[dev]"
|
|
66
|
+
python -m pytest
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Быстрый старт
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from event_extraction_agent import (
|
|
73
|
+
ExtractionAgentConfig,
|
|
74
|
+
ExtractionPipeline,
|
|
75
|
+
OllamaChatClient,
|
|
76
|
+
SourcePost,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class MySource:
|
|
81
|
+
def fetch_posts(self) -> list[SourcePost]:
|
|
82
|
+
return [
|
|
83
|
+
SourcePost(
|
|
84
|
+
text="12 июня в 18:00 пройдет открытая лекция.",
|
|
85
|
+
source_name="Example source",
|
|
86
|
+
source_url="https://example.com/posts/123",
|
|
87
|
+
published_at="2026-06-01T10:00:00+03:00",
|
|
88
|
+
external_id="post-123",
|
|
89
|
+
)
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
pipeline = ExtractionPipeline(
|
|
94
|
+
source=MySource(),
|
|
95
|
+
agent_config=ExtractionAgentConfig(
|
|
96
|
+
main_client=OllamaChatClient(model="qwen2.5:3b"),
|
|
97
|
+
),
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
result = pipeline.run()
|
|
101
|
+
|
|
102
|
+
for outcome in result.outcomes:
|
|
103
|
+
if outcome.event:
|
|
104
|
+
print(outcome.event.model_dump(mode="json"))
|
|
105
|
+
else:
|
|
106
|
+
print(outcome.status, outcome.errors)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Минимально в `ExtractionAgentConfig` нужно передать `main_client`. Если `refinement_client` не задан, уточнение типа события выполняется тем же клиентом.
|
|
110
|
+
|
|
111
|
+
## Сохранение результата
|
|
112
|
+
|
|
113
|
+
`pipeline.run()` возвращает `BatchExtractionResult`. Его можно сохранить в JSON:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
result = pipeline.run()
|
|
117
|
+
result.save_json("events_result.json")
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
И загрузить обратно:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from event_extraction_agent import BatchExtractionResult
|
|
124
|
+
|
|
125
|
+
previous = BatchExtractionResult.load_json("events_result.json")
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Incremental processing
|
|
129
|
+
|
|
130
|
+
Pipeline может сам загрузить предыдущий результат и сохранить новый:
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
pipeline = ExtractionPipeline(
|
|
134
|
+
source=source,
|
|
135
|
+
agent_config=agent_config,
|
|
136
|
+
previous_result_path="events_result.json",
|
|
137
|
+
save_result_path="events_result.json",
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
result = pipeline.run()
|
|
141
|
+
print(result.cached, result.processed)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Incremental-режим пропускает LLM extraction, если у нового поста совпали `external_id` и нормализованный текст для LLM (`raw_text`, если он задан, иначе `text`) с предыдущим результатом. Результаты со статусом `llm_error` по умолчанию обрабатываются повторно.
|
|
145
|
+
|
|
146
|
+
## VK source
|
|
147
|
+
|
|
148
|
+
Для VK есть готовый source adapter:
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from event_extraction_agent import ExtractionAgentConfig, ExtractionPipeline, OllamaChatClient, VKSource
|
|
152
|
+
|
|
153
|
+
source = VKSource(
|
|
154
|
+
access_token="vk-service-token",
|
|
155
|
+
sources=[
|
|
156
|
+
"https://vk.com/club123",
|
|
157
|
+
"public456",
|
|
158
|
+
"my_community_domain",
|
|
159
|
+
-789,
|
|
160
|
+
],
|
|
161
|
+
posts_per_source_limit=20,
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
result = ExtractionPipeline(
|
|
165
|
+
source=source,
|
|
166
|
+
agent_config=ExtractionAgentConfig(
|
|
167
|
+
main_client=OllamaChatClient(model="qwen2.5:3b"),
|
|
168
|
+
),
|
|
169
|
+
previous_result_path="events_result.json",
|
|
170
|
+
save_result_path="events_result.json",
|
|
171
|
+
).run()
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
`VKSource` получает посты через `wall.get`, очищает текст для LLM, добавляет `source_name`, `source_url`, `published_at`, `external_id` и возвращает список `SourcePost`.
|
|
175
|
+
|
|
176
|
+
Если один VK source недоступен, остальные источники по умолчанию продолжают обрабатываться. Ошибки доступны через `source.errors` или `fetch_posts_with_errors()`:
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
fetch_result = source.fetch_posts_with_errors()
|
|
180
|
+
|
|
181
|
+
for error in fetch_result.errors:
|
|
182
|
+
print(error.source, error.code, error)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
По умолчанию `VKSource` использует rate limit `20` запросов в секунду и retry/backoff для временных ошибок VK, HTTP `429`/`5xx` и сетевых сбоев.
|
|
186
|
+
|
|
187
|
+
## Настройка агента
|
|
188
|
+
|
|
189
|
+
Все настройки LLM и extraction-поведения передаются через `ExtractionAgentConfig`:
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
config = ExtractionAgentConfig(
|
|
193
|
+
main_client=main_client,
|
|
194
|
+
refinement_client=refinement_client,
|
|
195
|
+
use_event_type_refinement=True,
|
|
196
|
+
current_datetime="2026-06-10T12:00:00+03:00",
|
|
197
|
+
min_request_interval_seconds=2.1,
|
|
198
|
+
max_retries=1,
|
|
199
|
+
)
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Поддерживается любой LLM-клиент с методом:
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
complete(system_prompt: str, user_prompt: str) -> str
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
В пакете есть готовые клиенты:
|
|
209
|
+
|
|
210
|
+
- `OllamaChatClient`
|
|
211
|
+
- `GroqChatClient`
|
|
212
|
+
|
|
213
|
+
## Что возвращает pipeline
|
|
214
|
+
|
|
215
|
+
`BatchExtractionResult` содержит:
|
|
216
|
+
|
|
217
|
+
- `outcomes`: результаты по каждому посту;
|
|
218
|
+
- `extracted`, `skipped`, `invalid`, `llm_errors`: счетчики статусов;
|
|
219
|
+
- `cached`, `processed`: счетчики incremental-режима;
|
|
220
|
+
- `error_count`, `error_limit_reached`: информация о batch-лимитах;
|
|
221
|
+
- `save_json(path)` и `load_json(path)`.
|
|
222
|
+
|
|
223
|
+
Каждый `ExtractionOutcome` содержит исходный `SourcePost`, статус обработки, найденное `Event` или структурированные ошибки.
|
|
224
|
+
|
|
225
|
+
## Границы пакета
|
|
226
|
+
|
|
227
|
+
В пакет входит extraction-ядро, pipeline, модели, LLM-клиенты для Ollama/Groq и VK source adapter.
|
|
228
|
+
|
|
229
|
+
Пакет намеренно не включает:
|
|
230
|
+
|
|
231
|
+
- базу данных;
|
|
232
|
+
- HTTP API;
|
|
233
|
+
- расписания;
|
|
234
|
+
- чтение секретов из `.env`;
|
|
235
|
+
- обработку VK-вложений;
|
|
236
|
+
- source adapters кроме VK.
|
|
237
|
+
|
|
238
|
+
Приложение, которое использует библиотеку, отвечает за конфигурацию, секреты, хранение данных и собственные источники.
|
|
239
|
+
|
|
240
|
+
## Происхождение пакета
|
|
241
|
+
|
|
242
|
+
`event_extraction_agent` выделен из проекта [olivoreo/event-ai-agent](https://github.com/olivoreo/event-ai-agent). Из исходного проекта перенесено extraction-ядро: модели события, промпты, валидация, исправление ответа LLM и клиенты для Ollama/Groq.
|
|
243
|
+
|
|
244
|
+
При переносе намеренно не включались backend API, база данных, загрузчики внешних источников и экспериментальные ML-компоненты. Цель пакета - сделать extraction-логику переиспользуемой в других проектах.
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# event_extraction_agent
|
|
2
|
+
|
|
3
|
+
`event_extraction_agent` - Python-библиотека для извлечения структурированных данных о мероприятиях из текстовых постов с помощью LLM.
|
|
4
|
+
|
|
5
|
+
Главный и стабильный способ использования - `ExtractionPipeline`: вы передаете источник постов и `ExtractionAgentConfig`, а на выходе получаете `BatchExtractionResult` со всеми событиями, статусами, ошибками и методами сохранения результата.
|
|
6
|
+
|
|
7
|
+
## Установка
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install event-extraction-agent
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Для локальной разработки из репозитория:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
python -m pip install -e ".[dev]"
|
|
17
|
+
python -m pytest
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Быстрый старт
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from event_extraction_agent import (
|
|
24
|
+
ExtractionAgentConfig,
|
|
25
|
+
ExtractionPipeline,
|
|
26
|
+
OllamaChatClient,
|
|
27
|
+
SourcePost,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class MySource:
|
|
32
|
+
def fetch_posts(self) -> list[SourcePost]:
|
|
33
|
+
return [
|
|
34
|
+
SourcePost(
|
|
35
|
+
text="12 июня в 18:00 пройдет открытая лекция.",
|
|
36
|
+
source_name="Example source",
|
|
37
|
+
source_url="https://example.com/posts/123",
|
|
38
|
+
published_at="2026-06-01T10:00:00+03:00",
|
|
39
|
+
external_id="post-123",
|
|
40
|
+
)
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
pipeline = ExtractionPipeline(
|
|
45
|
+
source=MySource(),
|
|
46
|
+
agent_config=ExtractionAgentConfig(
|
|
47
|
+
main_client=OllamaChatClient(model="qwen2.5:3b"),
|
|
48
|
+
),
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
result = pipeline.run()
|
|
52
|
+
|
|
53
|
+
for outcome in result.outcomes:
|
|
54
|
+
if outcome.event:
|
|
55
|
+
print(outcome.event.model_dump(mode="json"))
|
|
56
|
+
else:
|
|
57
|
+
print(outcome.status, outcome.errors)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Минимально в `ExtractionAgentConfig` нужно передать `main_client`. Если `refinement_client` не задан, уточнение типа события выполняется тем же клиентом.
|
|
61
|
+
|
|
62
|
+
## Сохранение результата
|
|
63
|
+
|
|
64
|
+
`pipeline.run()` возвращает `BatchExtractionResult`. Его можно сохранить в JSON:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
result = pipeline.run()
|
|
68
|
+
result.save_json("events_result.json")
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
И загрузить обратно:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from event_extraction_agent import BatchExtractionResult
|
|
75
|
+
|
|
76
|
+
previous = BatchExtractionResult.load_json("events_result.json")
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Incremental processing
|
|
80
|
+
|
|
81
|
+
Pipeline может сам загрузить предыдущий результат и сохранить новый:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
pipeline = ExtractionPipeline(
|
|
85
|
+
source=source,
|
|
86
|
+
agent_config=agent_config,
|
|
87
|
+
previous_result_path="events_result.json",
|
|
88
|
+
save_result_path="events_result.json",
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
result = pipeline.run()
|
|
92
|
+
print(result.cached, result.processed)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Incremental-режим пропускает LLM extraction, если у нового поста совпали `external_id` и нормализованный текст для LLM (`raw_text`, если он задан, иначе `text`) с предыдущим результатом. Результаты со статусом `llm_error` по умолчанию обрабатываются повторно.
|
|
96
|
+
|
|
97
|
+
## VK source
|
|
98
|
+
|
|
99
|
+
Для VK есть готовый source adapter:
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from event_extraction_agent import ExtractionAgentConfig, ExtractionPipeline, OllamaChatClient, VKSource
|
|
103
|
+
|
|
104
|
+
source = VKSource(
|
|
105
|
+
access_token="vk-service-token",
|
|
106
|
+
sources=[
|
|
107
|
+
"https://vk.com/club123",
|
|
108
|
+
"public456",
|
|
109
|
+
"my_community_domain",
|
|
110
|
+
-789,
|
|
111
|
+
],
|
|
112
|
+
posts_per_source_limit=20,
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
result = ExtractionPipeline(
|
|
116
|
+
source=source,
|
|
117
|
+
agent_config=ExtractionAgentConfig(
|
|
118
|
+
main_client=OllamaChatClient(model="qwen2.5:3b"),
|
|
119
|
+
),
|
|
120
|
+
previous_result_path="events_result.json",
|
|
121
|
+
save_result_path="events_result.json",
|
|
122
|
+
).run()
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`VKSource` получает посты через `wall.get`, очищает текст для LLM, добавляет `source_name`, `source_url`, `published_at`, `external_id` и возвращает список `SourcePost`.
|
|
126
|
+
|
|
127
|
+
Если один VK source недоступен, остальные источники по умолчанию продолжают обрабатываться. Ошибки доступны через `source.errors` или `fetch_posts_with_errors()`:
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
fetch_result = source.fetch_posts_with_errors()
|
|
131
|
+
|
|
132
|
+
for error in fetch_result.errors:
|
|
133
|
+
print(error.source, error.code, error)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
По умолчанию `VKSource` использует rate limit `20` запросов в секунду и retry/backoff для временных ошибок VK, HTTP `429`/`5xx` и сетевых сбоев.
|
|
137
|
+
|
|
138
|
+
## Настройка агента
|
|
139
|
+
|
|
140
|
+
Все настройки LLM и extraction-поведения передаются через `ExtractionAgentConfig`:
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
config = ExtractionAgentConfig(
|
|
144
|
+
main_client=main_client,
|
|
145
|
+
refinement_client=refinement_client,
|
|
146
|
+
use_event_type_refinement=True,
|
|
147
|
+
current_datetime="2026-06-10T12:00:00+03:00",
|
|
148
|
+
min_request_interval_seconds=2.1,
|
|
149
|
+
max_retries=1,
|
|
150
|
+
)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Поддерживается любой LLM-клиент с методом:
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
complete(system_prompt: str, user_prompt: str) -> str
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
В пакете есть готовые клиенты:
|
|
160
|
+
|
|
161
|
+
- `OllamaChatClient`
|
|
162
|
+
- `GroqChatClient`
|
|
163
|
+
|
|
164
|
+
## Что возвращает pipeline
|
|
165
|
+
|
|
166
|
+
`BatchExtractionResult` содержит:
|
|
167
|
+
|
|
168
|
+
- `outcomes`: результаты по каждому посту;
|
|
169
|
+
- `extracted`, `skipped`, `invalid`, `llm_errors`: счетчики статусов;
|
|
170
|
+
- `cached`, `processed`: счетчики incremental-режима;
|
|
171
|
+
- `error_count`, `error_limit_reached`: информация о batch-лимитах;
|
|
172
|
+
- `save_json(path)` и `load_json(path)`.
|
|
173
|
+
|
|
174
|
+
Каждый `ExtractionOutcome` содержит исходный `SourcePost`, статус обработки, найденное `Event` или структурированные ошибки.
|
|
175
|
+
|
|
176
|
+
## Границы пакета
|
|
177
|
+
|
|
178
|
+
В пакет входит extraction-ядро, pipeline, модели, LLM-клиенты для Ollama/Groq и VK source adapter.
|
|
179
|
+
|
|
180
|
+
Пакет намеренно не включает:
|
|
181
|
+
|
|
182
|
+
- базу данных;
|
|
183
|
+
- HTTP API;
|
|
184
|
+
- расписания;
|
|
185
|
+
- чтение секретов из `.env`;
|
|
186
|
+
- обработку VK-вложений;
|
|
187
|
+
- source adapters кроме VK.
|
|
188
|
+
|
|
189
|
+
Приложение, которое использует библиотеку, отвечает за конфигурацию, секреты, хранение данных и собственные источники.
|
|
190
|
+
|
|
191
|
+
## Происхождение пакета
|
|
192
|
+
|
|
193
|
+
`event_extraction_agent` выделен из проекта [olivoreo/event-ai-agent](https://github.com/olivoreo/event-ai-agent). Из исходного проекта перенесено extraction-ядро: модели события, промпты, валидация, исправление ответа LLM и клиенты для Ollama/Groq.
|
|
194
|
+
|
|
195
|
+
При переносе намеренно не включались backend API, база данных, загрузчики внешних источников и экспериментальные ML-компоненты. Цель пакета - сделать extraction-логику переиспользуемой в других проектах.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "event-extraction-agent"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Python library for extracting structured event data from text posts with LLM agents."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = { file = "LICENSE" }
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "event-extraction-agent contributors" }
|
|
14
|
+
]
|
|
15
|
+
keywords = ["event extraction", "llm", "structured data", "vk", "pipeline"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 5 - Production/Stable",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
25
|
+
"Typing :: Typed"
|
|
26
|
+
]
|
|
27
|
+
dependencies = [
|
|
28
|
+
"pydantic>=2,<3"
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
Homepage = "https://github.com/olivoreo/event-extraction-agent"
|
|
33
|
+
Repository = "https://github.com/olivoreo/event-extraction-agent"
|
|
34
|
+
Issues = "https://github.com/olivoreo/event-extraction-agent/issues"
|
|
35
|
+
Source = "https://github.com/olivoreo/event-ai-agent"
|
|
36
|
+
|
|
37
|
+
[project.optional-dependencies]
|
|
38
|
+
dev = [
|
|
39
|
+
"pytest>=8"
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.packages.find]
|
|
43
|
+
where = ["src"]
|
|
44
|
+
|
|
45
|
+
[tool.setuptools.package-data]
|
|
46
|
+
event_extraction_agent = ["py.typed"]
|
|
47
|
+
|
|
48
|
+
[tool.pytest.ini_options]
|
|
49
|
+
pythonpath = ["src"]
|
|
50
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Public API for the event extraction package."""
|
|
2
|
+
|
|
3
|
+
from event_extraction_agent.agent import (
|
|
4
|
+
ExtractionAgent,
|
|
5
|
+
GroqChatClient,
|
|
6
|
+
LLMClient,
|
|
7
|
+
OllamaChatClient,
|
|
8
|
+
)
|
|
9
|
+
from event_extraction_agent.models import (
|
|
10
|
+
AttendanceType,
|
|
11
|
+
BatchExtractionResult,
|
|
12
|
+
BatchExtractionSettings,
|
|
13
|
+
BatchMode,
|
|
14
|
+
Event,
|
|
15
|
+
EventStatus,
|
|
16
|
+
EventType,
|
|
17
|
+
ExtractionAgentConfig,
|
|
18
|
+
ExtractionError,
|
|
19
|
+
ExtractionOutcome,
|
|
20
|
+
ExtractionStatus,
|
|
21
|
+
SourcePost,
|
|
22
|
+
)
|
|
23
|
+
from event_extraction_agent.pipeline import ExtractionPipeline
|
|
24
|
+
from event_extraction_agent.sources import SourceAdapter
|
|
25
|
+
from event_extraction_agent.vk import (
|
|
26
|
+
VKApiError,
|
|
27
|
+
VKFetchResult,
|
|
28
|
+
VKPostSource,
|
|
29
|
+
VKSource,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
__all__ = [
|
|
33
|
+
"AttendanceType",
|
|
34
|
+
"BatchExtractionResult",
|
|
35
|
+
"BatchExtractionSettings",
|
|
36
|
+
"BatchMode",
|
|
37
|
+
"Event",
|
|
38
|
+
"EventStatus",
|
|
39
|
+
"EventType",
|
|
40
|
+
"ExtractionAgentConfig",
|
|
41
|
+
"ExtractionAgent",
|
|
42
|
+
"ExtractionError",
|
|
43
|
+
"ExtractionOutcome",
|
|
44
|
+
"ExtractionStatus",
|
|
45
|
+
"ExtractionPipeline",
|
|
46
|
+
"GroqChatClient",
|
|
47
|
+
"LLMClient",
|
|
48
|
+
"OllamaChatClient",
|
|
49
|
+
"SourceAdapter",
|
|
50
|
+
"SourcePost",
|
|
51
|
+
"VKApiError",
|
|
52
|
+
"VKFetchResult",
|
|
53
|
+
"VKPostSource",
|
|
54
|
+
"VKSource",
|
|
55
|
+
]
|