mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-05 13:20:39 +08:00
stable
This commit is contained in:
12
Usage.md
12
Usage.md
@ -50,12 +50,12 @@ When running from your local repo (CLI), your local configuration file will be u
|
|||||||
|
|
||||||
Examples for invoking the different tools via the CLI:
|
Examples for invoking the different tools via the CLI:
|
||||||
|
|
||||||
- **Review**: `python cli.py --pr_url=<pr_url> /review`
|
- **Review**: `python cli.py --pr_url=<pr_url> review`
|
||||||
- **Describe**: `python cli.py --pr_url=<pr_url> /describe`
|
- **Describe**: `python cli.py --pr_url=<pr_url> describe`
|
||||||
- **Improve**: `python cli.py --pr_url=<pr_url> /improve`
|
- **Improve**: `python cli.py --pr_url=<pr_url> improve`
|
||||||
- **Ask**: `python cli.py --pr_url=<pr_url> /ask "Write me a poem about this PR"`
|
- **Ask**: `python cli.py --pr_url=<pr_url> ask "Write me a poem about this PR"`
|
||||||
- **Reflect**: `python cli.py --pr_url=<pr_url> /reflect`
|
- **Reflect**: `python cli.py --pr_url=<pr_url> reflect`
|
||||||
- **Update Changelog**: `python cli.py --pr_url=<pr_url> /update_changelog`
|
- **Update Changelog**: `python cli.py --pr_url=<pr_url> update_changelog`
|
||||||
|
|
||||||
`<pr_url>` is the url of the relevant PR (for example: https://github.com/Codium-ai/pr-agent/pull/50).
|
`<pr_url>` is the url of the relevant PR (for example: https://github.com/Codium-ai/pr-agent/pull/50).
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ import os
|
|||||||
|
|
||||||
from pr_agent.agent.pr_agent import PRAgent, commands
|
from pr_agent.agent.pr_agent import PRAgent, commands
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
from pr_agent.tools.pr_similar_issue import PRSimilarIssue
|
|
||||||
|
|
||||||
|
|
||||||
def run(inargs=None):
|
def run(inargs=None):
|
||||||
@ -18,6 +17,7 @@ For example:
|
|||||||
- cli.py --pr_url=... improve
|
- cli.py --pr_url=... improve
|
||||||
- cli.py --pr_url=... ask "write me a poem about this PR"
|
- cli.py --pr_url=... ask "write me a poem about this PR"
|
||||||
- cli.py --pr_url=... reflect
|
- cli.py --pr_url=... reflect
|
||||||
|
- cli.py --issue_url=... similar_issue
|
||||||
|
|
||||||
Supported commands:
|
Supported commands:
|
||||||
-review / review_pr - Add a review that includes a summary of the PR and specific suggestions for improvement.
|
-review / review_pr - Add a review that includes a summary of the PR and specific suggestions for improvement.
|
||||||
@ -38,17 +38,20 @@ Configuration:
|
|||||||
To edit any configuration parameter from 'configuration.toml', just add -config_path=<value>.
|
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: ..."'
|
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')
|
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('--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('command', type=str, help='The', choices=commands, default='review')
|
||||||
parser.add_argument('rest', nargs=argparse.REMAINDER, default=[])
|
parser.add_argument('rest', nargs=argparse.REMAINDER, default=[])
|
||||||
args = parser.parse_args(inargs)
|
args = parser.parse_args(inargs)
|
||||||
|
if not args.pr_url and not args.issue_url:
|
||||||
|
parser.print_help()
|
||||||
|
return
|
||||||
|
|
||||||
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
|
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
|
||||||
command = args.command.lower()
|
command = args.command.lower()
|
||||||
get_settings().set("CONFIG.CLI_MODE", True)
|
get_settings().set("CONFIG.CLI_MODE", True)
|
||||||
if args.issue_url:
|
if args.issue_url:
|
||||||
result = asyncio.run(PRAgent().handle_request(args.issue_url, command + " " + " ".join(args.rest)))
|
result = asyncio.run(PRAgent().handle_request(args.issue_url, command + " " + " ".join(args.rest)))
|
||||||
# result = asyncio.run(PRSimilarIssue(args.issue_url, cli_mode=True, args=command + " " + " ".join(args.rest)).run())
|
|
||||||
else:
|
else:
|
||||||
result = asyncio.run(PRAgent().handle_request(args.pr_url, command + " " + " ".join(args.rest)))
|
result = asyncio.run(PRAgent().handle_request(args.pr_url, command + " " + " ".join(args.rest)))
|
||||||
if not result:
|
if not result:
|
||||||
|
@ -132,7 +132,7 @@ class PRSimilarIssue:
|
|||||||
header = issue.title
|
header = issue.title
|
||||||
body = issue.body
|
body = issue.body
|
||||||
number = issue.number
|
number = issue.number
|
||||||
if get_settings().pinecone.skip_comments:
|
if get_settings().pr_similar_issue.skip_comments:
|
||||||
comments = []
|
comments = []
|
||||||
else:
|
else:
|
||||||
comments = list(issue.get_comments())
|
comments = list(issue.get_comments())
|
||||||
@ -151,11 +151,12 @@ class PRSimilarIssue:
|
|||||||
|
|
||||||
counter = 0
|
counter = 0
|
||||||
for issue in issues_list:
|
for issue in issues_list:
|
||||||
|
|
||||||
if issue.pull_request:
|
if issue.pull_request:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
counter += 1
|
counter += 1
|
||||||
|
if counter % 100 == 0:
|
||||||
|
logging.info(f"Scanned {counter} issues")
|
||||||
if counter >= self.max_issues_to_scan:
|
if counter >= self.max_issues_to_scan:
|
||||||
logging.info(f"Scanned {self.max_issues_to_scan} issues, stopping")
|
logging.info(f"Scanned {self.max_issues_to_scan} issues, stopping")
|
||||||
break
|
break
|
||||||
@ -179,7 +180,7 @@ class PRSimilarIssue:
|
|||||||
for j, comment in enumerate(comments):
|
for j, comment in enumerate(comments):
|
||||||
comment_body = comment.body
|
comment_body = comment.body
|
||||||
num_words_comment = len(comment_body.split())
|
num_words_comment = len(comment_body.split())
|
||||||
if num_words_comment < 10:
|
if num_words_comment < 10 or not isinstance(comment_body, str):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if len(issue_str) < 8000 or \
|
if len(issue_str) < 8000 or \
|
||||||
@ -199,8 +200,14 @@ class PRSimilarIssue:
|
|||||||
logging.info('Embedding...')
|
logging.info('Embedding...')
|
||||||
openai.api_key = get_settings().openai.key
|
openai.api_key = get_settings().openai.key
|
||||||
list_to_encode = list(df["text"].values)
|
list_to_encode = list(df["text"].values)
|
||||||
|
try:
|
||||||
res = openai.Embedding.create(input=list_to_encode, engine=MODEL)
|
res = openai.Embedding.create(input=list_to_encode, engine=MODEL)
|
||||||
embeds = [record['embedding'] for record in res['data']]
|
embeds = [record['embedding'] for record in res['data']]
|
||||||
|
except:
|
||||||
|
embeds = []
|
||||||
|
for i, text in enumerate(list_to_encode):
|
||||||
|
res = openai.Embedding.create(input=[text], engine=MODEL)
|
||||||
|
embeds.append(res['data'][0]['embedding'])
|
||||||
df["values"] = embeds
|
df["values"] = embeds
|
||||||
meta = DatasetMetadata.empty()
|
meta = DatasetMetadata.empty()
|
||||||
meta.dense_model.dimension = len(embeds[0])
|
meta.dense_model.dimension = len(embeds[0])
|
||||||
@ -210,7 +217,7 @@ class PRSimilarIssue:
|
|||||||
api_key = get_settings().pinecone.api_key
|
api_key = get_settings().pinecone.api_key
|
||||||
environment = get_settings().pinecone.environment
|
environment = get_settings().pinecone.environment
|
||||||
if not upsert:
|
if not upsert:
|
||||||
logging.info('Creating index...')
|
logging.info('Creating index from scratch...')
|
||||||
ds.to_pinecone_index(self.index_name, api_key=api_key, environment=environment)
|
ds.to_pinecone_index(self.index_name, api_key=api_key, environment=environment)
|
||||||
else:
|
else:
|
||||||
logging.info('Upserting index...')
|
logging.info('Upserting index...')
|
||||||
|
Reference in New Issue
Block a user