This commit is contained in:
mrT23
2024-04-14 12:34:14 +03:00
parent 8f0f08006f
commit 4683a29819
3 changed files with 34 additions and 5 deletions

View File

@ -7,9 +7,9 @@ It can be invoked manually by commenting on any PR:
``` ```
For example: For example:
![Ask Comment](https://codium.ai/images/pr_agent/ask_comment.png){width=768} ![Ask Comment](https://codium.ai/images/pr_agent/ask_comment.png){width=512}
![Ask](https://codium.ai/images/pr_agent/ask.png){width=768} ![Ask](https://codium.ai/images/pr_agent/ask.png){width=512}
## Ask lines ## Ask lines
@ -18,6 +18,35 @@ You can run `/ask` on specific lines of code in the PR from the PR's diff view.
- To select multiple lines, click on the '+' sign of the first line and then hold and drag to select the rest of the lines. - To select multiple lines, click on the '+' sign of the first line and then hold and drag to select the rest of the lines.
- write `/ask "..."` in the comment box and press `Add single comment` button. - write `/ask "..."` in the comment box and press `Add single comment` button.
![Ask Line](https://codium.ai/images/pr_agent/Ask_line.png){width=768} ![Ask Line](https://codium.ai/images/pr_agent/Ask_line.png){width=512}
Note that the tool does not have "memory" of previous questions, and answers each question independently. Note that the tool does not have "memory" of previous questions, and answers each question independently.
## Ask on images (using the PR code as context)
You can also ask questions about images that appear in the comment, where the entire PR is considered as the context. The tool will answer questions based on the images in the PR.
The basic syntax is:
```
/ask "..."
[Image](https://real_link_to_image)
```
Note that GitHub has a mecahnism of pasting images in comments. However, pasted image does not provide a direct link.
To get a direct link to the image, we recommend using the following steps:
1) send a comment that contains only the image:
![Ask image1](https://codium.ai/images/pr_agent/ask_images1.png){width=512}
2) quote reply to that comment:
![Ask image2](https://codium.ai/images/pr_agent/ask_images2.png){width=512}
3) type the question below the image:
![Ask image3](https://codium.ai/images/pr_agent/ask_images3.png){width=512}
![Ask image4](https://codium.ai/images/pr_agent/ask_images3.png){width=512}
4) post the comment, and receive the answer:
![Ask image5](https://codium.ai/images/pr_agent/ask_images5.png){width=512}

View File

@ -113,7 +113,7 @@ class LiteLLMAIHandler(BaseAiHandler):
import requests import requests
r = requests.get(img_path, allow_redirects=True) r = requests.get(img_path, allow_redirects=True)
if r.status_code == 404: if r.status_code == 404:
error_msg = "The image link is not alive. Please repost the image, get a new address, and send the question again." error_msg = f"The image link is not [alive](img_path).\nPlease repost the original image as a comment, and send the question again with 'quote reply' (see [instructions](https://pr-agent-docs.codium.ai/tools/ask/#ask-on-images-using-the-pr-code-as-context))."
get_logger().error(error_msg) get_logger().error(error_msg)
return f"{error_msg}", "error" return f"{error_msg}", "error"
messages[1]["content"] = [{"type": "text", "text": messages[1]["content"]}, messages[1]["content"] = [{"type": "text", "text": messages[1]["content"]},

View File

@ -88,7 +88,7 @@ async def handle_comments_on_pr(body: Dict[str, Any],
if comment_body and isinstance(comment_body, str) and not comment_body.lstrip().startswith("/"): if comment_body and isinstance(comment_body, str) and not comment_body.lstrip().startswith("/"):
if '/ask' in comment_body and comment_body.strip().startswith('> ![image]'): if '/ask' in comment_body and comment_body.strip().startswith('> ![image]'):
comment_body_split = comment_body.split('/ask') comment_body_split = comment_body.split('/ask')
comment_body = '/ask' + comment_body_split[1] +'/n' +comment_body_split[0].strip() comment_body = '/ask' + comment_body_split[1] +' \n' +comment_body_split[0].strip().lstrip('>')
get_logger().info(f"Reformatting comment_body so command is at the beginning: {comment_body}") get_logger().info(f"Reformatting comment_body so command is at the beginning: {comment_body}")
else: else:
get_logger().info("Ignoring comment not starting with /") get_logger().info("Ignoring comment not starting with /")