Spaces:
Runtime error
Runtime error
Miguel Cardoso commited on
Commit ·
6510272
1
Parent(s): 8d66b17
chore: minimal parser
Browse files- __pycache__/parser.cpython-312.pyc +0 -0
- app.py +5 -6
- parser.py +30 -0
- simplereview.md +4 -0
__pycache__/parser.cpython-312.pyc
ADDED
|
Binary file (1.88 kB). View file
|
|
|
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
| 3 |
|
| 4 |
def get_language_from_extension(extension):
|
| 5 |
ext_map = {
|
|
@@ -23,16 +23,15 @@ def get_language_from_extension(extension):
|
|
| 23 |
|
| 24 |
api_key = st.text_input("Enter your OpenAI API Key:", type="password")
|
| 25 |
|
| 26 |
-
|
| 27 |
def llmcall(input):
|
|
|
|
|
|
|
| 28 |
from openai import OpenAI
|
| 29 |
client = OpenAI(api_key = api_key)
|
| 30 |
completion = client.chat.completions.create(
|
| 31 |
model="gpt-3.5-turbo",
|
| 32 |
-
messages=
|
| 33 |
-
{"role": "system", "content": simple_review},
|
| 34 |
-
{"role": "user", "content": input}
|
| 35 |
-
]
|
| 36 |
)
|
| 37 |
|
| 38 |
return completion.choices[0].message.content
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from parser import MinimalPromptParser
|
| 3 |
|
| 4 |
def get_language_from_extension(extension):
|
| 5 |
ext_map = {
|
|
|
|
| 23 |
|
| 24 |
api_key = st.text_input("Enter your OpenAI API Key:", type="password")
|
| 25 |
|
| 26 |
+
|
| 27 |
def llmcall(input):
|
| 28 |
+
simple_review = MinimalPromptParser().parse_file('simplereview.md', {'code':input})
|
| 29 |
+
|
| 30 |
from openai import OpenAI
|
| 31 |
client = OpenAI(api_key = api_key)
|
| 32 |
completion = client.chat.completions.create(
|
| 33 |
model="gpt-3.5-turbo",
|
| 34 |
+
messages=simple_review
|
|
|
|
|
|
|
|
|
|
| 35 |
)
|
| 36 |
|
| 37 |
return completion.choices[0].message.content
|
parser.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class MinimalPromptParser:
|
| 2 |
+
def __init__(self):
|
| 3 |
+
self.parsed_data = []
|
| 4 |
+
|
| 5 |
+
def parse_file(self, filename, user_input):
|
| 6 |
+
with open(filename, 'r') as file:
|
| 7 |
+
role = None
|
| 8 |
+
content = ""
|
| 9 |
+
for line in file:
|
| 10 |
+
line = line.strip()
|
| 11 |
+
if line.startswith("system:") or line.startswith("user:"):
|
| 12 |
+
if role is not None:
|
| 13 |
+
self.parsed_data.append({"role": role, "content": content})
|
| 14 |
+
role = line.split(":")[0]
|
| 15 |
+
content = ""
|
| 16 |
+
else:
|
| 17 |
+
content += line + "\n"
|
| 18 |
+
if role is not None:
|
| 19 |
+
self.parsed_data.append({"role": role, "content": content})
|
| 20 |
+
|
| 21 |
+
self.replace_placeholders(user_input)
|
| 22 |
+
|
| 23 |
+
return self.parsed_data
|
| 24 |
+
|
| 25 |
+
def replace_placeholders(self, user_input):
|
| 26 |
+
for item in self.parsed_data:
|
| 27 |
+
content = item["content"]
|
| 28 |
+
for key, value in user_input.items():
|
| 29 |
+
content = content.replace("{{" + key + "}}", value)
|
| 30 |
+
item["content"] = content
|
simplereview.md
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
system:
|
| 2 |
+
You are an harsh code reviewer that enforces diligent and good code practices. You are tasked with reviewing the user code in a funny, spitefull and relevant way. Use markdown.
|
| 3 |
+
user:
|
| 4 |
+
{{code}}
|