Skip to content

Commit

Permalink
adjustments to pypi
Browse files Browse the repository at this point in the history
  • Loading branch information
mrT23 committed Mar 23, 2024
1 parent 2fccadc commit 9a46690
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 33 deletions.
43 changes: 43 additions & 0 deletions docs/docs/installation/locally.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
## Using Pip package

1. Install the package:

```
pip install pr-agent
```

2. Run the relevant tool. Make sure to fill in the required parameters (`user_token`, `openai_key`, `pr_url`, `command`):

```python
from pr_agent import cli
from pr_agent.config_loader import get_settings
from pr_agent.log import setup_logger

setup_logger()


def main():
# Fill in the following values
provider = "github" # GitHub provider
user_token = "..." # GitHub user token
openai_key = "..." # OpenAI key
pr_url = "..." # PR URL, for example 'https://github.com/Codium-ai/pr-agent/pull/809'
command = "/review" # Command to run (e.g. '/review', '/describe', '/ask="What is the purpose of this PR?"', ...)

# Setting the configurations
get_settings().set("CONFIG.git_provider", provider)
get_settings().set("openai.key", openai_key)
get_settings().set("github.user_token", user_token)

# Preparing the command
run_command = f"--pr_url={pr_url} {command.lstrip('/')}"
args = cli.set_parser().parse_args(run_command.split())

# Run the command. Feedback will appear in GitHub PR comments
cli.run(args=args)


if __name__ == '__main__':
main()
```

## Use Docker image (no installation required)

A list of the relevant tools can be found in the [tools guide](../tools/ask.md).
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/usage-guide/automations_and_usage.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Local repo (CLI)
When running from your local repo (CLI), your local configuration file will be used.
When running from your locally cloned PR-Agent repo (CLI), your local configuration file will be used.
Examples of invoking the different tools via the CLI:

- **Review**: `python -m pr_agent.cli --pr_url=<pr_url> review`
Expand Down
58 changes: 31 additions & 27 deletions pr_agent/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,52 @@
log_level = os.environ.get("LOG_LEVEL", "INFO")
setup_logger(log_level)



def run(inargs=None):
def set_parser():
parser = argparse.ArgumentParser(description='AI based pull request analyzer', usage=
"""\
Usage: cli.py --pr-url=<URL on supported git hosting service> <command> [<args>].
For example:
- cli.py --pr_url=... review
- cli.py --pr_url=... describe
- cli.py --pr_url=... improve
- cli.py --pr_url=... ask "write me a poem about this PR"
- cli.py --pr_url=... reflect
- cli.py --issue_url=... similar_issue
"""\
Usage: cli.py --pr-url=<URL on supported git hosting service> <command> [<args>].
For example:
- cli.py --pr_url=... review
- cli.py --pr_url=... describe
- cli.py --pr_url=... improve
- cli.py --pr_url=... ask "write me a poem about this PR"
- cli.py --pr_url=... reflect
- cli.py --issue_url=... similar_issue
Supported commands:
- review / review_pr - Add a review that includes a summary of the PR and specific suggestions for improvement.
Supported commands:
- review / review_pr - Add a review that includes a summary of the PR and specific suggestions for improvement.
- ask / ask_question [question] - Ask a question about the PR.
- ask / ask_question [question] - Ask a question about the PR.
- describe / describe_pr - Modify the PR title and description based on the PR's contents.
- describe / describe_pr - Modify the PR title and description based on the PR's contents.
- improve / improve_code - Suggest improvements to the code in the PR as pull request comments ready to commit.
Extended mode ('improve --extended') employs several calls, and provides a more thorough feedback
- improve / improve_code - Suggest improvements to the code in the PR as pull request comments ready to commit.
Extended mode ('improve --extended') employs several calls, and provides a more thorough feedback
- reflect - Ask the PR author questions about the PR.
- reflect - Ask the PR author questions about the PR.
- update_changelog - Update the changelog based on the PR's contents.
- update_changelog - Update the changelog based on the PR's contents.
- add_docs
- add_docs
- generate_labels
- generate_labels
Configuration:
To edit any configuration parameter from 'configuration.toml', just add -config_path=<value>.
For example: 'python cli.py --pr_url=... review --pr_reviewer.extra_instructions="focus on the file: ..."'
""")
Configuration:
To edit any configuration parameter from 'configuration.toml', just add -config_path=<value>.
For example: 'python cli.py --pr_url=... review --pr_reviewer.extra_instructions="focus on the file: ..."'
""")
parser.add_argument('--pr_url', type=str, help='The URL of the PR to review', default=None)
parser.add_argument('--issue_url', type=str, help='The URL of the Issue to review', default=None)
parser.add_argument('command', type=str, help='The', choices=commands, default='review')
parser.add_argument('rest', nargs=argparse.REMAINDER, default=[])
args = parser.parse_args(inargs)
return parser


def run(inargs=None, args=None):
parser = set_parser()
if not args:
args = parser.parse_args(inargs)
if not args.pr_url and not args.issue_url:
parser.print_help()
return
Expand Down
30 changes: 30 additions & 0 deletions pr_agent/cli_pip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from pr_agent import cli
from pr_agent.config_loader import get_settings
from pr_agent.log import setup_logger

setup_logger()


def main():
# Fill in the following values
provider = "github" # GitHub provider
user_token = "..." # GitHub user token
openai_key = "..." # OpenAI key
pr_url = "..." # PR URL, for example 'https://github.com/Codium-ai/pr-agent/pull/809'
command = "/review" # Command to run (e.g. '/review', '/describe', '/ask="What is the purpose of this PR?"')

# Setting the configurations
get_settings().set("CONFIG.git_provider", provider)
get_settings().set("openai.key", openai_key)
get_settings().set("github.user_token", user_token)

# Preparing the command
run_command = f"--pr_url={pr_url} {command.lstrip('/')}"
args = cli.set_parser().parse_args(run_command.split())

# Run the command. Feedback will appear in GitHub PR comments
cli.run(args=args)


if __name__ == '__main__':
main()
3 changes: 2 additions & 1 deletion pr_agent/tools/pr_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class PRQuestions:
def __init__(self, pr_url: str, args=None, ai_handler: partial[BaseAiHandler,] = LiteLLMAIHandler):
question_str = self.parse_args(args)
self.pr_url = pr_url
self.git_provider = get_git_provider()(pr_url)
self.main_pr_language = get_main_pr_language(
self.git_provider.get_languages(), self.git_provider.get_files()
Expand Down Expand Up @@ -49,7 +50,7 @@ def parse_args(self, args):
return question_str

async def run(self):
get_logger().info('Answering a PR question...')
get_logger().info(f'Answering a PR question about the PR {self.pr_url} ')
relevant_configs = {'pr_questions': dict(get_settings().pr_questions),
'config': dict(get_settings().config)}
get_logger().debug("Relevant configs", artifacts=relevant_configs)
Expand Down
14 changes: 10 additions & 4 deletions pr_agent/tools/pr_similar_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
from typing import List

import openai
import pandas as pd
import pinecone
from pinecone_datasets import Dataset, DatasetMetadata
from pydantic import BaseModel, Field

from pr_agent.algo import MAX_TOKENS
Expand Down Expand Up @@ -36,6 +33,12 @@ def __init__(self, issue_url: str, ai_handler, args: list = None):
index_name = self.index_name = "codium-ai-pr-agent-issues"

if get_settings().pr_similar_issue.vectordb == "pinecone":
try:
import pinecone
from pinecone_datasets import Dataset, DatasetMetadata
import pandas as pd
except:
raise Exception("Please install 'pinecone' and 'pinecone_datasets' to use pinecone as vectordb")
# assuming pinecone api key and environment are set in secrets file
try:
api_key = get_settings().pinecone.api_key
Expand Down Expand Up @@ -107,7 +110,10 @@ def __init__(self, issue_url: str, ai_handler, args: list = None):
get_logger().info('No new issues to update')

elif get_settings().pr_similar_issue.vectordb == "lancedb":
import lancedb # import lancedb only if needed
try:
import lancedb # import lancedb only if needed
except:
raise Exception("Please install lancedb to use lancedb as vectordb")
self.db = lancedb.connect(get_settings().lancedb.uri)
self.table = None

Expand Down

0 comments on commit 9a46690

Please sign in to comment.