Spaces:
Runtime error
Runtime error
Commit
·
e148f2b
1
Parent(s):
e9b97c6
app create
Browse files- app.py +13 -9
- selfinstruct/instance.py +17 -0
app.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
from selfinstruct.instance import instance_main
|
| 3 |
import openai
|
| 4 |
from langchain.llms.openai import OpenAI
|
|
@@ -9,15 +11,17 @@ def OpenaiChat(key, input, temperature):
|
|
| 9 |
print(input)
|
| 10 |
openai.api_key = key
|
| 11 |
MODEL = "gpt-3.5-turbo"
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
|
| 22 |
with gr.Blocks() as demo:
|
| 23 |
gr.Markdown("# Self-instruct Prompt")
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from openai import OpenAIError
|
| 3 |
+
|
| 4 |
from selfinstruct.instance import instance_main
|
| 5 |
import openai
|
| 6 |
from langchain.llms.openai import OpenAI
|
|
|
|
| 11 |
print(input)
|
| 12 |
openai.api_key = key
|
| 13 |
MODEL = "gpt-3.5-turbo"
|
| 14 |
+
try:
|
| 15 |
+
response = openai.ChatCompletion.create(
|
| 16 |
+
model=MODEL,
|
| 17 |
+
messages=[
|
| 18 |
+
{"role": "user", "content": input}
|
| 19 |
+
],
|
| 20 |
+
temperature=temperature
|
| 21 |
+
)
|
| 22 |
+
return json.dumps(response["choices"], ensure_ascii=False)
|
| 23 |
+
except OpenAIError:
|
| 24 |
+
return "Wrong Key!"
|
| 25 |
|
| 26 |
with gr.Blocks() as demo:
|
| 27 |
gr.Markdown("# Self-instruct Prompt")
|
selfinstruct/instance.py
CHANGED
|
@@ -6,6 +6,9 @@ import re
|
|
| 6 |
import argparse
|
| 7 |
import pandas as pd
|
| 8 |
from collections import OrderedDict
|
|
|
|
|
|
|
|
|
|
| 9 |
from .gpt3_api import make_requests as make_gpt3_requests
|
| 10 |
from .templates.instance_gen_template import output_first_template_for_clf, input_first_template_for_gen
|
| 11 |
from .templates.clf_task_template import template_1
|
|
@@ -302,9 +305,23 @@ def prepare_finetune(inputs, api_key):
|
|
| 302 |
return results1, classify_res, instance_outputs, results2
|
| 303 |
|
| 304 |
def instance_main(inputs, key):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
api_key = key
|
| 306 |
inputs = inputs.split('\n')
|
| 307 |
print("***", inputs)
|
| 308 |
return prepare_finetune(inputs, api_key)
|
| 309 |
|
|
|
|
| 310 |
# instance_main()
|
|
|
|
| 6 |
import argparse
|
| 7 |
import pandas as pd
|
| 8 |
from collections import OrderedDict
|
| 9 |
+
|
| 10 |
+
from openai import OpenAIError
|
| 11 |
+
|
| 12 |
from .gpt3_api import make_requests as make_gpt3_requests
|
| 13 |
from .templates.instance_gen_template import output_first_template_for_clf, input_first_template_for_gen
|
| 14 |
from .templates.clf_task_template import template_1
|
|
|
|
| 305 |
return results1, classify_res, instance_outputs, results2
|
| 306 |
|
| 307 |
def instance_main(inputs, key):
|
| 308 |
+
try:
|
| 309 |
+
import openai
|
| 310 |
+
openai.api_key = key
|
| 311 |
+
MODEL = "gpt-3.5-turbo"
|
| 312 |
+
openai.ChatCompletion.create(
|
| 313 |
+
model=MODEL,
|
| 314 |
+
messages=[
|
| 315 |
+
{"role": "user", "content": "Hi"}
|
| 316 |
+
],
|
| 317 |
+
temperature=1
|
| 318 |
+
)
|
| 319 |
+
except OpenAIError:
|
| 320 |
+
return "Wrong Key!", " ", " ", " "
|
| 321 |
api_key = key
|
| 322 |
inputs = inputs.split('\n')
|
| 323 |
print("***", inputs)
|
| 324 |
return prepare_finetune(inputs, api_key)
|
| 325 |
|
| 326 |
+
|
| 327 |
# instance_main()
|