Skip to content

Commit

Permalink
Merge branch 'mono/0.6.0.dev1' into comm_pkg5
Browse files Browse the repository at this point in the history
  • Loading branch information
cobycloud authored Jan 12, 2025
2 parents b1076e1 + e9fe1eb commit 72d552e
Show file tree
Hide file tree
Showing 32 changed files with 2,066 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkgs/base/swarmauri_base/agents/AgentBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ class AgentBase(IAgent, ComponentBase):
type: Literal['AgentBase'] = 'AgentBase'

def exec(self, input_str: Optional[Union[str, IMessage]] = "", llm_kwargs: Optional[Dict] = {}) -> Any:
raise NotImplementedError('The `exec` function has not been implemeneted on this class.')
raise NotImplementedError('The `exec` function has not been implemented on this class.')
2 changes: 1 addition & 1 deletion pkgs/base/swarmauri_base/distances/DistanceBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from typing import List, Optional, Literal
from pydantic import Field

from swarmauri_core.distances.IDistanceSimilarity import IDistanceSimilarity
from swarmauri_standard.vectors.Vector import Vector
from swarmauri_core.distances.IDistanceSimilarity import IDistanceSimilarity
from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes

@ComponentBase.register_model()
Expand Down
8 changes: 8 additions & 0 deletions pkgs/base/swarmauri_base/prompts/PromptTemplateBase.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from typing import Dict, List, Union, Optional, Literal
from pydantic import Field

import warnings


from swarmauri_core.prompts.IPrompt import IPrompt
from swarmauri_core.prompts.ITemplate import ITemplate
from swarmauri_core.ComponentBase import ComponentBase, ResourceTypes
Expand Down Expand Up @@ -29,9 +32,14 @@ def set_variables(self, variables: Dict[str, str]) -> None:
self.variables = variables

def generate_prompt(self, variables: Dict[str, str] = None) -> str:
warnings.warn("Deprecating 'generate_prompt()', use `fill()`.")
return self.fill(variables)

def fill(self, variables: Dict[str, str] = None) -> str:
variables = variables or self.variables
return self.template.format(**variables)


def __call__(self, variables: Optional[Dict[str, str]] = None) -> str:
"""
Generates a prompt using the current template and provided keyword arguments for substitution.
Expand Down
4 changes: 4 additions & 0 deletions pkgs/community/swarmauri_community/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ captcha = "^0.6.0"
#gensim = { version = "^4.3.3", optional = true }
#gradio = { version = "^5.4.0", optional = true }
leptonai = { version = "^0.22.0", optional = true }

neo4j = { version = "^5.25.0", optional = true }
#nltk = { version = "^3.9.1", optional = true }

#neo4j = { version = "^5.25.0", optional = true }

pandas = "^2.2.3"
psutil = { version = "^6.1.0", optional = true }
pygithub = { version = "^2.4.0", optional = true }
Expand Down
1 change: 1 addition & 0 deletions pkgs/community/swarmauri_tool_communitygithub/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Swarmauri Example Community Package
63 changes: 63 additions & 0 deletions pkgs/community/swarmauri_tool_communitygithub/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[tool.poetry]
name = "swarmauri_tool_communitygithub"
version = "0.6.0.dev1"
description = "Github Tool"
authors = ["Jacob Stewart <[email protected]>"]
license = "Apache-2.0"
readme = "README.md"
repository = "http://github.com/swarmauri/swarmauri-sdk"
classifiers = [
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12"
]

[tool.poetry.dependencies]
python = ">=3.10,<3.13"

# Swarmauri
swarmauri_core = { path = "../../core" }
swarmauri_base = { path = "../../base" }

# Dependencies
pygithub = "^2.4.0"



[tool.poetry.group.dev.dependencies]
flake8 = "^7.0"
pytest = "^8.0"
pytest-asyncio = ">=0.24.0"
pytest-xdist = "^3.6.1"
pytest-json-report = "^1.5.0"
python-dotenv = "*"
requests = "^2.32.3"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
norecursedirs = ["combined", "scripts"]

markers = [
"test: standard test",
"unit: Unit tests",
"integration: Integration tests",
"acceptance: Acceptance tests",
"experimental: Experimental tests"
]
log_cli = true
log_cli_level = "INFO"
log_cli_format = "%(asctime)s [%(levelname)s] %(message)s"
log_cli_date_format = "%Y-%m-%d %H:%M:%S"
asyncio_default_fixture_loop_scope = "function"

[tool.poetry.plugins."swarmauri.tools"]
GithubBranchTool = "swarmauri_tool_communitygithub.GithubBranchTool"
GithubCommitTool = "swarmauri_tool_communitygithub.GithubCommitTool"
GithubIssueTool = "swarmauri_tool_communitygithub.GithubIssueTool"
GithubPRTool = "swarmauri_tool_communitygithub.GithubPRTool"
GithubTool = "swarmauri_tool_communitygithub.GithubTool"
GithubRepoTool = "swarmauri_tool_communitygithub.GithubRepoTool"
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# swarmauri/community/tools/concrete/GithubCommunityTool.py

from github import Github, GithubException
from typing import List, Dict, Literal, Any
from pydantic import Field, ConfigDict
from swarmauri_base.tools.ToolBase import ToolBase
from swarmauri_standard.tool.Parameter import Parameter


class GithubBranchTool(ToolBase):
version: str = "1.1.0"
parameters: List[Parameter] = Field(
default_factory=lambda: [
Parameter(
name="action",
type="string",
description="The action to perform on the GitHub API, e.g., 'create_repo', 'delete_repo', 'create_issue', etc.",
required=True,
),
Parameter(
name="repo_name",
type="string",
description="The full name of the repository to interact with, e.g. 'owner/repository'.",
required=True,
),
Parameter(
name="branch_name",
type="string",
description="The name of the branch to interact with.",
required=False,
),
Parameter(
name="source_branch",
type="string",
description="The name of the source branch to create a branch from.",
required=False,
),
]
)
name: str = "GithubBranchTool"
description: str = "Interacts with GitHub branches using PyGithub."
type: Literal["GithubBranchTool"] = "GithubBranchTool"
token: str
model_config = ConfigDict(arbitrary_types_allowed=True)

def __call__(self, action: str, **kwargs) -> Dict[str, Any]:
"""
Central method to call various GitHub API actions.
Args:
action (str): The action to perform.
**kwargs: Additional keyword arguments related to the action.
Returns:
Dict[str, Any]: The result of the action.
"""
action_map = {
"create_branch": self.create_branch,
"delete_branch": self.delete_branch,
"list_branches": self.list_branches,
"get_branch": self.get_branch,
}

if action in action_map:
self._github = Github(self.token)
return {action: action_map[action](**kwargs)}

raise ValueError(f"Action '{action}' is not supported.")

# Branch Management Methods
def create_branch(
self, repo_name: str, branch_name: str, source: str = "main"
) -> str:
try:
repo = self._github.get_repo(repo_name)
source_branch = repo.get_branch(source)
repo.create_git_ref(
ref=f"refs/heads/{branch_name}", sha=source_branch.commit.sha
)
return f"Branch '{branch_name}' created successfully."
except GithubException as e:
return f"Error creating branch: {e}"

def delete_branch(self, repo_name: str, branch_name: str) -> str:
try:
repo = self._github.get_repo(repo_name)
ref = repo.get_git_ref(f"heads/{branch_name}")
ref.delete()
return f"Branch '{branch_name}' deleted successfully."
except GithubException as e:
return f"Error deleting branch: {e}"

def list_branches(self, repo_name: str) -> List[str]:
try:
repo = self._github.get_repo(repo_name)
return [branch.name for branch in repo.get_branches()]
except GithubException as e:
return f"Error listing branches: {e}"

def get_branch(self, repo_name: str, branch_name: str) -> str:
try:
repo = self._github.get_repo(repo_name)
branch = repo.get_branch(branch_name)
return f"Branch {branch.name}: {branch.commit.sha}"
except GithubException as e:
return f"Error retrieving branch: {e}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# swarmauri/standard/tools/concrete/GithubTool.py

from github import Github, GithubException
from typing import List, Dict, Literal, Any
from pydantic import Field, ConfigDict
from swarmauri_base.tools.ToolBase import ToolBase
from swarmauri_standard.tool.Parameter import Parameter


class GithubCommitTool(ToolBase):
version: str = "1.1.0"
parameters: List[Parameter] = Field(
default_factory=lambda: [
Parameter(
name="action",
type="string",
description="The action to perform on the GitHub API, e.g., 'create_repo', 'delete_repo', 'create_issue', etc.",
required=True,
),
Parameter(
name="repo_name",
type="string",
description="The full name of the repository to interact with, e.g. 'owner/repository'.",
required=True,
),
Parameter(
name="file_path",
type="string",
description="The path to the file in the repository, e.g. 'path/to/file.txt'.",
required=False,
),
Parameter(
name="message",
type="string",
description=".",
required=False,
),
Parameter(
name="content",
type="string",
description="The name of the branch to interact with.",
required=False,
),
Parameter(
name="branch_name",
type="string",
description="The name of the branch to interact with.",
required=False,
),
Parameter(
name="sha",
type="string",
description="The sha of the commit to interact with.",
required=False,
),
Parameter(
name="base",
type="string",
description="The base of the commit to interact with.",
required=False,
),
Parameter(
name="head",
type="string",
description="The head of the commit to interact with.",
required=False,
),
]
)
name: str = "GithubCommitTool"
description: str = (
"Interacts with GitHub repositories using PyGithub to submit commits."
)
type: Literal["GithubCommitTool"] = "GithubCommitTool"
token: str
model_config = ConfigDict(arbitrary_types_allowed=True)

def __call__(self, action: str, **kwargs) -> Dict[str, Any]:
"""
Central method to call various GitHub API actions.
Args:
action (str): The action to perform.
**kwargs: Additional keyword arguments related to the action.
Returns:
Dict[str, Any]: The result of the action.
"""
action_map = {
"create_commit": self.create_commit,
"list_commits": self.list_commits,
"get_commit": self.get_commit,
"compare_commits": self.compare_commits,
}

if action in action_map:
self._github = Github(self.token)
return {action: action_map[action](**kwargs)}

raise ValueError(f"Action '{action}' is not supported.")

# Commit Management Methods
def create_commit(
self,
repo_name: str,
file_path: str,
message: str,
content: str,
branch: str = "main",
) -> str:
try:
repo = self._github.get_repo(repo_name)
repo.create_file(
path=file_path, message=message, content=content, branch=branch
)
return f"Commit created successfully at {file_path}."
except GithubException as e:
return f"Error creating commit: {e}"

def list_commits(self, repo_name: str) -> List[str]:
try:
repo = self._github.get_repo(repo_name)
return [commit.commit.message for commit in repo.get_commits()]
except GithubException as e:
return f"Error listing commits: {e}"

def get_commit(self, repo_name: str, sha: str) -> str:
try:
repo = self._github.get_repo(repo_name)
commit = repo.get_commit(sha=sha)
return f"Commit {commit.sha}: {commit.commit.message}"
except GithubException as e:
return f"Error retrieving commit: {e}"

def compare_commits(self, repo_name: str, base: str, head: str) -> str:
try:
repo = self._github.get_repo(repo_name)
comparison = repo.compare(base, head)
return f"Comparison from {base} to {head}:\n{comparison.diff_url}"
except GithubException as e:
return f"Error comparing commits: {e}"
Loading

0 comments on commit 72d552e

Please sign in to comment.