Arcadia822 commited on
Commit
a9b5570
·
1 Parent(s): 29763aa
Files changed (1) hide show
  1. app.py +113 -7
app.py CHANGED
@@ -5,8 +5,110 @@ from codedog_demo.callbacks import get_sample_choices, request_pr_review, show_s
5
  sample_choices = get_sample_choices()
6
 
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  with gr.Blocks(theme="xiaobaiyuan/theme_brief") as demo:
9
- gr.Markdown("# Codedog Demo")
 
 
 
 
 
 
 
 
 
 
10
 
11
  with gr.Tab(label="Try Yourself"):
12
  with gr.Row():
@@ -20,20 +122,24 @@ with gr.Blocks(theme="xiaobaiyuan/theme_brief") as demo:
20
  custom_submit = gr.Button(value="Review It")
21
  with gr.Row():
22
  with gr.Tab(label="Markdown"):
23
- custom_content = gr.Markdown(value="")
24
  with gr.Tab(label="Raw"):
25
- custom_content_raw = gr.Textbox(show_label=False, lines=100, max_lines=500)
 
 
26
  custom_submit.click(
27
  request_pr_review,
28
  inputs=[custom_pr_url],
29
  outputs=[custom_content, custom_content_raw],
30
  )
31
 
32
- with gr.Tab(label="Samples"):
33
- sample_choice = gr.Radio(choices=sample_choices, type="index", show_label=False)
34
- sample_content = gr.Markdown(value="")
35
 
36
- sample_choice.input(show_sample, inputs=[sample_choice], outputs=[sample_content])
 
 
37
 
38
 
39
  if __name__ == "__main__":
 
5
  sample_choices = get_sample_choices()
6
 
7
 
8
+ text = """# [codedog-ai/codedog #2 - feat(telemetry): :sparkles: collect gpt api cost](https://github.com/codedog-ai/codedog/pull/2) Pull Request Report
9
+
10
+ *powered by GPT and codedog 0.8.2*
11
+
12
+ ## Execution
13
+ - Start at: 2023-09-07 07:18:18
14
+ - Time usage: 12.72s
15
+ - Openai api tokens: 3506
16
+ - Openai api costs: $0.0460
17
+
18
+
19
+
20
+
21
+ ## PR Summary
22
+
23
+ ### PR Overview
24
+ This PR is a new feature :sparkles:
25
+
26
+ 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'.
27
+
28
+
29
+
30
+ ### Change Details
31
+
32
+ | Major Changes | Description |
33
+ |---|---|
34
+ | **[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. |
35
+ | **[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. |
36
+
37
+
38
+
39
+
40
+ <details>
41
+ <summary><h3>Change File List</h3></summary>
42
+
43
+ Modified files:
44
+ - codedog/review.py
45
+ - examples/github/github_review.py
46
+
47
+
48
+ </details>
49
+
50
+
51
+
52
+ ## Code Review (preview)
53
+
54
+ *This feature is still under test. Suggestions are given by AI and might be incorrect.*
55
+
56
+ **[codedog/review.py](https://github.com/codedog-ai/codedog/pull/2/files#diff-10471033f603ac7fae28b2c7c57040e8732947f0)**
57
+
58
+ Based on the code diff, here are my observations and suggestions:
59
+
60
+ 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.
61
+
62
+ 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.
63
+
64
+ 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.
65
+
66
+ 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.
67
+
68
+ 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:
69
+
70
+ - It would be helpful to include comments or docstrings explaining the purpose and usage of the `_meter_api_call_tokens` method and its parameters.
71
+
72
+ - Consider using more descriptive variable names instead of abbreviations like `cb` to improve code readability.
73
+
74
+ - Ensure that the `cb.total_cost` value passed to `_meter_api_call_tokens` is calculated correctly and represents the actual cost of API calls.
75
+
76
+ - Consider adding unit tests to verify the correctness of the code changes and to ensure that the cost tracking functionality works as expected.
77
+
78
+ - Double-check if there are any other places in the codebase where the `cost` value needs to be updated or used.
79
+
80
+ These suggestions will help improve the clarity, maintainability, and reliability of the code.
81
+
82
+ **[examples/github/github_review.py](https://github.com/codedog-ai/codedog/pull/2/files#diff-78de2b9548d0316c55661aaf9b2222ad80a07012)**
83
+
84
+ 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:
85
+
86
+ 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.
87
+
88
+ 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.
89
+
90
+ 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.
91
+
92
+ 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.
93
+
94
+
95
+
96
+
97
+ """
98
+
99
+
100
  with gr.Blocks(theme="xiaobaiyuan/theme_brief") as demo:
101
+ gr.Markdown("# Codedog - A pull reqeust review tool")
102
+
103
+ gr.Markdown(
104
+ """**Codedog is designed to save reviewer's time by providing useful information based on PR context.**
105
+
106
+ - Github App (Rate limit is low): https://github.com/apps/codedog-assistant
107
+ - Source Code: https://github.com/codedog-ai/codedog
108
+ - Deploy as a service: https://github.com/codedog-ai/codedog/tree/master/examples
109
+ - Feedback or showcase ❤️: https://github.com/codedog-ai/codedog/discussions
110
+ """
111
+ )
112
 
113
  with gr.Tab(label="Try Yourself"):
114
  with gr.Row():
 
122
  custom_submit = gr.Button(value="Review It")
123
  with gr.Row():
124
  with gr.Tab(label="Markdown"):
125
+ custom_content = gr.Markdown(value=text)
126
  with gr.Tab(label="Raw"):
127
+ custom_content_raw = gr.Textbox(
128
+ value=text, show_label=False, lines=100, max_lines=500
129
+ )
130
  custom_submit.click(
131
  request_pr_review,
132
  inputs=[custom_pr_url],
133
  outputs=[custom_content, custom_content_raw],
134
  )
135
 
136
+ # with gr.Tab(label="Samples"):
137
+ # sample_choice = gr.Radio(choices=sample_choices, type="index", show_label=False)
138
+ # sample_content = gr.Markdown(value="")
139
 
140
+ # sample_choice.input(
141
+ # show_sample, inputs=[sample_choice], outputs=[sample_content]
142
+ # )
143
 
144
 
145
  if __name__ == "__main__":