dhuynh95 commited on
Commit
14e166f
1 Parent(s): f29565b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -21
app.py CHANGED
@@ -8,6 +8,7 @@ import requests
8
  import ast
9
 
10
 
 
11
  api_base = "https://api.endpoints.anyscale.com/v1"
12
  token = os.environ["OPENAI_API_KEY"]
13
  url = f"{api_base}/chat/completions"
@@ -54,7 +55,7 @@ def remove_leading_whitespace(func_str):
54
  return "\n".join(new_lines)
55
 
56
 
57
- def main(fxn: str, examples: str = "", temperature: float = 0.7):
58
  """Requires Anyscale Endpoints Alpha API access.
59
 
60
  If examples is not a empty string, it will be formatted into
@@ -63,7 +64,7 @@ def main(fxn: str, examples: str = "", temperature: float = 0.7):
63
 
64
  s = requests.Session()
65
  api_base = os.environ["OPENAI_API_BASE"]
66
- token = os.environ["OPENAI_API_KEY"]
67
  url = f"{api_base}/chat/completions"
68
 
69
  message = "Write me a test of this function\n{}".format(fxn)
@@ -234,30 +235,18 @@ def is_semipositive_definite(matrix):
234
 
235
  # Check if all eigenvalues are non-negative
236
  return all(val >= 0 for val in eigenvalues)
237
- """,
238
- """
239
- def key_exists(data, key_to_find):
240
- # Base case: If data is not a dictionary, return False
241
- if not isinstance(data, dict):
242
- return False
243
-
244
- # If the key is in the dictionary, return True
245
- if key_to_find in data:
246
- return True
247
-
248
- # Otherwise, recurse into each nested dictionary
249
- for key, value in data.items():
250
- if key_exists(value, key_to_find):
251
- return True
252
-
253
- # If the key was not found in this dictionary or any sub-dictionary, return False
254
- return False
255
  """
256
  ]
257
  example = examples[0]
258
 
259
  with gr.Blocks() as demo:
260
  gr.Markdown("<h1><center>Llama_test: generate unit test for your Python code</center></h1>")
 
 
 
 
 
 
261
  code_input = gr.Code(example, language="python", label="Provide the code of the function you want to test")
262
  gr.Examples(
263
  examples=examples,
@@ -268,6 +257,6 @@ with gr.Blocks() as demo:
268
  code_output = gr.Code(language="python", label="Passed tests")
269
  code_output2 = gr.Code(language="python", label="Failed tests")
270
 
271
- generate_btn.click(main, inputs=code_input, outputs=[code_output, code_output2])
272
  if __name__ == "__main__":
273
  demo.launch()
 
8
  import ast
9
 
10
 
11
+
12
  api_base = "https://api.endpoints.anyscale.com/v1"
13
  token = os.environ["OPENAI_API_KEY"]
14
  url = f"{api_base}/chat/completions"
 
55
  return "\n".join(new_lines)
56
 
57
 
58
+ def main(fxn: str, openai_api_key, examples: str = "", temperature: float = 0.7):
59
  """Requires Anyscale Endpoints Alpha API access.
60
 
61
  If examples is not a empty string, it will be formatted into
 
64
 
65
  s = requests.Session()
66
  api_base = os.environ["OPENAI_API_BASE"]
67
+ token = openai_api_key
68
  url = f"{api_base}/chat/completions"
69
 
70
  message = "Write me a test of this function\n{}".format(fxn)
 
235
 
236
  # Check if all eigenvalues are non-negative
237
  return all(val >= 0 for val in eigenvalues)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  """
239
  ]
240
  example = examples[0]
241
 
242
  with gr.Blocks() as demo:
243
  gr.Markdown("<h1><center>Llama_test: generate unit test for your Python code</center></h1>")
244
+ openai_api_key = gr.Textbox(
245
+ show_label=False,
246
+ label="Set your Anyscale API key here.",
247
+ lines=1,
248
+ type="password"
249
+ )
250
  code_input = gr.Code(example, language="python", label="Provide the code of the function you want to test")
251
  gr.Examples(
252
  examples=examples,
 
257
  code_output = gr.Code(language="python", label="Passed tests")
258
  code_output2 = gr.Code(language="python", label="Failed tests")
259
 
260
+ generate_btn.click(main, inputs=[code_input, openai_api_key], outputs=[code_output, code_output2])
261
  if __name__ == "__main__":
262
  demo.launch()