posix4e commited on
Commit
ade1378
·
1 Parent(s): 9ed685d

add doctests

Browse files
.github/workflows/backend_ci.yml CHANGED
@@ -19,5 +19,7 @@ jobs:
19
  cache: 'pip'
20
  - name: pip Install
21
  run: pip install -r requirements.txt
22
- - name: Test
 
 
23
  run: pytest
 
19
  cache: 'pip'
20
  - name: pip Install
21
  run: pip install -r requirements.txt
22
+ - name: UnitTests
23
+ run: python -m doctest -v backend.py
24
+ - name: EndToEnd Test
25
  run: pytest
backend/backend.py CHANGED
@@ -228,7 +228,7 @@ def assist_interface(uid, prompt, gpt_version):
228
  "/assist",
229
  json={"uid": uid, "prompt": prompt, "version": gpt_version},
230
  )
231
- return display_json(response.text)
232
 
233
 
234
  def get_user_interface(uid):
@@ -248,7 +248,15 @@ class HighlightRenderer(mistune.HTMLRenderer):
248
  return "<pre><code>" + mistune.escape(code) + "</code></pre>"
249
 
250
 
251
- def display_json(data):
 
 
 
 
 
 
 
 
252
  html_output = "<html>"
253
  json_data = json.loads(data)
254
 
@@ -270,27 +278,21 @@ def display_json(data):
270
  html_output += f"<p>Text: {text}</p>"
271
  elif "gpt" in model:
272
  for choice in choices:
273
- try:
274
- markdown = mistune.create_markdown(renderer=HighlightRenderer())
275
- text = markdown(choice["message"]["content"])
276
- html_output += f"<p>Text: {text}</p>"
277
- except:
278
- markdown = mistune.create_markdown()
279
- text = markdown(choice["message"]["content"])
280
- html_output += f"<p>Text: {text}</p>"
281
-
282
  html_output += "</html>"
283
  return html_output
284
 
285
 
286
  def get_assist_interface():
287
- gpt_version_dropdown = gr.inputs.Dropdown(label="GPT Version", choices=LANGS)
288
 
289
  return gr.Interface(
290
  fn=assist_interface,
291
  inputs=[
292
- gr.inputs.Textbox(label="UID", type="text"),
293
- gr.inputs.Textbox(label="Prompt", type="text"),
294
  gpt_version_dropdown,
295
  ],
296
  outputs="html",
@@ -321,7 +323,7 @@ def register_interface(openai_key):
321
  def get_register_interface():
322
  return gr.Interface(
323
  fn=register_interface,
324
- inputs=[gr.inputs.Textbox(label="OpenAI Key", type="text")],
325
  outputs="json",
326
  title="Register New User",
327
  description="Register a new user by entering an OpenAI key.",
@@ -337,7 +339,7 @@ def get_history_interface(uid):
337
  def get_history_gradio_interface():
338
  return gr.Interface(
339
  fn=get_history_interface,
340
- inputs=[gr.inputs.Textbox(label="UID", type="text")],
341
  outputs="json",
342
  title="Get User History",
343
  description="Get the history of questions and answers for a given user.",
@@ -357,8 +359,8 @@ def get_add_command_interface():
357
  return gr.Interface(
358
  fn=add_command_interface,
359
  inputs=[
360
- gr.inputs.Textbox(label="UID", type="text"),
361
- gr.inputs.Textbox(label="Command", type="text"),
362
  ],
363
  outputs="json",
364
  title="Add Command",
 
228
  "/assist",
229
  json={"uid": uid, "prompt": prompt, "version": gpt_version},
230
  )
231
+ return gradio_user_output_helper(response.text)
232
 
233
 
234
  def get_user_interface(uid):
 
248
  return "<pre><code>" + mistune.escape(code) + "</code></pre>"
249
 
250
 
251
+ def gradio_user_output_helper(data):
252
+ r"""
253
+ This is used by the gradio to extract all of the user
254
+ data and write it out as a giant json blob that can be easily diplayed.
255
+ >>> choices = [{'message': {'content': 'This is a test'}}]
256
+ >>> data = { 'id': '1', 'object': 'user', 'created': '2021-09-01', 'model': 'gpt-3', 'choices': choices}
257
+ >>> gradio_user_output_helper(json.dumps(data))
258
+ '<html><h2>ID: 1</h2><p>Object: user</p><p>Created: 2021-09-01</p><p>Model: gpt-3</p><h3>Choices:</h3><p>Text: <p>This is a test</p>\n</p></html>'
259
+ """
260
  html_output = "<html>"
261
  json_data = json.loads(data)
262
 
 
278
  html_output += f"<p>Text: {text}</p>"
279
  elif "gpt" in model:
280
  for choice in choices:
281
+ markdown = mistune.create_markdown(renderer=HighlightRenderer())
282
+ text = markdown(choice["message"]["content"])
283
+ html_output += f"<p>Text: {text}</p>"
 
 
 
 
 
 
284
  html_output += "</html>"
285
  return html_output
286
 
287
 
288
  def get_assist_interface():
289
+ gpt_version_dropdown = gr.components.Dropdown(label="GPT Version", choices=LANGS)
290
 
291
  return gr.Interface(
292
  fn=assist_interface,
293
  inputs=[
294
+ gr.components.Textbox(label="UID", type="text"),
295
+ gr.components.Textbox(label="Prompt", type="text"),
296
  gpt_version_dropdown,
297
  ],
298
  outputs="html",
 
323
  def get_register_interface():
324
  return gr.Interface(
325
  fn=register_interface,
326
+ inputs=[gr.components.Textbox(label="OpenAI Key", type="text")],
327
  outputs="json",
328
  title="Register New User",
329
  description="Register a new user by entering an OpenAI key.",
 
339
  def get_history_gradio_interface():
340
  return gr.Interface(
341
  fn=get_history_interface,
342
+ inputs=[gr.components.Textbox(label="UID", type="text")],
343
  outputs="json",
344
  title="Get User History",
345
  description="Get the history of questions and answers for a given user.",
 
359
  return gr.Interface(
360
  fn=add_command_interface,
361
  inputs=[
362
+ gr.components.Textbox(label="UID", type="text"),
363
+ gr.components.Textbox(label="Command", type="text"),
364
  ],
365
  outputs="json",
366
  title="Add Command",
puppet/app/build.gradle CHANGED
@@ -6,7 +6,7 @@ plugins {
6
 
7
  android {
8
  namespace 'com.ttt246.puppet'
9
- compileSdkVersion 34
10
  kotlinOptions {
11
  jvmTarget = "1.8"
12
  }
 
6
 
7
  android {
8
  namespace 'com.ttt246.puppet'
9
+ compileSdkVersion 33
10
  kotlinOptions {
11
  jvmTarget = "1.8"
12
  }