Spaces:
Runtime error
Runtime error
import gradio as gr | |
from codedog_demo.callbacks import get_sample_choices, request_pr_review, show_sample | |
sample_choices = get_sample_choices() | |
text = """# [codedog-ai/codedog #2 - feat(telemetry): :sparkles: collect gpt api cost](https://github.com/codedog-ai/codedog/pull/2) Pull Request Report | |
*powered by GPT and codedog 0.8.2* | |
## Execution | |
- Start at: 2023-09-07 07:18:18 | |
- Time usage: 12.72s | |
- Openai api tokens: 3506 | |
- Openai api costs: $0.0460 | |
## PR Summary | |
### PR Overview | |
This PR is a new feature :sparkles: | |
This PR aims to collect the cost of GPT API calls from the openai callback of langchain. It modifies several functions in the 'codedog/review.py' file to include an additional parameter 'cb.total_cost' in the '_meter_api_call_tokens' function call and updates the value of the 'cost' key in the '_telemetry' dictionary. It also modifies the 'examples/github/github_review.py' file to update the variables 'repository_name_or_id' and 'pull_request_number'. | |
### Change Details | |
| Major Changes | Description | | |
|---|---| | |
| **[review.py](https://github.com/codedog-ai/codedog/pull/2/files#diff-10471033f603ac7fae28b2c7c57040e8732947f0 "codedog/review.py")** | This diff contains the following changes in the file codedog/review.py: - Added a new key "cost" to the dictionary `_telemetry` in the `__init__` function. - Modified the `_single_file_summarize` function to include an additional parameter `cb.total_cost` in the `_meter_api_call_tokens` function call. - Modified the `_changelist_summarize` function to include an additional parameter `cb.total_cost` in the `_meter_api_call_tokens` function call. - Modified the `_feedback` function to include an additional parameter `cb.total_cost` in the `_meter_api_call_tokens` function call. - Modified the `_meter_api_call_tokens` function to include a new parameter `cost` and update the value of the "cost" key in the `_telemetry` dictionary. - No other changes were made in the file. | | |
| **[github_review.py](https://github.com/codedog-ai/codedog/pull/2/files#diff-78de2b9548d0316c55661aaf9b2222ad80a07012 "examples/github/github_review.py")** | This diff contains changes in the file `github_review.py`. The changes include: - Commenting out the lines that set the variables `repository_name_or_id` and `pull_request_number` to "ClickHouse/ClickHouse" and 49113 respectively. - Adding new lines that set the variables `repository_name_or_id` to "Arcadia822/codedog" and `pull_request_number` to 2. - The function `build_pull_request_event` is called with the updated `repository_name_or_id` and `pull_request_number` variables. | | |
<details> | |
<summary><h3>Change File List</h3></summary> | |
Modified files: | |
- codedog/review.py | |
- examples/github/github_review.py | |
</details> | |
## Code Review (preview) | |
*This feature is still under test. Suggestions are given by AI and might be incorrect.* | |
**[codedog/review.py](https://github.com/codedog-ai/codedog/pull/2/files#diff-10471033f603ac7fae28b2c7c57040e8732947f0)** | |
Based on the code diff, here are my observations and suggestions: | |
1. Line 44: The code change to add a new key "cost" to the `_telemetry` dictionary seems correct. It allows tracking the cost associated with API calls. | |
2. Line 113 and 130: The code changes to the `_meter_api_call_tokens` method seem correct. It now accepts an additional parameter `cb.total_cost` to track the cost associated with API calls. | |
3. Line 144: The code change to pass `cb.total_cost` as the second argument to `_meter_api_call_tokens` method seems correct. It ensures that the cost is properly tracked for API calls made during the feedback process. | |
4. Line 175: The code change to add the `cost` key to the `TEMPLATE.REPORT_HEADER` format seems correct. It allows displaying the total cost in the generated report. | |
Overall, the code changes seem correct and aligned with the purpose of tracking API call costs. However, here are a few suggestions for the author: | |
- It would be helpful to include comments or docstrings explaining the purpose and usage of the `_meter_api_call_tokens` method and its parameters. | |
- Consider using more descriptive variable names instead of abbreviations like `cb` to improve code readability. | |
- Ensure that the `cb.total_cost` value passed to `_meter_api_call_tokens` is calculated correctly and represents the actual cost of API calls. | |
- Consider adding unit tests to verify the correctness of the code changes and to ensure that the cost tracking functionality works as expected. | |
- Double-check if there are any other places in the codebase where the `cost` value needs to be updated or used. | |
These suggestions will help improve the clarity, maintainability, and reliability of the code. | |
**[examples/github/github_review.py](https://github.com/codedog-ai/codedog/pull/2/files#diff-78de2b9548d0316c55661aaf9b2222ad80a07012)** | |
Based on the code diff, it seems that the author has made some changes to the `github_review.py` file. Here are my observations and suggestions: | |
1. The author has commented out the lines that set the `repository_name_or_id` and `pull_request_number` variables for the "ClickHouse/ClickHouse" repository. It appears that the author wants to disable this repository for now. If this change is intentional, it is fine. | |
2. The author has uncommented the lines that set the `repository_name_or_id` and `pull_request_number` variables for the "Arcadia822/codedog" repository and pull request number 2. If this change is intentional, it is fine. | |
3. It is important to ensure that the correct repository and pull request number are set for the desired review. Please double-check that the "Arcadia822/codedog" repository and pull request number 2 are the intended targets for the review. | |
Overall, the code change seems to be correct, assuming the author's intention is to disable the "ClickHouse/ClickHouse" repository and review the "Arcadia822/codedog" repository's pull request number 2. | |
""" | |
about = """Codedog is used for a while in my team (reviewed about 2000 PRs.). | |
Basically it's a service triggered by PR event and comment directly on the PR to give a pre human review. | |
Comment report includes PR summary and code suggestions. Summary is great and time saving. | |
But suggestions are not very valuable now. | |
CR practice learned from: https://google.github.io/eng-practices/review/reviewer | |
""" | |
with gr.Blocks(theme="xiaobaiyuan/theme_brief") as demo: | |
gr.Markdown("# Codedog - A pull reqeust review tool") | |
gr.Markdown( | |
"""**Codedog is designed to save reviewer's time by providing useful information based on PR context.** | |
- Github App (Rate limit is low): https://github.com/apps/codedog-assistant | |
- Source Code: https://github.com/codedog-ai/codedog | |
- Deploy as a service: https://github.com/codedog-ai/codedog/tree/master/examples | |
- Feedback or showcase ❤️: https://github.com/codedog-ai/codedog/discussions | |
""" | |
) | |
with gr.Tab(label="Try Yourself"): | |
with gr.Row(): | |
custom_pr_url = gr.Textbox( | |
max_lines=1, | |
value="https://github.com/codedog-ai/codedog/pull/2", | |
placeholder="Paste Github PR URL here", | |
show_label=False, | |
) | |
with gr.Row(): | |
custom_submit = gr.Button(value="Review It") | |
with gr.Row(): | |
with gr.Tab(label="Markdown"): | |
custom_content = gr.Markdown(value=text) | |
with gr.Tab(label="Raw"): | |
custom_content_raw = gr.Textbox( | |
value=text, show_label=False, lines=100, max_lines=500 | |
) | |
custom_submit.click( | |
request_pr_review, | |
inputs=[custom_pr_url], | |
outputs=[custom_content, custom_content_raw], | |
) | |
# with gr.Tab(label="Samples"): | |
# sample_choice = gr.Radio(choices=sample_choices, type="index", show_label=False) | |
# sample_content = gr.Markdown(value="") | |
# sample_choice.input( | |
# show_sample, inputs=[sample_choice], outputs=[sample_content] | |
# ) | |
with gr.Tab(label="About"): | |
gr.Markdown(value=about) | |
if __name__ == "__main__": | |
demo.launch() | |