Skip to content

Commit

Permalink
Update pre-commit to auto-fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
dhirenmathur committed Feb 20, 2025
1 parent 7a6ea87 commit 95c7aec
Show file tree
Hide file tree
Showing 20 changed files with 127 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ RESEND_API_KEY=
ANTHROPIC_API_KEY=
POSTHOG_API_KEY=
POSTHOG_HOST=
FIRECRAWL_API_KEY=
FIRECRAWL_API_KEY=
32 changes: 29 additions & 3 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,36 @@ on:
pull_request:
types: [opened, synchronize]

permissions:
contents: write # Grants write access to push changes

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/action@v3.0.0
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full commit history
token: ${{ secrets.GITHUB_TOKEN }} # Allows pushing changes

- uses: actions/setup-python@v4
with:
python-version: "3.11" # Set a consistent Python version

- name: Install dependencies
run: pip install --upgrade pip pre-commit # Ensure latest pre-commit version

- name: Run pre-commit
run: pre-commit run --all-files --show-diff-on-failure || true # Run all hooks without failing

- name: Check for changes and commit
run: |
if [[ `git status --porcelain` ]]; then
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "chore: Auto-fix pre-commit issues"
git push origin HEAD:${{ github.head_ref }}
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Ensures authentication
19 changes: 2 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@ repos:
hooks:
- id: check-yaml
- id: trailing-whitespace
- id: check-docstring-first
- id: end-of-file-fixer
- id: check-merge-conflict
- id: check-added-large-files
args: ["--maxkb=51200"]
- id: debug-statements

- repo: https://github.com/timothycrosley/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]

- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
Expand All @@ -25,18 +19,9 @@ repos:
rev: v0.6.2
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format

- repo: https://github.com/PyCQA/pylint
rev: v3.2.6
hooks:
- id: pylint
entry: bash -c 'pylint "$@" || true' --
verbose: true
args: ["--fix"]

- repo: https://github.com/PyCQA/bandit
rev: 1.7.9
hooks:
- id: bandit
entry: bash -c 'bandit "$@" || true' --
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.ht
[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
https://www.contributor-covenant.org/faq
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,4 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ Potpie is designed to be flexible and customizable. Here are key areas to person

### **Effortless Agent Creation**:
Design custom agents tailored to your specific tasks using a single prompt. Utilize the following API to create your custom agents:

```bash
curl -X POST "http://localhost:8001/api/v1/custom-agents/agents/auto" \
-H "Content-Type: application/json" \
Expand All @@ -280,7 +280,7 @@ Design custom agents tailored to your specific tasks using a single prompt. Util

### Tool Integration
Edit or add tools in the `app/modules/intelligence/tools` directory for your custom agents.
Initialise the tools in the `app/modules/intelligence/tools/tool_service.py` file and include them in your agent.
Initialise the tools in the `app/modules/intelligence/tools/tool_service.py` file and include them in your agent.

## 🤝 Contributing

Expand Down
2 changes: 1 addition & 1 deletion app/alembic/README
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Generic single-database configuration.
Generic single-database configuration.
49 changes: 27 additions & 22 deletions app/alembic/versions/20241020111943_262d870e9686_custom_agents.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,54 @@
"""custom_agents
Revision ID: 20241020111943_262d870e9686
Revises:
Revises:
Create Date: 2024-10-20 11:19:43.653649
"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = '20241020111943_262d870e9686'
revision: str = "20241020111943_262d870e9686"
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None

# Add this line
branch_labels = ('custom_agents_microservice',)
branch_labels = ("custom_agents_microservice",)


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('custom_agents',
sa.Column('id', sa.String(), nullable=False),
sa.Column('user_id', sa.String(), nullable=True),
sa.Column('role', sa.String(), nullable=True),
sa.Column('goal', sa.String(), nullable=True),
sa.Column('backstory', sa.String(), nullable=True),
sa.Column('system_prompt', sa.String(), nullable=True),
sa.Column('tasks', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.Column('deployment_url', sa.String(), nullable=True),
sa.Column('deployment_status', sa.String(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint('id')
op.create_table(
"custom_agents",
sa.Column("id", sa.String(), nullable=False),
sa.Column("user_id", sa.String(), nullable=True),
sa.Column("role", sa.String(), nullable=True),
sa.Column("goal", sa.String(), nullable=True),
sa.Column("backstory", sa.String(), nullable=True),
sa.Column("system_prompt", sa.String(), nullable=True),
sa.Column("tasks", postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.Column("deployment_url", sa.String(), nullable=True),
sa.Column("deployment_status", sa.String(), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(op.f("ix_custom_agents_id"), "custom_agents", ["id"], unique=False)
op.create_index(
op.f("ix_custom_agents_user_id"), "custom_agents", ["user_id"], unique=False
)
op.create_index(op.f('ix_custom_agents_id'), 'custom_agents', ['id'], unique=False)
op.create_index(op.f('ix_custom_agents_user_id'), 'custom_agents', ['user_id'], unique=False)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_custom_agents_user_id'), table_name='custom_agents')
op.drop_index(op.f('ix_custom_agents_id'), table_name='custom_agents')
op.drop_table('custom_agents')
op.drop_index(op.f("ix_custom_agents_user_id"), table_name="custom_agents")
op.drop_index(op.f("ix_custom_agents_id"), table_name="custom_agents")
op.drop_table("custom_agents")
# ### end Alembic commands ###
4 changes: 3 additions & 1 deletion app/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Conversation,
)
from app.modules.conversations.message.message_model import Message # noqa
from app.modules.intelligence.agents.custom_agents.custom_agent_model import ( # noqa
CustomAgent,
)
from app.modules.intelligence.prompts.prompt_model import ( # noqa
AgentPromptMapping,
Prompt,
Expand All @@ -11,4 +14,3 @@
from app.modules.tasks.task_model import Task # noqa
from app.modules.users.user_model import User # noqa
from app.modules.users.user_preferences_model import UserPreferences # noqa
from app.modules.intelligence.agents.custom_agents.custom_agent_model import CustomAgent # noqa
84 changes: 44 additions & 40 deletions app/modules/code_provider/local_repo/local_repo_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,22 @@ async def _fetch_repo_structure_async(

# Filter out files with excluded extensions
contents = [
item
for item in contents
if item['type'] == "dir"
or not any(item['name'].endswith(ext) for ext in exclude_extensions)
]
item
for item in contents
if item["type"] == "dir"
or not any(item["name"].endswith(ext) for ext in exclude_extensions)
]

tasks = []
for item in contents:
# Only process items within the base_path if it's specified
if base_path and not item['path'].startswith(base_path):
if base_path and not item["path"].startswith(base_path):
continue

if item['type'] == "dir":
if item["type"] == "dir":
task = self._fetch_repo_structure_async(
repo,
item['path'],
item["path"],
current_depth=current_depth,
base_path=base_path,
)
Expand All @@ -184,8 +184,8 @@ async def _fetch_repo_structure_async(
structure["children"].append(
{
"type": "file",
"name": item['name'],
"path": item['path'],
"name": item["name"],
"path": item["path"],
}
)

Expand Down Expand Up @@ -275,7 +275,7 @@ def _get_contents(self, path: str) -> Union[List[dict], dict]:
"""
If the path is a directory, it returns a list of dictionaries,
each representing a file or subdirectory. If the path is a file, its content is read and returned.
:param path: Relative or absolute path within the local repository.
:return: A dict if the path is a file (with file content loaded), or a list of dicts if the path is a directory.
"""
Expand All @@ -284,51 +284,55 @@ def _get_contents(self, path: str) -> Union[List[dict], dict]:

if path == "/":
path = ""

abs_path = os.path.abspath(path)

if not os.path.exists(abs_path):
raise FileNotFoundError(f"Path '{abs_path}' does not exist.")

if os.path.isdir(abs_path):
contents = []
for item in os.listdir(abs_path):
item_path = os.path.join(abs_path, item)
if os.path.isdir(item_path):
contents.append({
"path": item_path,
"name": item,
"type": "dir",
"content": None, #path is a dir, content is not loaded
"completed": True
})
contents.append(
{
"path": item_path,
"name": item,
"type": "dir",
"content": None, # path is a dir, content is not loaded
"completed": True,
}
)
elif os.path.isfile(item_path):
contents.append({
"path": item_path,
"name": item,
"type": "file",
"content": None,
"completed": False
})
contents.append(
{
"path": item_path,
"name": item,
"type": "file",
"content": None,
"completed": False,
}
)
else:
contents.append({
"path": item_path,
"name": item,
"type": "other",
"content": None,
"completed": True
})
contents.append(
{
"path": item_path,
"name": item,
"type": "other",
"content": None,
"completed": True,
}
)
return contents

elif os.path.isfile(abs_path):
with open(abs_path, "r", encoding="utf-8") as file:
file_content = file.read()
return {
"path": abs_path,
"name": os.path.basename(abs_path),
"type": "file",
"content": file_content, #path is a file, content is loaded
"completed": True
"content": file_content, # path is a file, content is loaded
"completed": True,
}


Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ async def agent_node(self, state: State, writer: StreamWriter):

try:
system_agents = [
agent.id for agent in self.available_agents if agent.status == "SYSTEM"
]
agent.id for agent in self.available_agents if agent.status == "SYSTEM"
]
if state["agent_id"] in system_agents:
async for chunk in self.agent.run(
query=state["query"],
Expand All @@ -234,7 +234,7 @@ async def agent_node(self, state: State, writer: StreamWriter):
node_ids=state["node_ids"],
):
if isinstance(chunk, str):
writer(chunk)
writer(chunk)
else:
async for chunk in await self.agent.run(
query=state["query"],
Expand Down
5 changes: 4 additions & 1 deletion app/modules/intelligence/agents/agents_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

logger = setup_logger(__name__)


class AgentsService:
def __init__(self, db):
self.project_path = os.getenv("PROJECT_PATH", "projects/")
Expand Down Expand Up @@ -69,7 +70,9 @@ async def list_available_agents(
current_user["user_id"]
)
except Exception as e:
logger.error(f"Failed to fetch custom agents for user {current_user['user_id']}: {e}")
logger.error(
f"Failed to fetch custom agents for user {current_user['user_id']}: {e}"
)
custom_agents = []
agent_info_list = [
AgentInfo(
Expand Down
Loading

0 comments on commit 95c7aec

Please # to comment.