Skip to content

Hypergraph is more powerful. Transform unstructured text into structured knowledge with LLMs. Graphs, hypergraphs, and spatio-temporal extractions — with one command.

Add integration tests for OpenAI API interactions

yifanfeng979d21f76ad92a
diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml
index 01d4d96..6f55fd8 100644
--- a/.github/workflows/docs.yml
+++ b/.github/workflows/docs.yml
@@ -9,6 +9,7 @@ on:
- "mkdocs.yml"
- "pyproject.toml"
- ".github/workflows/docs.yml"
+ - "docs_hooks.py"
workflow_dispatch:
inputs:
version:
@@ -21,7 +22,7 @@ on:
default: ""
permissions:
- contents: write
+ contents: read
pages: write
id-token: write
@@ -30,12 +31,8 @@ concurrency:
cancel-in-progress: false
jobs:
- deploy-docs:
+ build:
runs-on: ubuntu-latest
- environment:
- name: github-pages
- url: ${{ steps.deployment.outputs.page_url }}
-
steps:
- name: Checkout repository
uses: actions/checkout@v4
@@ -61,23 +58,39 @@ jobs:
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- - name: Deploy with mike
+ - name: Fetch existing gh-pages branch
+ run: git fetch origin gh-pages || true
+
+ - name: Deploy with mike (local only)
run: |
VERSION="${{ github.event.inputs.version || 'latest' }}"
ALIAS="${{ github.event.inputs.alias }}"
- # Build and deploy the version
if [ -n "$ALIAS" ]; then
- echo "Deploying version $VERSION with alias $ALIAS"
- mike deploy --push --update-aliases "$VERSION" "$ALIAS"
+ mike deploy --update-aliases "$VERSION" "$ALIAS"
else
- echo "Deploying version $VERSION"
- mike deploy --push "$VERSION"
+ mike deploy "$VERSION"
fi
- # Set default version to latest
- mike set-default --push latest
+ mike set-default latest
+
+ - name: Export gh-pages site
+ run: |
+ mkdir -p _site
+ git archive gh-pages | tar -x -C _site
+
+ - name: Upload Pages artifact
+ uses: actions/upload-pages-artifact@v3
+ with:
+ path: _site
+ deploy:
+ runs-on: ubuntu-latest
+ needs: build
+ environment:
+ name: github-pages
+ url: ${{ steps.deployment.outputs.page_url }}
+ steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml
new file mode 100644
index 0000000..2abad2e
--- /dev/null
+++ b/.github/workflows/integration.yml
@@ -0,0 +1,51 @@
+name: Integration Tests
+
+on:
+ schedule:
+ # Run nightly at 2 AM UTC
+ - cron: '0 2 * * *'
+ workflow_dispatch:
+ inputs:
+ python_version:
+ description: 'Python version to test'
+ required: false
+ default: '3.11'
+ type: choice
+ options:
+ - '3.11'
+ - '3.12'
+
+permissions:
+ contents: read
+
+jobs:
+ integration-test:
+ name: Integration Tests
+ runs-on: ubuntu-latest
+ environment: integration-tests
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v4
+
+ - name: Set up Python
+ uses: actions/setup-python@v5
+ with:
+ python-version: ${{ github.event.inputs.python_version || '3.11' }}
+
+ - name: Install uv
+ uses: astral-sh/setup-uv@v5
+ with:
+ enable-cache: true
+
+ - name: Install dependencies
+ run: |
+ uv pip install --system -e ".[all]"
+ uv pip install --system pytest
+
+ - name: Run integration tests
+ run: |
+ pytest -m integration -v --tb=short
+ env:
+ PYTHONPATH: ${{ github.workspace }}
+ OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 48e2d26..34ec41c 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -32,7 +32,7 @@ jobs:
enable-cache: true
- name: Install ruff
- run: uv pip install --system ruff
+ run: uv tool install ruff
- name: Run ruff linter
run: ruff check hyperextract
@@ -60,8 +60,9 @@ jobs:
- name: Install dependencies
run: |
- uv pip install --system -e ".[all]"
- uv pip install --system mypy
+ uv venv
+ uv pip install -e ".[all]"
+ uv pip install mypy
- name: Run mypy
- run: mypy hyperextract --ignore-missing-imports
+ run: uv run mypy hyperextract --ignore-missing-imports
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index 098589a..7ade1f2 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -57,11 +57,11 @@ jobs:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
- if: github.event_name == 'release' && !inputs.test_pypi
+ if: '!inputs.test_pypi'
environment:
name: pypi
- url: https://pypi.org/p/hyperextract
+ url: https://pypi.org/project/hyperextract
permissions:
id-token: write
@@ -82,11 +82,11 @@ jobs:
name: Publish to Test PyPI
needs: build
runs-on: ubuntu-latest
- if: inputs.test_pypi
+ if: 'inputs.test_pypi'
environment:
name: test-pypi
- url: https://test.pypi.org/p/hyperextract
+ url: https://test.pypi.org/project/hyperextract
permissions:
id-token: write
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 0417cbe..77712b7 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -57,6 +57,7 @@ jobs:
pytest --cov=hyperextract --cov-report=xml --cov-report=term -v
env:
PYTHONPATH: ${{ github.workspace }}
+ OPENAI_API_KEY: "" # Force using mock for deterministic tests
- name: Upload coverage to Codecov
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
diff --git a/README.md b/README.md
index 07ef36c..79eca7a 100644
--- a/README.md
+++ b/README.md
@@ -27,7 +27,7 @@
<br/>
-<img src="docs/assets/hero.png" alt="Hero & Workflow" width="800" style="max-width: 100%;">
+<img src="docs/assets/hero.jpg" alt="Hero & Workflow" width="800" style="max-width: 100%;">
<br/>
</div>
@@ -170,13 +170,13 @@ ka.show(result)
Our framework embraces complexity without making you write boilerplate code.
-<img src="docs/assets/autotypes.png" alt="Knowledge Structures Matrix" width="700" style="max-width: 100%;">
+<img src="docs/assets/autotypes.jpg" alt="Knowledge Structures Matrix" width="700" style="max-width: 100%;">
### Example: AutoGraph Visualization
Here is the knowledge graph visualization after `AutoGraph` extraction:
-<img src="docs/assets/en_show.png" alt="AutoGraph Visualization" width="600" style="max-width: 100%; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1);">
+<img src="docs/assets/en_show.jpg" alt="AutoGraph Visualization" width="600" style="max-width: 100%; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1);">
## 🛠️ Architecture Overview
@@ -190,7 +190,7 @@ Hyper-Extract follows a **three-layer architecture**:
Use via **CLI** (`he parse`, `he search`, `he show`...) or **Python API** (`Template.create()`).
-<img src="docs/assets/arch.png" alt="Architecture" width="750" style="max-width: 100%;">
+<img src="docs/assets/arch.jpg" alt="Architecture" width="750" style="max-width: 100%;">
### 📚 Related Documentation
diff --git a/README_ZH.md b/README_ZH.md
index 80aec4c..631f357 100644
--- a/README_ZH.md
+++ b/README_ZH.md
@@ -27,7 +27,7 @@
<br/>
-<img src="docs/assets/hero.png" alt="Hero & Workflow" width="800" style="max-width: 100%;">
+<img src="docs/assets/hero.jpg" alt="Hero & Workflow" width="800" style="max-width: 100%;">
<br/>
</div>
@@ -170,13 +170,13 @@ ka.show(result)
拒绝样板代码,纯干货聚焦数据本身。
-<img src="docs/assets/autotypes.png" alt="知识结构矩阵" width="700" style="max-width: 100%;">
+<img src="docs/assets/autotypes.jpg" alt="知识结构矩阵" width="700" style="max-width: 100%;">
### 示例:AutoGraph 知识图谱可视化
以下是 `AutoGraph` 类型提取后的知识图谱可视化效果:
-<img src="docs/assets/zh_show.png" alt="AutoGraph 可视化" width="600" style="max-width: 100%; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1);">
+<img src="docs/assets/zh_show.jpg" alt="AutoGraph 可视化" width="600" style="max-width: 100%; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1);">
## 🛠️ 系统架构
@@ -190,7 +190,7 @@ Hyper-Extract 采用**三层架构**:
可通过 **CLI**(`he parse`、`he search`、`he show`...)或 **Python API**(`Template.create()`)使用。
-<img src="docs/assets/arch.png" alt="系统架构" width="750" style="max-width: 100%;">
+<img src="docs/assets/arch.jpg" alt="系统架构" width="750" style="max-width: 100%;">
### 📝 相关文档
diff --git a/docs/assets/arch.jpg b/docs/assets/arch.jpg
new file mode 100644
index 0000000..bc4b083
Binary files /dev/null and b/docs/assets/arch.jpg differ
diff --git a/docs/assets/arch.png b/docs/assets/arch.png
deleted file mode 100644
index a80cc67..0000000
Binary files a/docs/assets/arch.png and /dev/null differ
diff --git a/docs/assets/autotypes.jpg b/docs/assets/autotypes.jpg
new file mode 100644
index 0000000..25492d7
Binary files /dev/null and b/docs/assets/autotypes.jpg differ
diff --git a/docs/assets/autotypes.png b/docs/assets/autotypes.png
deleted file mode 100644
index 4fc6d7e..0000000
Binary files a/docs/assets/autotypes.png and /dev/null differ
diff --git a/docs/assets/en_show.jpg b/docs/assets/en_show.jpg
new file mode 100644
index 0000000..f6b7075
Binary files /dev/null and b/docs/assets/en_show.jpg differ
diff --git a/docs/assets/en_show.png b/docs/assets/en_show.png
deleted file mode 100644
index 485b3eb..0000000
Binary files a/docs/assets/en_show.png and /dev/null differ
diff --git a/docs/assets/hero.jpg b/docs/assets/hero.jpg
new file mode 100644
index 0000000..6dfed4b
Binary files /dev/null and b/docs/assets/hero.jpg differ
diff --git a/docs/assets/hero.png b/docs/assets/hero.png
deleted file mode 100644
index bcdb76f..0000000
Binary files a/docs/assets/hero.png and /dev/null differ
diff --git a/docs/assets/zh_show.jpg b/docs/assets/zh_show.jpg
new file mode 100644
index 0000000..b5c9eca
Binary files /dev/null and b/docs/assets/zh_show.jpg differ
diff --git a/docs/assets/zh_show.png b/docs/assets/zh_show.png
deleted file mode 100644
index 0f97d33..0000000
Binary files a/docs/assets/zh_show.png and /dev/null differ
diff --git a/docs/en/cli/workflow.md b/docs/en/cli/workflow.md
index 7d0fc53..c69d76d 100644
--- a/docs/en/cli/workflow.md
+++ b/docs/en/cli/workflow.md
@@ -71,7 +71,7 @@ Index Built
he show ./transformer_kb/
```
-![Knowledge Graph Visualization](../../assets/en_show.png)
+![Knowledge Graph Visualization](../../assets/en_show.jpg)
This opens an interactive graph in your browser showing:
diff --git a/docs/en/getting-started/cli-quickstart.md b/docs/en/getting-started/cli-quickstart.md
index 3b11a88..fb87e67 100644
--- a/docs/en/getting-started/cli-quickstart.md
+++ b/docs/en/getting-started/cli-quickstart.md
@@ -101,7 +101,7 @@ This opens an interactive visualization in your browser, showing:
- **Entities** (people, places, events) as nodes
- **Relationships** as edges connecting the nodes
-![Knowledge Graph Visualization](../../assets/en_show.png)
+![Knowledge Graph Visualization](../../assets/en_show.jpg)
---
diff --git a/docs/en/getting-started/python-quickstart.md b/docs/en/getting-started/python-quickstart.md
index 6253868..3b709b1 100644
--- a/docs/en/getting-started/python-quickstart.md
+++ b/docs/en/getting-started/python-quickstart.md
@@ -95,7 +95,7 @@ result.build_index()
result.show()
```
-![Knowledge Graph Visualization](../../assets/en_show.png)
+![Knowledge Graph Visualization](../../assets/en_show.jpg)
---
@@ -116,7 +116,7 @@ First entity: Nikola Tesla (person)
And a browser window will open showing the interactive knowledge graph.
-![Knowledge Graph Visualization](../../assets/en_show.png)
+![Knowledge Graph Visualization](../../assets/en_show.jpg)
---
@@ -179,7 +179,7 @@ result.build_index()
result.show()
```
-![Updated Knowledge Graph Visualization](../../assets/en_show.png)
+![Updated Knowledge Graph Visualization](../../assets/en_show.jpg)
---
@@ -237,7 +237,7 @@ def main():
print("\nDone!")
```
-![Interactive Knowledge Graph Visualization](../../assets/en_show.png)
+![Interactive Knowledge Graph Visualization](../../assets/en_show.jpg)
if __name__ == "__main__":
diff --git a/docs/en/python/core-concepts.md b/docs/en/python/core-concepts.md
index 65f0bdf..dbf9715 100644
--- a/docs/en/python/core-concepts.md
+++ b/docs/en/python/core-concepts.md
@@ -227,7 +227,7 @@ result.build_index()
result.show()
```
-![Interactive Visualization](../../assets/en_show.png)
+![Interactive Visualization](../../assets/en_show.jpg)
### Method Approach (Advanced)
diff --git a/docs/en/python/guides/incremental-updates.md b/docs/en/python/guides/incremental-updates.md
index def591e..128ea62 100644
--- a/docs/en/python/guides/incremental-updates.md
+++ b/docs/en/python/guides/incremental-updates.md
@@ -56,7 +56,7 @@ ka.build_index()
ka.show()
```
-![Interactive Visualization](../../../assets/en_show.png)
+![Interactive Visualization](../../../assets/en_show.jpg)
### Processing Multiple Documents
diff --git a/docs/en/python/guides/using-templates.md b/docs/en/python/guides/using-templates.md
index 0002727..4f0f3bc 100644
--- a/docs/en/python/guides/using-templates.md
+++ b/docs/en/python/guides/using-templates.md
@@ -236,7 +236,7 @@ result.build_index()
result.show() # Visualize life timeline with search/chat
```
-![Interactive Visualization](../../../assets/en_show.png)
+![Interactive Visualization](../../../assets/en_show.jpg)
### Pattern 2: Financial Report
diff --git a/docs/en/python/index.md b/docs/en/python/index.md
index 449a355..e17b85a 100644
--- a/docs/en/python/index.md
+++ b/docs/en/python/index.md
@@ -41,7 +41,7 @@ result.build_index()
result.show()
```
-![Interactive Visualization](../../assets/en_show.png)
+![Interactive Visualization](../../assets/en_show.jpg)
---
@@ -106,7 +106,7 @@ result.load("./output/") # Load from disk
result.show() # Interactive visualization
```
-![Interactive Visualization](../../assets/en_show.png)
+![Interactive Visualization](../../assets/en_show.jpg)
---
diff --git a/docs/en/python/quickstart.md b/docs/en/python/quickstart.md
index 200c680..e3fbcd7 100644
--- a/docs/en/python/quickstart.md
+++ b/docs/en/python/quickstart.md
@@ -80,7 +80,7 @@ result.build_index()
result.show()
```
-![Interactive Visualization](../../assets/en_show.png)
+![Interactive Visualization](../../assets/en_show.jpg)
### 4. Search
diff --git a/docs/en/resources/faq.md b/docs/en/resources/faq.md
index 40ea6e7..b7a60c3 100644
--- a/docs/en/resources/faq.md
+++ b/docs/en/resources/faq.md
@@ -176,7 +176,7 @@ result.build_index()
result.show()
```
-![Interactive Visualization](../../assets/en_show.png)
+![Interactive Visualization](../../assets/en_show.jpg)
### Can I export to other formats?
diff --git a/docs/en/tutorials/research-assistant/step3-chat.md b/docs/en/tutorials/research-assistant/step3-chat.md
index 3a4ad5a..1534731 100644
--- a/docs/en/tutorials/research-assistant/step3-chat.md
+++ b/docs/en/tutorials/research-assistant/step3-chat.md
@@ -246,7 +246,7 @@ class ResearchAssistantApp:
"""Open visualization."""
self.ka.show()
-![Interactive Visualization](../../../../assets/en_show.png)
+![Interactive Visualization](../../../../assets/en_show.jpg)
def run(self):
"""Run interactive session."""
diff --git a/docs/zh/cli/workflow.md b/docs/zh/cli/workflow.md
index c2e46c7..99b2f5d 100644
--- a/docs/zh/cli/workflow.md
+++ b/docs/zh/cli/workflow.md
@@ -71,7 +71,7 @@ Index Built
he show ./transformer_kb/
```
-![知识图谱可视化](../../assets/zh_show.png)
+![知识图谱可视化](../../assets/zh_show.jpg)
这将在浏览器中打开交互式图谱,显示:
diff --git a/docs/zh/getting-started/cli-quickstart.md b/docs/zh/getting-started/cli-quickstart.md
index 2e3c356..a7f3977 100644
--- a/docs/zh/getting-started/cli-quickstart.md
+++ b/docs/zh/getting-started/cli-quickstart.md
@@ -96,7 +96,7 @@ he show ./output/
- **实体**(人物、地点、事件)作为节点
- **关系** 作为连接节点的边
-![知识图谱可视化](../../assets/zh_show.png)
+![知识图谱可视化](../../assets/zh_show.jpg)
---
diff --git a/docs/zh/getting-started/python-quickstart.md b/docs/zh/getting-started/python-quickstart.md
index 00ff899..efa1d4c 100644
--- a/docs/zh/getting-started/python-quickstart.md
+++ b/docs/zh/getting-started/python-quickstart.md
@@ -109,7 +109,7 @@ python extract.py
同时会打开浏览器窗口显示交互式知识图谱。
-![知识图谱可视化](../../assets/zh_show.png)
+![知识图谱可视化](../../assets/zh_show.jpg)
---
@@ -172,7 +172,7 @@ result.build_index()
result.show()
```
-![更新后的知识图谱可视化](../../assets/zh_show.png)
+![更新后的知识图谱可视化](../../assets/zh_show.jpg)
---
@@ -234,7 +234,7 @@ if __name__ == "__main__":
main()
```
-![交互式知识图谱可视化](../../assets/zh_show.png)
+![交互式知识图谱可视化](../../assets/zh_show.jpg)
```
---
diff --git a/docs/zh/python/core-concepts.md b/docs/zh/python/core-concepts.md
index 9610369..23de3ad 100644
--- a/docs/zh/python/core-concepts.md
+++ b/docs/zh/python/core-concepts.md
@@ -227,7 +227,7 @@ result.build_index()
result.show()
```
-![交互式可视化](../../assets/zh_show.png)
+![交互式可视化](../../assets/zh_show.jpg)
### 方法方法(高级)
diff --git a/docs/zh/python/guides/incremental-updates.md b/docs/zh/python/guides/incremental-updates.md
index 7a12b54..d50840d 100644
--- a/docs/zh/python/guides/incremental-updates.md
+++ b/docs/zh/python/guides/incremental-updates.md
@@ -56,7 +56,7 @@ ka.build_index()
ka.show()
```
-![交互式可视化](../../../assets/zh_show.png)
+![交互式可视化](../../../assets/zh_show.jpg)
### 处理多个文档
diff --git a/docs/zh/python/guides/using-templates.md b/docs/zh/python/guides/using-templates.md
index 0113c68..8d3cc07 100644
--- a/docs/zh/python/guides/using-templates.md
+++ b/docs/zh/python/guides/using-templates.md
@@ -236,7 +236,7 @@ result.build_index()
result.show() # 可视化生平时间线(支持搜索/对话功能)
```
-![交互式可视化](../../../assets/zh_show.png)
+![交互式可视化](../../../assets/zh_show.jpg)
### 模式 2:财务报告
diff --git a/docs/zh/python/index.md b/docs/zh/python/index.md
index 1aeab8c..d15d1bf 100644
--- a/docs/zh/python/index.md
+++ b/docs/zh/python/index.md
@@ -41,7 +41,7 @@ result.build_index()
result.show()
```
-![交互式可视化](../../assets/zh_show.png)
+![交互式可视化](../../assets/zh_show.jpg)
---
@@ -106,7 +106,7 @@ result.load("./output/") # 从磁盘加载
result.show() # 交互式可视化
```
-![交互式可视化](../../assets/zh_show.png)
+![交互式可视化](../../assets/zh_show.jpg)
---
diff --git a/docs/zh/python/quickstart.md b/docs/zh/python/quickstart.md
index 559c72d..debaff9 100644
--- a/docs/zh/python/quickstart.md
+++ b/docs/zh/python/quickstart.md
@@ -90,7 +90,7 @@ result.build_index()
result.show()
```
-![交互式可视化](../../assets/zh_show.png)
+![交互式可视化](../../assets/zh_show.jpg)
### 4. 搜索
diff --git a/docs/zh/resources/faq.md b/docs/zh/resources/faq.md
index 9b69ae7..fcb1ef2 100644
--- a/docs/zh/resources/faq.md
+++ b/docs/zh/resources/faq.md
@@ -176,7 +176,7 @@ result.build_index()
result.show()
```
-![交互式可视化](../../assets/zh_show.png)
+![交互式可视化](../../assets/zh_show.jpg)
### 可以导出为其他格式吗?
diff --git a/docs/zh/tutorials/research-assistant/step3-chat.md b/docs/zh/tutorials/research-assistant/step3-chat.md
index fd74fc2..8b3662c 100644
--- a/docs/zh/tutorials/research-assistant/step3-chat.md
+++ b/docs/zh/tutorials/research-assistant/step3-chat.md
@@ -244,7 +244,7 @@ class ResearchAssistantApp:
"""打开可视化。"""
self.ka.show()
-![交互式可视化](../../../../assets/zh_show.png)
+![交互式可视化](../../../../assets/zh_show.jpg)
def run(self):
"""运行交互式会话。"""
diff --git a/mkdocs.yml b/mkdocs.yml
index 6117e59..ed60649 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -3,7 +3,7 @@
site_name: Hyper-Extract
site_description: LLM-powered knowledge extraction framework
site_author: Yifan Feng
-site_url: https://hyper-extract.github.io/
+site_url: https://yifanfeng97.github.io/hyper-extract/
repo_name: yifanfeng97/hyper-extract
repo_url: https://github.com/yifanfeng97/hyper-extract
diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py
new file mode 100644
index 0000000..04f0289
--- /dev/null
+++ b/tests/integration/__init__.py
@@ -0,0 +1,16 @@
+"""Integration tests using real OpenAI API.
+
+These tests are marked with @pytest.mark.integration and require OPENAI_API_KEY.
+Run with: pytest -m integration -v
+"""
+
+import pytest
+
+# Skip all integration tests if no API key is available
+pytestmark = [
+ pytest.mark.integration,
+ pytest.mark.skipif(
+ not pytest.importorskip("os").environ.get("OPENAI_API_KEY"),
+ reason="OPENAI_API_KEY not set"
+ ),
+]
diff --git a/tests/integration/test_real_extraction.py b/tests/integration/test_real_extraction.py
new file mode 100644
index 0000000..d5b4da2
--- /dev/null
+++ b/tests/integration/test_real_extraction.py
@@ -0,0 +1,181 @@
+"""Integration tests for real LLM extraction using OpenAI API."""
+
+import os
+
+import pytest
+from langchain_openai import ChatOpenAI, OpenAIEmbeddings
+from pydantic import BaseModel, Field
+
+from hyperextract.types import AutoModel, AutoList, AutoSet, AutoGraph
+
+
+# Skip all tests if no API key
+pytestmark = [
+ pytest.mark.integration,
+ pytest.mark.skipif(
+ not os.environ.get("OPENAI_API_KEY"),
+ reason="OPENAI_API_KEY not set"
+ ),
+]
+
+
+def llm_client():
+ """Provide real OpenAI LLM client."""
+ return ChatOpenAI(model="gpt-4o-mini", temperature=0)
+
+
+def embedder():
+ """Provide real OpenAI embeddings client."""
+ return OpenAIEmbeddings(model="text-embedding-3-small")
+
+
+class PersonInfo(BaseModel):
+ """Schema for person information."""
+ name: str = Field(description="The person's name")
+ age: int = Field(description="The person's age")
+ occupation: str = Field(description="The person's job or occupation")
+
+
+class TestAutoModelIntegration:
+ """Integration tests for AutoModel with real API."""
+
+ def test_extract_person_info(self, llm_client, embedder):
+ """Test extracting structured person information."""
+ text = "Alice is a 28-year-old software engineer living in San Francisco."
+
+ automodel = AutoModel(
+ schema=PersonInfo,
+ llm_client=llm_client,
+ embedder=embedder,
+ )
+
+ result = automodel.parse_text(text)
+
+ assert result is not None
+ assert result.name == "Alice"
+ assert result.age == 28
+ assert result.occupation == "software engineer"
+
+ def test_real_extraction_not_mock(self, llm_client, embedder):
+ """Verify that real extraction returns actual values, not mocks."""
+ text = "Dr. Sarah Johnson is a 45-year-old cardiologist working at Mayo Clinic."
+
+ automodel = AutoModel(
+ schema=PersonInfo,
+ llm_client=llm_client,
+ embedder=embedder,
+ )
+
+ result = automodel.parse_text(text)
+
+ # Verify real extraction (not mock values)
+ assert "Sarah" in result.name
+ assert result.age == 45
+ assert "cardiologist" in result.occupation.lower()
+
+
+class TestAutoListIntegration:
+ """Integration tests for AutoList with real API."""
+
+ def test_extract_multiple_items(self, llm_client, embedder):
+ """Test extracting a list of items."""
+ text = """
+ The conference featured several keynote speakers:
+ - Dr. Jane Smith, Chief Scientist at AI Labs
+ - Prof. Michael Chen, Director of Research at Tech Institute
+ - Sarah Williams, CEO of StartupCo
+ """
+
+ autolist = AutoList(
+ item_schema=PersonInfo,
+ llm_client=llm_client,
+ embedder=embedder,
+ )
+
+ result = autolist.parse_text(text)
+
+ assert len(result) >= 2
+ for item in result:
+ assert item.name
+ assert item.age > 0
+ assert item.occupation
+
+
+class TestAutoSetIntegration:
+ """Integration tests for AutoSet with real API."""
+
+ def test_deduplication_with_real_embeddings(self, llm_client, embedder):
+ """Test that deduplication works with real semantic embeddings."""
+ from pydantic import BaseModel
+
+ class KeywordItem(BaseModel):
+ term: str
+ category: str = None
+
+ autoset = AutoSet(
+ item_schema=KeywordItem,
+ llm_client=llm_client,
+ embedder=embedder,
+ key_extractor=lambda x: x.term.lower(),
+ )
+
+ # Add same term with different cases
+ autoset.add(KeywordItem(term="Python", category="Language"))
+ autoset.add(KeywordItem(term="python", category="Programming"))
+ autoset.add(KeywordItem(term="JavaScript", category="Language"))
+
+ # Should dedupe "Python" and "python"
+ assert len(autoset) == 2
+ assert "python" in autoset or "Python" in autoset
+ assert "JavaScript" in autoset or "javascript" in autoset
+
+
+class TestAutoGraphIntegration:
+ """Integration tests for AutoGraph with real API."""
+
+ def test_extract_knowledge_graph(self, llm_client, embedder):
+ """Test extracting entities and relationships."""
+ text = """
+ Apple Inc. was founded by Steve Jobs, Steve Wozniak, and Ronald Wayne.
+ Steve Jobs served as CEO of Apple and introduced the iPhone.
+ """
+
+ autograph = AutoGraph(
+ llm_client=llm_client,
+ embedder=embedder,
+ )
+
+ result = autograph.parse_text(text)
+
+ # Should extract some entities
+ assert len(result.nodes) > 0
+
+ # Should have some relationships
+ if len(result.edges) > 0:
+ edge = result.edges[0]
+ assert edge.source
+ assert edge.target
+ assert edge.type
+
+ def test_search_with_real_embeddings(self, llm_client, embedder):
+ """Test semantic search with real embeddings."""
+ text = """
+ Tesla was founded by Elon Musk. The company produces electric vehicles
+ and is headquartered in Austin, Texas. SpaceX, also founded by Musk,
+ focuses on space exploration and rocket technology.
+ """
+
+ autograph = AutoGraph(
+ llm_client=llm_client,
+ embedder=embedder,
+ )
+
+ result = autograph.parse_text(text)
+ result.build_index()
+
+ # Search should work with real embeddings
+ nodes = result.search("electric cars", top_k=3)
+ # Just verify search doesn't crash
+ assert isinstance(nodes, (list, tuple))