Skip to content

Commit

Permalink
Add day limit to get_repo_commits (#1133)
Browse files Browse the repository at this point in the history
* Add day limit to get_repo_commits

* Fix OpenAI provider
  • Loading branch information
Josh-XT authored Mar 7, 2024
1 parent 1375b6c commit 6994c27
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions agixt/extensions/github.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import time
import datetime

try:
import git
Expand Down Expand Up @@ -75,6 +76,7 @@ async def clone_repo(self, repo_url: str) -> str:
# Pull the latest changes
repo = git.Repo(repo_dir)
repo.remotes.origin.pull()
self.failures = 0
return f"Pulled latest changes for {repo_url} to {repo_dir}"
git.Repo.clone_from(
url=auth_repo_url,
Expand Down Expand Up @@ -321,22 +323,27 @@ async def update_repo_pull_request(
except Exception as e:
return f"Error: {str(e)}"

async def get_repo_commits(self, repo_url: str) -> str:
async def get_repo_commits(self, repo_url: str, days: int = 7) -> str:
try:
repo = self.gh.get_repo(repo_url.split("github.com/")[-1])
commits = repo.get_commits()
if days == 0:
commits = repo.get_commits()
else:
since = datetime.datetime.now() - datetime.timedelta(days=days)
commits = repo.get_commits(since=since)
commit_list = []
for commit in commits:
commit_list.append(f"{commit.sha}: {commit.commit.message}")
self.failures = 0
return f"Commits for GitHub Repository at {repo_url}:\n\n" + "\n".join(
commit_list
return (
f"Commits for GitHub Repository at {repo_url} (last {days} days):\n\n"
+ "\n".join(commit_list)
)
except RateLimitExceededException:
if self.failures < 3:
self.failures += 1
time.sleep(5)
return await self.get_repo_commits(repo_url)
return await self.get_repo_commits(repo_url, days)
return "Error: GitHub API rate limit exceeded. Please try again later."
except Exception as e:
return f"Error: {str(e)}"
Expand Down
2 changes: 1 addition & 1 deletion agixt/providers/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def inference(self, prompt, tokens: int = 0):
n=1,
stream=False,
)
return response.messages[-1]["content"]
return response.choices[0].message.content
except Exception as e:
logging.info(f"OpenAI API Error: {e}")
if "," in self.API_URI:
Expand Down

0 comments on commit 6994c27

Please sign in to comment.