Yashnik commited on
Commit
0989ed9
·
verified ·
1 Parent(s): 58e409e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -5
app.py CHANGED
@@ -6,11 +6,52 @@ chatbot = pipeline(model="bigcode/starcoder2-15b")
6
  message_list = []
7
  response_list = []
8
 
9
- def vanilla_chatbot(message, history):
10
- conversation = chatbot(message)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
 
12
  return conversation[0]['generated_text']
13
 
14
- demo_chatbot = gr.ChatInterface(vanilla_chatbot, title="YourCoder Chatbot", description="Enter piece of code to generate a code review!")
15
-
16
- demo_chatbot.launch()
 
6
  message_list = []
7
  response_list = []
8
 
9
+ def YourCoder_chatbot(message, history):
10
+
11
+ python_code_examples = f"""
12
+ ---------------------
13
+ Example 1: Code Snippet
14
+ def calculate_average(numbers):
15
+ total = 0
16
+ for number in numbers:
17
+ total += number
18
+ average = total / len(numbers)
19
+ return average
20
+ Code Review: Consider using the sum() function to calculate the total sum of the numbers
21
+ instead of manually iterating over the list.
22
+ This would make the code more concise and efficient.
23
+ ---------------------
24
+ Example 2: Code Snippet
25
+ def find_largest_number(numbers):
26
+ largest_number = numbers[0]
27
+ for number in numbers:
28
+ if number > largest_number:
29
+ largest_number = number
30
+ return largest_number
31
+ Code Review: Refactor the code using the max() function to find the largest number in the list.
32
+ This would simplify the code and improve its readability.
33
+ ---------------------
34
+ """
35
+
36
+ prompt = f"""
37
+ I will provide you with code snippets,
38
+ and you will review them for potential issues and suggest improvements.
39
+ Please focus on providing concise and actionable feedback, highlighting areas
40
+ that could benefit from refactoring, optimization, or bug fixes.
41
+ Your feedback should be constructive and aim to enhance the overall quality and maintainability of the code.
42
+ Please avoid providing explanations for your suggestions unless specifically requested. Instead, focus on clearly identifying areas for improvement and suggesting alternative approaches or solutions.
43
+ Few good examples of Python code output between #### separator:
44
+ ####
45
+ {python_code_examples}
46
+ ####
47
+ Code Snippet is shared below, delimited with triple backticks:
48
+ ```
49
+ {message}
50
+ ```
51
+ """
52
 
53
+ conversation = chatbot(prompt)
54
  return conversation[0]['generated_text']
55
 
56
+ chatbot = gr.ChatInterface(YourCoder_chatbot, title="YourCoder Chatbot", description="Enter piece of code to generate a code review!")
57
+ chatbot.launch()