Spaces:
Runtime error
Runtime error
DSXiangLi
commited on
Commit
•
13d0afb
1
Parent(s):
faf58a4
- ape/llm.py +2 -1
- app.py +12 -12
ape/llm.py
CHANGED
@@ -12,6 +12,7 @@ from langchain.prompts.chat import (
|
|
12 |
from langchain.prompts import PromptTemplate
|
13 |
from langchain.chains.llm import LLMChain
|
14 |
|
|
|
15 |
Cost = {
|
16 |
'davinci': 0.02,
|
17 |
'chatgpt': 0.004
|
@@ -23,7 +24,7 @@ class LLMGPT(object):
|
|
23 |
|
24 |
def __init__(self, openai_key):
|
25 |
self.gen_llm = ChatOpenAI(openai_api_key=openai_key, max_tokens=2000, temperature=0.7, verbose=True)
|
26 |
-
self.eval_llm = OpenAI(openai_api_key=openai_key, max_tokens=2000, temperature=0.7, logprobs=
|
27 |
self.test_llm = OpenAI(openai_api_key=openai_key, max_tokens=2000, temperature=0.7, verbose=True)
|
28 |
self.gen_chain = None
|
29 |
self.eval_chain = None
|
|
|
12 |
from langchain.prompts import PromptTemplate
|
13 |
from langchain.chains.llm import LLMChain
|
14 |
|
15 |
+
#默认使用davinci-003来测试和评估(可控性高),使用ChatGPT生成指令(便宜)
|
16 |
Cost = {
|
17 |
'davinci': 0.02,
|
18 |
'chatgpt': 0.004
|
|
|
24 |
|
25 |
def __init__(self, openai_key):
|
26 |
self.gen_llm = ChatOpenAI(openai_api_key=openai_key, max_tokens=2000, temperature=0.7, verbose=True)
|
27 |
+
self.eval_llm = OpenAI(openai_api_key=openai_key, max_tokens=2000, temperature=0.7, logprobs=2, verbose=True)
|
28 |
self.test_llm = OpenAI(openai_api_key=openai_key, max_tokens=2000, temperature=0.7, verbose=True)
|
29 |
self.gen_chain = None
|
30 |
self.eval_chain = None
|
app.py
CHANGED
@@ -10,19 +10,19 @@ with gr.Blocks(title="Automatic Prompt Engineer", theme=gr.themes.Glass()) as de
|
|
10 |
gr.Markdown("# Automatic Prompt Engineer")
|
11 |
with gr.Row():
|
12 |
with gr.Column(scale=2):
|
13 |
-
gr.Markdown("##
|
14 |
with gr.Row():
|
15 |
openai_key = gr.Textbox(type='password', label='输入 API key')
|
16 |
with gr.Row():
|
17 |
-
n_train = gr.Slider(label="
|
18 |
-
n_few_shot = gr.Slider(label="
|
19 |
|
20 |
with gr.Row():
|
21 |
-
n_eval = gr.Slider(label="
|
22 |
|
23 |
with gr.Column(scale=3):
|
24 |
-
gr.Markdown("##
|
25 |
-
with gr.Tab("
|
26 |
with gr.Row():
|
27 |
file = gr.File(label='上传txt文件,input\toutput\n', file_types=['txt'])
|
28 |
with gr.Row():
|
@@ -34,14 +34,14 @@ with gr.Blocks(title="Automatic Prompt Engineer", theme=gr.themes.Glass()) as de
|
|
34 |
sample_button = gr.Button('sample Data')
|
35 |
sample_flag = gr.Textbox()
|
36 |
|
37 |
-
with gr.Tab("
|
38 |
with gr.Row():
|
39 |
train_str = gr.Textbox(max_lines=100, lines=10, label="Data for prompt generation")
|
40 |
eval_str = gr.Textbox(max_lines=100, lines=10, label="Data for scoring")
|
41 |
|
42 |
with gr.Row():
|
43 |
with gr.Column(scale=2):
|
44 |
-
gr.Markdown("## Run APE:
|
45 |
gen_prompt = gr.Textbox(max_lines=100, lines=3, interative=True,
|
46 |
placeholder=MyTemplate['gen_user_prompt'],
|
47 |
value='', label="Prompt for generation")
|
@@ -60,13 +60,13 @@ with gr.Blocks(title="Automatic Prompt Engineer", theme=gr.themes.Glass()) as de
|
|
60 |
eval_button = gr.Button("Eval")
|
61 |
|
62 |
with gr.Column(scale=3):
|
63 |
-
gr.Markdown("##
|
64 |
-
with gr.Tab("
|
65 |
all_prompt = gr.Textbox(label='Generated Prompt')
|
66 |
# Display all generated prompt with log probs
|
67 |
output_df = gr.DataFrame(type='pandas', headers=['Prompt', 'Likelihood'], wrap=True, interactive=False)
|
68 |
|
69 |
-
with gr.Tab("
|
70 |
# Test the output of LLM using prompt
|
71 |
with gr.Row():
|
72 |
with gr.Column(scale=1):
|
@@ -76,7 +76,7 @@ with gr.Blocks(title="Automatic Prompt Engineer", theme=gr.themes.Glass()) as de
|
|
76 |
with gr.Column(scale=1):
|
77 |
test_output = gr.Textbox(lines=9, value="", label="Model Output")
|
78 |
|
79 |
-
with gr.Tab("
|
80 |
# By Default use the Evaluation Set in APE
|
81 |
with gr.Row():
|
82 |
with gr.Column(scale=1):
|
|
|
10 |
gr.Markdown("# Automatic Prompt Engineer")
|
11 |
with gr.Row():
|
12 |
with gr.Column(scale=2):
|
13 |
+
gr.Markdown("## 第一步:输入参数")
|
14 |
with gr.Row():
|
15 |
openai_key = gr.Textbox(type='password', label='输入 API key')
|
16 |
with gr.Row():
|
17 |
+
n_train = gr.Slider(label="训练样本数", minimum=1, maximum=20, step=1, value=5)
|
18 |
+
n_few_shot = gr.Slider(label="每组几个样例", minimum=1, maximum=20, step=1, value=5)
|
19 |
|
20 |
with gr.Row():
|
21 |
+
n_eval = gr.Slider(label="评估样本数", minimum=1, maximum=30, step=5, value=20)
|
22 |
|
23 |
with gr.Column(scale=3):
|
24 |
+
gr.Markdown("## 第二步加载数据")
|
25 |
+
with gr.Tab("选择数据"):
|
26 |
with gr.Row():
|
27 |
file = gr.File(label='上传txt文件,input\toutput\n', file_types=['txt'])
|
28 |
with gr.Row():
|
|
|
34 |
sample_button = gr.Button('sample Data')
|
35 |
sample_flag = gr.Textbox()
|
36 |
|
37 |
+
with gr.Tab("展示数据"):
|
38 |
with gr.Row():
|
39 |
train_str = gr.Textbox(max_lines=100, lines=10, label="Data for prompt generation")
|
40 |
eval_str = gr.Textbox(max_lines=100, lines=10, label="Data for scoring")
|
41 |
|
42 |
with gr.Row():
|
43 |
with gr.Column(scale=2):
|
44 |
+
gr.Markdown("## Run APE: 可以替换以下默认指令")
|
45 |
gen_prompt = gr.Textbox(max_lines=100, lines=3, interative=True,
|
46 |
placeholder=MyTemplate['gen_user_prompt'],
|
47 |
value='', label="Prompt for generation")
|
|
|
60 |
eval_button = gr.Button("Eval")
|
61 |
|
62 |
with gr.Column(scale=3):
|
63 |
+
gr.Markdown("## APE 结果")
|
64 |
+
with gr.Tab("生成指令"):
|
65 |
all_prompt = gr.Textbox(label='Generated Prompt')
|
66 |
# Display all generated prompt with log probs
|
67 |
output_df = gr.DataFrame(type='pandas', headers=['Prompt', 'Likelihood'], wrap=True, interactive=False)
|
68 |
|
69 |
+
with gr.Tab("指令单测"):
|
70 |
# Test the output of LLM using prompt
|
71 |
with gr.Row():
|
72 |
with gr.Column(scale=1):
|
|
|
76 |
with gr.Column(scale=1):
|
77 |
test_output = gr.Textbox(lines=9, value="", label="Model Output")
|
78 |
|
79 |
+
with gr.Tab("指令评估"):
|
80 |
# By Default use the Evaluation Set in APE
|
81 |
with gr.Row():
|
82 |
with gr.Column(scale=1):
|