Spaces:
Sleeping
Sleeping
Upload 10 files
Browse files
app.py
CHANGED
|
@@ -39,9 +39,6 @@ def app():
|
|
| 39 |
with st.form("repo_url_form"):
|
| 40 |
repo_form.display_form()
|
| 41 |
|
| 42 |
-
# Check if the API key is valid before proceeding
|
| 43 |
-
if repo_form.clone_repo_button and not repo_form.is_api_key_valid():
|
| 44 |
-
st.stop()
|
| 45 |
|
| 46 |
repo_url, extensions = repo_form.get_form_data()
|
| 47 |
|
|
|
|
| 39 |
with st.form("repo_url_form"):
|
| 40 |
repo_form.display_form()
|
| 41 |
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
repo_url, extensions = repo_form.get_form_data()
|
| 44 |
|
forms.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import logging
|
| 2 |
import os
|
| 3 |
|
| 4 |
-
import
|
| 5 |
import repo
|
| 6 |
import streamlit as st
|
| 7 |
from streamlit_tree_select import tree_select
|
|
@@ -25,15 +25,7 @@ class RepoForm:
|
|
| 25 |
self.repo_url = st.text_input(
|
| 26 |
"GitHub Repository URL:", self.default_repo_url
|
| 27 |
)
|
| 28 |
-
|
| 29 |
-
env_api_key = os.getenv("OPENAI_API_KEY", "")
|
| 30 |
-
self.api_key = st.text_input(
|
| 31 |
-
"OpenAI API Key:",
|
| 32 |
-
env_api_key,
|
| 33 |
-
placeholder="Paste your API key here",
|
| 34 |
-
)
|
| 35 |
-
openai.api_key = self.api_key
|
| 36 |
-
|
| 37 |
self.extensions = st.multiselect(
|
| 38 |
"File extensions to analyze",
|
| 39 |
options=self.options,
|
|
|
|
| 1 |
import logging
|
| 2 |
import os
|
| 3 |
|
| 4 |
+
from openai import OpenAI
|
| 5 |
import repo
|
| 6 |
import streamlit as st
|
| 7 |
from streamlit_tree_select import tree_select
|
|
|
|
| 25 |
self.repo_url = st.text_input(
|
| 26 |
"GitHub Repository URL:", self.default_repo_url
|
| 27 |
)
|
| 28 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
self.extensions = st.multiselect(
|
| 30 |
"File extensions to analyze",
|
| 31 |
options=self.options,
|
query.py
CHANGED
|
@@ -1,12 +1,14 @@
|
|
| 1 |
import logging
|
| 2 |
from textwrap import dedent
|
| 3 |
from typing import Iterable
|
| 4 |
-
|
| 5 |
-
import
|
|
|
|
| 6 |
import streamlit as st
|
| 7 |
import tiktoken
|
| 8 |
|
| 9 |
-
|
|
|
|
| 10 |
def analyze_code_files(code_files: list[str]) -> Iterable[dict[str, str]]:
|
| 11 |
"""Analyze the selected code files and return recommendations."""
|
| 12 |
return (analyze_code_file(code_file) for code_file in code_files)
|
|
@@ -134,7 +136,7 @@ Your review:"""
|
|
| 134 |
|
| 135 |
logging.info("Sending request to OpenAI API for code analysis")
|
| 136 |
logging.info("Max response tokens: %d", tokens_for_response)
|
| 137 |
-
response =
|
| 138 |
model="gpt-3.5-turbo",
|
| 139 |
messages=messages,
|
| 140 |
max_tokens=tokens_for_response,
|
|
@@ -144,6 +146,6 @@ Your review:"""
|
|
| 144 |
logging.info("Received response from OpenAI API")
|
| 145 |
|
| 146 |
# Get the assistant's response from the API response
|
| 147 |
-
assistant_response = response.choices[0].message
|
| 148 |
|
| 149 |
return assistant_response.strip()
|
|
|
|
| 1 |
import logging
|
| 2 |
from textwrap import dedent
|
| 3 |
from typing import Iterable
|
| 4 |
+
import os
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
from openai import OpenAI
|
| 7 |
import streamlit as st
|
| 8 |
import tiktoken
|
| 9 |
|
| 10 |
+
load_dotenv()
|
| 11 |
+
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
|
| 12 |
def analyze_code_files(code_files: list[str]) -> Iterable[dict[str, str]]:
|
| 13 |
"""Analyze the selected code files and return recommendations."""
|
| 14 |
return (analyze_code_file(code_file) for code_file in code_files)
|
|
|
|
| 136 |
|
| 137 |
logging.info("Sending request to OpenAI API for code analysis")
|
| 138 |
logging.info("Max response tokens: %d", tokens_for_response)
|
| 139 |
+
response = client.chat.completions.create(
|
| 140 |
model="gpt-3.5-turbo",
|
| 141 |
messages=messages,
|
| 142 |
max_tokens=tokens_for_response,
|
|
|
|
| 146 |
logging.info("Received response from OpenAI API")
|
| 147 |
|
| 148 |
# Get the assistant's response from the API response
|
| 149 |
+
assistant_response = response.choices[0].message.content
|
| 150 |
|
| 151 |
return assistant_response.strip()
|