Added setup scripts
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ __pycache__/
|
||||
.env
|
||||
|
||||
# Virtual environment
|
||||
venv/
|
||||
.venv/
|
||||
env/
|
||||
|
||||
# IDE files
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
@echo off
|
||||
call .venv\Scripts\activate
|
||||
@@ -0,0 +1,5 @@
|
||||
## Setting up the environment (Windows)
|
||||
|
||||
1. Run `python setup_venv.py` to create the virtual environment and install dependencies.
|
||||
2. To activate the virtual environment, run `activate_venv` in the Windows Terminal.
|
||||
3. To deactivate the virtual environment, simply type `deactivate`.
|
||||
@@ -0,0 +1,5 @@
|
||||
requests==2.26.0
|
||||
python-telegram-bot==21.4
|
||||
openai==1.41.0
|
||||
python-dotenv==1.0.1
|
||||
requests==2.32.3
|
||||
@@ -0,0 +1,20 @@
|
||||
import venv
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
def main():
|
||||
venv_path = Path(".venv")
|
||||
if not venv_path.exists():
|
||||
print("Creating virtual environment...")
|
||||
venv.create(venv_path, with_pip=True)
|
||||
|
||||
pip_path = venv_path / "bin" / "pip" if sys.platform != "win32" else venv_path / "Scripts" / "pip.exe"
|
||||
|
||||
print("Installing dependencies...")
|
||||
subprocess.run([str(pip_path), "install", "-r", "requirements.txt"])
|
||||
|
||||
print("Virtual environment setup complete.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,31 @@
|
||||
# tools/camera_tool.py
|
||||
from .base_tool import BaseTool
|
||||
import picamera
|
||||
import time
|
||||
import base64
|
||||
from io import BytesIO
|
||||
|
||||
class CameraTool(BaseTool):
|
||||
def get_functions(self):
|
||||
return [{
|
||||
"name": "take_picture",
|
||||
"description": "Take a picture using the Raspberry Pi camera",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"required": []
|
||||
}
|
||||
}]
|
||||
|
||||
def execute(self, function_name, **kwargs):
|
||||
if function_name == "take_picture":
|
||||
with picamera.PiCamera() as camera:
|
||||
camera.resolution = (1024, 768)
|
||||
camera.start_preview()
|
||||
# Camera warm-up time
|
||||
time.sleep(2)
|
||||
image_stream = BytesIO()
|
||||
camera.capture(image_stream, 'jpeg')
|
||||
image_stream.seek(0)
|
||||
image_base64 = base64.b64encode(image_stream.getvalue()).decode('utf-8')
|
||||
return f"data:image/jpeg;base64,{image_base64}"
|
||||
+114
-1
@@ -101,6 +101,67 @@ class GitHubTool(BaseTool):
|
||||
},
|
||||
"required": ["title", "body", "head"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "list_files",
|
||||
"description": "List files in a directory of the repository",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string",
|
||||
"description": "Path to the directory in the repository"
|
||||
}
|
||||
},
|
||||
"required": ["path"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "search_code",
|
||||
"description": "Search for code in the repository",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"query": {
|
||||
"type": "string",
|
||||
"description": "Search query"
|
||||
}
|
||||
},
|
||||
"required": ["query"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "get_commit_history",
|
||||
"description": "Get commit history for a file",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"file_path": {
|
||||
"type": "string",
|
||||
"description": "Path to the file in the repository"
|
||||
},
|
||||
"num_commits": {
|
||||
"type": "integer",
|
||||
"description": "Number of commits to retrieve",
|
||||
"default": 10
|
||||
}
|
||||
},
|
||||
"required": ["file_path"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "get_branch_sha",
|
||||
"description": "Get the SHA of the latest commit on a branch",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"branch": {
|
||||
"type": "string",
|
||||
"description": "Name of the branch"
|
||||
}
|
||||
},
|
||||
"required": ["branch"]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -112,7 +173,15 @@ class GitHubTool(BaseTool):
|
||||
elif function_name == "commit_file":
|
||||
return self._commit_file(kwargs["branch_name"], kwargs["file_path"], kwargs["content"], kwargs["commit_message"])
|
||||
elif function_name == "create_pull_request":
|
||||
return self._create_pull_request(kwargs["title"], kwargs["body"], kwargs["head"], kwargs.get("base", "main"))
|
||||
return self._create_pull_request(kwargs["title"], kwargs["body"], kwargs["head"], kwargs.get("base", "main"))
|
||||
elif function_name == "list_files":
|
||||
return self._list_files(kwargs["path"])
|
||||
elif function_name == "search_code":
|
||||
return self._search_code(kwargs["query"])
|
||||
elif function_name == "get_commit_history":
|
||||
return self._get_commit_history(kwargs["file_path"], kwargs.get("num_commits", 10))
|
||||
elif function_name == "get_branch_sha":
|
||||
return self._get_branch_sha(kwargs["branch"])
|
||||
else:
|
||||
return f"Unknown function: {function_name}"
|
||||
|
||||
@@ -183,4 +252,48 @@ class GitHubTool(BaseTool):
|
||||
return f"Pull request created successfully: {response.json()['html_url']}"
|
||||
else:
|
||||
return f"Error creating pull request: {response.status_code}\nResponse: {response.text}"
|
||||
|
||||
def _get_branch_sha(self, branch):
|
||||
url = f"{self.base_url}/repos/{self.repo}/git/refs/heads/{branch}"
|
||||
response = requests.get(url, headers=self.headers)
|
||||
if response.status_code == 200:
|
||||
return response.json()["object"]["sha"]
|
||||
else:
|
||||
return f"Error getting branch SHA: {response.status_code}"
|
||||
|
||||
def _list_files(self, path, branch):
|
||||
url = f"{self.base_url}/repos/{self.repo}/contents/{path}"
|
||||
params = {"ref": branch}
|
||||
response = requests.get(url, headers=self.headers, params=params)
|
||||
if response.status_code == 200:
|
||||
files = [item["name"] for item in response.json() if item["type"] == "file"]
|
||||
directories = [item["name"] for item in response.json() if item["type"] == "dir"]
|
||||
return {"files": files, "directories": directories}
|
||||
else:
|
||||
return f"Error listing files: {response.status_code}"
|
||||
|
||||
def _search_code(self, query):
|
||||
url = f"{self.base_url}/search/code"
|
||||
params = {
|
||||
"q": f"{query} repo:{self.repo}",
|
||||
"per_page": 10
|
||||
}
|
||||
response = requests.get(url, headers=self.headers, params=params)
|
||||
if response.status_code == 200:
|
||||
results = [{"file": item["path"], "url": item["html_url"]} for item in response.json()["items"]]
|
||||
return results
|
||||
else:
|
||||
return f"Error searching code: {response.status_code}"
|
||||
|
||||
def _get_commit_history(self, file_path, num_commits):
|
||||
url = f"{self.base_url}/repos/{self.repo}/commits"
|
||||
params = {
|
||||
"path": file_path,
|
||||
"per_page": num_commits
|
||||
}
|
||||
response = requests.get(url, headers=self.headers, params=params)
|
||||
if response.status_code == 200:
|
||||
commits = [{"sha": commit["sha"], "message": commit["commit"]["message"], "date": commit["commit"]["author"]["date"]} for commit in response.json()]
|
||||
return commits
|
||||
else:
|
||||
return f"Error getting commit history: {response.status_code}"
|
||||
Reference in New Issue
Block a user