forked from Sinaptik-AI/pandas-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusing_pipeline.py
82 lines (64 loc) · 1.79 KB
/
using_pipeline.py
1
2
3
4
5
6
7
8
9
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
import pandas as pd
from pandasai.llm.openai import OpenAI
from pandasai.pipelines.logic_units.output_logic_unit import ProcessOutput
from pandasai.pipelines.logic_units.prompt_execution import PromptExecution
from pandasai.pipelines.pipeline import Pipeline
from pandasai.pipelines.pipeline_context import PipelineContext
from pandasai.pipelines.synthetic_dataframe.generate_sdf_pipeline import (
GenerateSDFPipeline,
)
from pandasai.pipelines.synthetic_dataframe.sdf_code_executor import (
SDFCodeExecutor,
)
from pandasai.pipelines.synthetic_dataframe.synthetic_df_prompt import (
SyntheticDataframePrompt,
)
employees_df = pd.DataFrame(
{
"EmployeeID": [1, 2, 3, 4, 5],
"Name": ["John", "Emma", "Liam", "Olivia", "William"],
"Department": ["HR", "Sales", "IT", "Marketing", "Finance"],
}
)
salaries_df = pd.DataFrame(
{
"EmployeeID": [1, 2, 3, 4, 5],
"Salary": [5000, 6000, 4500, 7000, 5500],
}
)
llm = OpenAI("Your-API-Key")
config = {"llm": llm, "verbose": True}
context = PipelineContext([salaries_df], config)
# Create your own pipeline
pipeline = Pipeline(
context=context,
steps=[
SyntheticDataframePrompt(amount=15),
PromptExecution(),
SDFCodeExecutor(),
ProcessOutput(),
],
)
data_frame = pipeline.run()
print(data_frame)
# Using defined Pipelines
context = PipelineContext([employees_df], config)
pipeline = GenerateSDFPipeline(
amount=10,
context=context,
)
data_frame = pipeline.run()
print(data_frame)
# Without passing Context
pipeline = Pipeline(
[salaries_df],
config=config,
steps=[
SyntheticDataframePrompt(amount=15),
PromptExecution(),
SDFCodeExecutor(),
ProcessOutput(),
],
)
data_frame = pipeline.run()
print(data_frame)