|
|
|
|
|
import asyncio |
|
import os |
|
|
|
import pandas as pd |
|
|
|
from examples.custom_set_of_available_verbs.custom_verb_definitions import custom_verbs |
|
from graphrag.index import run_pipeline, run_pipeline_with_config |
|
from graphrag.index.config import PipelineWorkflowReference |
|
|
|
|
|
dataset = pd.DataFrame([{"col1": 2, "col2": 4}, {"col1": 5, "col2": 10}]) |
|
|
|
|
|
async def run_with_config(): |
|
"""Run a pipeline with a config file""" |
|
|
|
config_path = os.path.join( |
|
os.path.dirname(os.path.abspath(__file__)), "./pipeline.yml" |
|
) |
|
|
|
outputs = [] |
|
async for output in run_pipeline_with_config( |
|
config_or_path=config_path, dataset=dataset |
|
): |
|
outputs.append(output) |
|
pipeline_result = outputs[-1] |
|
|
|
if pipeline_result.result is not None: |
|
|
|
|
|
|
|
|
|
print(pipeline_result.result) |
|
else: |
|
print("No results!") |
|
|
|
|
|
async def run_python(): |
|
workflows: list[PipelineWorkflowReference] = [ |
|
PipelineWorkflowReference( |
|
name="my_workflow", |
|
steps=[ |
|
{ |
|
"verb": "str_append", |
|
"args": { |
|
"source_column": "col1", |
|
"target_column": "col_1_custom", |
|
"string_to_append": " - custom verb", |
|
}, |
|
|
|
} |
|
], |
|
), |
|
] |
|
|
|
|
|
outputs = [] |
|
async for output in run_pipeline( |
|
dataset=dataset, |
|
workflows=workflows, |
|
additional_verbs=custom_verbs, |
|
): |
|
outputs.append(output) |
|
|
|
|
|
pipeline_result = next( |
|
(output for output in outputs if output.workflow == "my_workflow"), None |
|
) |
|
|
|
if pipeline_result is not None and pipeline_result.result is not None: |
|
|
|
|
|
|
|
|
|
print(pipeline_result.result) |
|
else: |
|
print("No results!") |
|
|
|
|
|
if __name__ == "__main__": |
|
asyncio.run(run_python()) |
|
asyncio.run(run_with_config()) |
|
|