Skip to content

Commit 9f3baf6

Browse files
committed
refactor(skills): move skills to ee
1 parent 342295e commit 9f3baf6

File tree

10 files changed

+61
-266
lines changed

10 files changed

+61
-266
lines changed

‎pandasai/__init__.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,31 @@
22
"""
33
PandasAI is a wrapper around a LLM to make dataframes conversational
44
"""
5+
from __future__ import annotations
56

67
import os
78
from io import BytesIO
89
from typing import Hashable, List, Optional, Union
910

1011
import pandas as pd
1112

12-
from pandasai.config import APIKeyManager, ConfigManager, SkillsManager
13+
from pandasai.config import APIKeyManager, ConfigManager
1314
from pandasai.data_loader.semantic_layer_schema import (
1415
Column,
1516
Relation,
1617
SemanticLayerSchema,
1718
Source,
1819
Transformation,
1920
)
21+
from pandasai.ee.skills import skill
22+
from pandasai.ee.skills.manager import SkillsManager
2023
from pandasai.exceptions import DatasetNotFound, InvalidConfigError
2124
from pandasai.helpers.path import (
2225
find_project_root,
2326
get_validated_dataset_path,
2427
transform_dash_to_underscore,
2528
)
2629
from pandasai.sandbox.sandbox import Sandbox
27-
from pandasai.skills import skill
2830

2931
from .agent import Agent
3032
from .data_loader.loader import DatasetLoader

‎pandasai/agent/base.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ def __init__(
6565
stacklevel=2,
6666
)
6767

68+
# Transition pd dataframe to pandasai dataframe
69+
if isinstance(dfs, list):
70+
for df in dfs:
71+
if isinstance(df, pd.DataFrame):
72+
df = DataFrame(df)
73+
elif isinstance(dfs, pd.DataFrame):
74+
dfs = DataFrame(dfs)
75+
6876
if isinstance(dfs, list):
6977
sources = [df.schema.source or df._loader.source for df in dfs]
7078
if not BaseQueryBuilder.check_compatible_sources(sources):

‎pandasai/agent/state.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
from dataclasses import dataclass, field
66
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
77

8-
from pandasai.config import Config, ConfigManager, SkillsManager
8+
from pandasai.config import Config, ConfigManager
99
from pandasai.constants import DEFAULT_CHART_DIRECTORY
1010
from pandasai.data_loader.semantic_layer_schema import is_schema_source_same
11+
from pandasai.ee.skills.manager import SkillsManager
1112
from pandasai.exceptions import InvalidConfigError
1213
from pandasai.helpers.folder import Folder
1314
from pandasai.helpers.logger import Logger

‎pandasai/config.py‎

Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import os
2-
from importlib.util import find_spec
3-
from typing import Any, Dict, List, Optional
2+
from typing import Any, Dict, Optional
43

54
from pydantic import BaseModel, ConfigDict
65

76
from pandasai.helpers.filemanager import DefaultFileManager, FileManager
87
from pandasai.llm.base import LLM
9-
from pandasai.skills import Skill
108

119

1210
class Config(BaseModel):
@@ -59,88 +57,3 @@ def set(cls, api_key: str):
5957
@classmethod
6058
def get(cls) -> Optional[str]:
6159
return cls._api_key
62-
63-
64-
class SkillsManager:
65-
"""
66-
A singleton class to manage the global skills list.
67-
"""
68-
69-
_skills: List[Skill] = []
70-
71-
@classmethod
72-
def add_skills(cls, *skills: Skill):
73-
"""
74-
Add skills to the global list of skills. If a skill with the same name
75-
already exists, raise an error.
76-
77-
Args:
78-
*skills: Variable number of skill objects to add.
79-
"""
80-
for skill in skills:
81-
if any(existing_skill.name == skill.name for existing_skill in cls._skills):
82-
raise ValueError(f"Skill with name '{skill.name}' already exists.")
83-
84-
cls._skills.extend(skills)
85-
86-
@classmethod
87-
def skill_exists(cls, name: str):
88-
"""
89-
Check if a skill with the given name exists in the global list of skills.
90-
91-
Args:
92-
name (str): The name of the skill to check.
93-
94-
Returns:
95-
bool: True if a skill with the given name exists, False otherwise.
96-
"""
97-
return any(skill.name == name for skill in cls._skills)
98-
99-
@classmethod
100-
def has_skills(cls):
101-
"""
102-
Check if there are any skills in the global list of skills.
103-
104-
Returns:
105-
bool: True if there are skills, False otherwise.
106-
"""
107-
return len(cls._skills) > 0
108-
109-
@classmethod
110-
def get_skill_by_func_name(cls, name: str):
111-
"""
112-
Get a skill by its name from the global list.
113-
114-
Args:
115-
name (str): The name of the skill to retrieve.
116-
117-
Returns:
118-
Skill or None: The skill with the given name, or None if not found.
119-
"""
120-
return next((skill for skill in cls._skills if skill.name == name), None)
121-
122-
@classmethod
123-
def get_skills(cls) -> List[Skill]:
124-
"""
125-
Get the global list of skills.
126-
127-
Returns:
128-
List[Skill]: The list of all skills.
129-
"""
130-
return cls._skills.copy()
131-
132-
@classmethod
133-
def clear_skills(cls):
134-
"""
135-
Clear all skills from the global list.
136-
"""
137-
cls._skills.clear()
138-
139-
@classmethod
140-
def __str__(cls) -> str:
141-
"""
142-
Present all skills
143-
Returns:
144-
str: String representation of all skills
145-
"""
146-
return "\n".join(str(skill) for skill in cls._skills)

‎pandasai/skills/__init__.py‎

Lines changed: 0 additions & 135 deletions
This file was deleted.

‎tests/unit_tests/skills/test_shared_template.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import pytest
99
from jinja2 import Environment, FileSystemLoader
1010

11-
from pandasai.config import SkillsManager
12-
from pandasai.skills import Skill, skill
11+
from pandasai.ee.skills import skill
12+
from pandasai.ee.skills.manager import SkillsManager
1313

1414

1515
class TestSharedTemplate:

0 commit comments

Comments
 (0)