Cristobal299 commited on
Commit
2456d59
·
verified ·
1 Parent(s): 2402a9c

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -6,17 +6,17 @@ from starlette.exceptions import StarletteDeprecationWarning
6
  warnings.filterwarnings("ignore", category=StarletteDeprecationWarning)
7
  import asyncio
8
  asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
9
- import openai
10
 
11
- # Load OpenAI API key from environment
12
- openai_api_key = os.getenv("OPENAI_API_KEY")
13
- if not openai_api_key:
14
- openai_api_key = ""
15
- openai.api_key = openai_api_key
16
 
17
  def improve_code(user_code, language):
18
  """
19
- Sends the user code to OpenAI GPT model and asks for an improved version.
20
  """
21
  system_prompt = f"You are an expert {language} developer. Refactor and improve the following code. Keep the same functionality but make it cleaner, more efficient and well commented."
22
  messages = [
@@ -24,8 +24,8 @@ def improve_code(user_code, language):
24
  {"role": "user", "content": user_code}
25
  ]
26
  try:
27
- response = openai.ChatCompletion.create(
28
- model="gpt-3.5-turbo",
29
  messages=messages,
30
  temperature=0.2,
31
  max_tokens=1024,
 
6
  warnings.filterwarnings("ignore", category=StarletteDeprecationWarning)
7
  import asyncio
8
  asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
9
+ import groq
10
 
11
+ # Load Groq API key from environment
12
+ groq_api_key = os.getenv("GROQ_API_KEY")
13
+ if not groq_api_key:
14
+ groq_api_key = ""
15
+ groq.api_key = groq_api_key
16
 
17
  def improve_code(user_code, language):
18
  """
19
+ Sends the user code to Groq model and asks for an improved version.
20
  """
21
  system_prompt = f"You are an expert {language} developer. Refactor and improve the following code. Keep the same functionality but make it cleaner, more efficient and well commented."
22
  messages = [
 
24
  {"role": "user", "content": user_code}
25
  ]
26
  try:
27
+ response = groq.ChatCompletion.create(
28
+ model="mixtral-8x7b-32768",
29
  messages=messages,
30
  temperature=0.2,
31
  max_tokens=1024,