forked from microsoft/autogen
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
566 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | ||
|
||
name: ContribGraphRagTests | ||
|
||
on: | ||
pull_request: | ||
branches: ["main"] | ||
paths: | ||
- "autogen/agentchat/contrib/graph_rag/**" | ||
- "test/agentchat/contrib/graph_rag/**" | ||
- ".github/workflows/contrib-tests.yml" | ||
- "setup.py" | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref }} | ||
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} | ||
permissions: | ||
{} | ||
# actions: read | ||
# checks: read | ||
# contents: read | ||
# deployments: read | ||
jobs: | ||
GraphRagUnitTest: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [macos-latest, windows-2019] | ||
python-version: ["3.9", "3.10", "3.11"] | ||
exclude: | ||
- os: macos-latest | ||
python-version: "3.9" | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install packages and dependencies for all tests | ||
run: | | ||
python -m pip install --upgrade pip wheel | ||
pip install pytest-cov>=5 | ||
- name: Install Falkor DB SDK when python-version is 3.10 | ||
if: matrix.python-version == '3.10' | ||
run: | | ||
pip install -e .[graph_rag_falkor_db] | ||
- name: Set AUTOGEN_USE_DOCKER based on OS | ||
shell: bash | ||
run: | | ||
if [[ ${{ matrix.os }} != ubuntu-latest ]]; then | ||
echo "AUTOGEN_USE_DOCKER=False" >> $GITHUB_ENV | ||
fi | ||
- name: Coverage | ||
run: | | ||
pytest test/agentchat/contrib/graph_rag/test_falkor_graph_rag.py --skip-openai | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
file: ./coverage.xml | ||
flags: unittests | ||
|
||
GraphRagIntegrationTest-FalkorDB-Ubuntu: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ["3.9", "3.10", "3.11"] | ||
services: | ||
falkordb: | ||
image: falkordb/falkordb:edge | ||
ports: | ||
- 6379:6379 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install packages and dependencies for all tests | ||
run: | | ||
python -m pip install --upgrade pip wheel | ||
pip install pytest | ||
- name: Install Falkor DB SDK when on linux | ||
run: | | ||
pip install -e .[graph_rag_falkor_db] | ||
- name: Set AUTOGEN_USE_DOCKER based on OS | ||
shell: bash | ||
run: | | ||
echo "AUTOGEN_USE_DOCKER=False" >> $GITHUB_ENV | ||
- name: Coverage | ||
run: | | ||
pip install pytest-cov>=5 | ||
pytest test/agentchat/contrib/graph_rag/test_falkor_graph_rag.py --skip-openai | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
file: ./coverage.xml | ||
flags: unittests |
46 changes: 46 additions & 0 deletions
46
autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
from dataclasses import field | ||
from typing import List | ||
|
||
from graphrag_sdk import KnowledgeGraph, Source | ||
from graphrag_sdk.schema import Schema | ||
|
||
from .document import Document | ||
from .graph_query_engine import GraphQueryEngine, GraphStoreQueryResult | ||
|
||
|
||
class FalkorGraphQueryResult(GraphStoreQueryResult): | ||
messages: list = field(default_factory=list) | ||
|
||
|
||
class FalkorGraphQueryEngine: | ||
|
||
def __init__( | ||
self, | ||
name: str, | ||
host: str = "127.0.0.1", | ||
port: int = 6379, | ||
username: str | None = None, | ||
password: str | None = None, | ||
model: str = "gpt-4-1106-preview", | ||
schema: Schema | None = None, | ||
): | ||
|
||
self.knowledge_graph = KnowledgeGraph(name, host, port, username, password, model, schema) | ||
|
||
def init_db(self, input_doc: List[Document] | None): | ||
sources = [] | ||
for doc in input_doc: | ||
if os.path.exists(doc.path_or_url): | ||
sources.append(Source(doc.path_or_url)) | ||
|
||
if sources: | ||
self.knowledge_graph.process_sources(sources) | ||
|
||
def add_records(self, new_records: List) -> bool: | ||
raise NotImplementedError("This method is not supported by Falkor DB SDK yet.") | ||
|
||
def query(self, question: str, n_results: int = 1, **kwargs) -> FalkorGraphQueryResult: | ||
messages = kwargs.pop("messages", []) | ||
answer, messages = self.knowledge_graph.ask(question, messages) | ||
return FalkorGraphQueryResult(answer=answer, results=[], messages=messages) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.