yaleh commited on
Commit
115910a
·
1 Parent(s): 48833bc

chore: Update config files with new options. Enabled `Flag as Example`.

Browse files
Files changed (4) hide show
  1. app/config.py +2 -1
  2. app/examples/log.csv +10 -9
  3. app/gradio_meta_prompt.py +87 -16
  4. config.yml +2 -1
app/config.py CHANGED
@@ -15,4 +15,5 @@ class MetaPromptConfig(BaseConfig):
15
  server_name: Optional[str] = None
16
  server_port: Optional[int] = None
17
  recursion_limit: Optional[int] = 25
18
- recursion_limit_max: Optional[int] = 50
 
 
15
  server_name: Optional[str] = None
16
  server_port: Optional[int] = None
17
  recursion_limit: Optional[int] = 25
18
+ recursion_limit_max: Optional[int] = 50
19
+ allow_flagging: Optional[bool] = False
app/examples/log.csv CHANGED
@@ -1,5 +1,5 @@
1
- User Message,Expected Output,Acceptance Criteria
2
- How do I reverse a list in Python?,Use the `[::-1]` slicing technique or the `list.reverse()` method.,"Similar in meaning, text length and style."
3
  (2+8)*3,"(2+8)*3
4
  = 10*3
5
  = 30
@@ -8,7 +8,7 @@ How do I reverse a list in Python?,Use the `[::-1]` slicing technique or the `li
8
  * Acceptable differences:
9
  * Extra or missing spaces.
10
  * Extra or missing line breaks at the beginning or end of the output.
11
- "
12
  "Here is the GDP data in billions of US dollars (USD) for these years:
13
 
14
  Germany:
@@ -57,7 +57,7 @@ Spain:
57
  * Differences in digital/percentage values in the table, even significant ones.
58
  * Extra or missing spaces.
59
  * Extra or missing line breaks.
60
- "
61
  "Gene sequence: ATGGCCATGGCGCCCAGAACTGAGATCAATAGTACCCGTATTAACGGGTGA
62
  Species: Escherichia coli","{
63
  ""Gene Sequence Analysis Results"": {
@@ -125,7 +125,7 @@ Species: Escherichia coli","{
125
  * Extra or missing spaces
126
  * Extra or missing line breaks at the beginning or end of the output
127
  * Differences in JSON field values
128
- * JSON wrapped in backquotes"
129
  今天下午3点,在北京国家会议中心,阿里巴巴集团董事局主席马云宣布将投资100亿元人民币用于农村电商发展。这一决定受到了与会代表的热烈欢迎,大家认为这将为中国农村经济带来新的机遇。,"{
130
  ""文本分析结果"": {
131
  ""情感分析"": {
@@ -164,7 +164,7 @@ Species: Escherichia coli","{
164
  * Extra or missing line breaks at the beginning or end of the output.
165
  * Differences in JSON field values
166
  * Differences in section/item orders.
167
- * JSON wrapped in backquotes."
168
  Low-noise amplifier,"A '''low-noise amplifier''' ('''LNA''') is an electronic component that amplifies a very low-power [[signal]] without significantly degrading its [[signal-to-noise ratio]] (SNR). Any [[electronic amplifier]] will increase the power of both the signal and the [[Noise (electronics)|noise]] present at its input, but the amplifier will also introduce some additional noise. LNAs are designed to minimize that additional noise, by choosing special components, operating points, and [[Circuit topology (electrical)|circuit topologies]]. Minimizing additional noise must balance with other design goals such as [[power gain]] and [[impedance matching]].
169
 
170
  LNAs are found in [[Radio|radio communications]] systems, [[Amateur Radio]] stations, medical instruments and [[electronic test equipment]]. A typical LNA may supply a power gain of 100 (20 [[decibels]] (dB)) while decreasing the SNR by less than a factor of two (a 3 dB [[noise figure]] (NF)). Although LNAs are primarily concerned with weak signals that are just above the [[noise floor]], they must also consider the presence of larger signals that cause [[intermodulation distortion]].","* Consistent with Expected Output:
@@ -178,7 +178,7 @@ LNAs are found in [[Radio|radio communications]] systems, [[Amateur Radio]] stat
178
  * Expression differences.
179
  * Numerical differences.
180
  * Additional content in Actual Output.
181
- * Missing minor content in Actual Output."
182
  What is the meaning of life?,"[
183
  {""persona"": ""Philosopher"", ""prompt"": ""Explore the concept of life's meaning through the lens of existentialism and purpose-driven existence.""},
184
  {""persona"": ""Scientist"", ""prompt"": ""Examine the biological and evolutionary perspectives on the function and significance of life.""},
@@ -193,7 +193,7 @@ What is the meaning of life?,"[
193
  * Extra or missing spaces
194
  * Extra or missing line breaks at the beginning or end of the output
195
  * Unacceptable:
196
- * Showing the personas in Expected Output in System Message"
197
  "<?php
198
  $username = $_POST['username'];
199
  $password = $_POST['password'];
@@ -233,4 +233,5 @@ if (mysqli_num_rows($result) > 0) {
233
  * Differences in field values
234
  * Extra or missing spaces
235
  * Extra or missing line breaks at the beginning or end of the output
236
- * YAML wrapped in backquotes"
 
 
1
+ User Message,Expected Output,Acceptance Criteria,Initial System Message
2
+ How do I reverse a list in Python?,Use the `[::-1]` slicing technique or the `list.reverse()` method.,"Similar in meaning, text length and style.",""
3
  (2+8)*3,"(2+8)*3
4
  = 10*3
5
  = 30
 
8
  * Acceptable differences:
9
  * Extra or missing spaces.
10
  * Extra or missing line breaks at the beginning or end of the output.
11
+ ",""
12
  "Here is the GDP data in billions of US dollars (USD) for these years:
13
 
14
  Germany:
 
57
  * Differences in digital/percentage values in the table, even significant ones.
58
  * Extra or missing spaces.
59
  * Extra or missing line breaks.
60
+ ",""
61
  "Gene sequence: ATGGCCATGGCGCCCAGAACTGAGATCAATAGTACCCGTATTAACGGGTGA
62
  Species: Escherichia coli","{
63
  ""Gene Sequence Analysis Results"": {
 
125
  * Extra or missing spaces
126
  * Extra or missing line breaks at the beginning or end of the output
127
  * Differences in JSON field values
128
+ * JSON wrapped in backquotes",""
129
  今天下午3点,在北京国家会议中心,阿里巴巴集团董事局主席马云宣布将投资100亿元人民币用于农村电商发展。这一决定受到了与会代表的热烈欢迎,大家认为这将为中国农村经济带来新的机遇。,"{
130
  ""文本分析结果"": {
131
  ""情感分析"": {
 
164
  * Extra or missing line breaks at the beginning or end of the output.
165
  * Differences in JSON field values
166
  * Differences in section/item orders.
167
+ * JSON wrapped in backquotes.",""
168
  Low-noise amplifier,"A '''low-noise amplifier''' ('''LNA''') is an electronic component that amplifies a very low-power [[signal]] without significantly degrading its [[signal-to-noise ratio]] (SNR). Any [[electronic amplifier]] will increase the power of both the signal and the [[Noise (electronics)|noise]] present at its input, but the amplifier will also introduce some additional noise. LNAs are designed to minimize that additional noise, by choosing special components, operating points, and [[Circuit topology (electrical)|circuit topologies]]. Minimizing additional noise must balance with other design goals such as [[power gain]] and [[impedance matching]].
169
 
170
  LNAs are found in [[Radio|radio communications]] systems, [[Amateur Radio]] stations, medical instruments and [[electronic test equipment]]. A typical LNA may supply a power gain of 100 (20&nbsp;[[decibels]] (dB)) while decreasing the SNR by less than a factor of two (a 3&nbsp;dB [[noise figure]] (NF)). Although LNAs are primarily concerned with weak signals that are just above the [[noise floor]], they must also consider the presence of larger signals that cause [[intermodulation distortion]].","* Consistent with Expected Output:
 
178
  * Expression differences.
179
  * Numerical differences.
180
  * Additional content in Actual Output.
181
+ * Missing minor content in Actual Output.",""
182
  What is the meaning of life?,"[
183
  {""persona"": ""Philosopher"", ""prompt"": ""Explore the concept of life's meaning through the lens of existentialism and purpose-driven existence.""},
184
  {""persona"": ""Scientist"", ""prompt"": ""Examine the biological and evolutionary perspectives on the function and significance of life.""},
 
193
  * Extra or missing spaces
194
  * Extra or missing line breaks at the beginning or end of the output
195
  * Unacceptable:
196
+ * Showing the personas in Expected Output in System Message",""
197
  "<?php
198
  $username = $_POST['username'];
199
  $password = $_POST['password'];
 
233
  * Differences in field values
234
  * Extra or missing spaces
235
  * Extra or missing line breaks at the beginning or end of the output
236
+ * YAML wrapped in backquotes",""
237
+ “老爸,老爸,我们去哪里呀?”,《爸爸去哪儿》,Exactly text match.,"查询歌词出处。"
app/gradio_meta_prompt.py CHANGED
@@ -1,9 +1,63 @@
 
 
 
1
  import gradio as gr
 
 
2
  from confz import BaseConfig, CLArgSource, EnvSource, FileSource
3
  from meta_prompt import MetaPromptGraph, AgentState
4
  from langchain_openai import ChatOpenAI
5
  from app.config import MetaPromptConfig
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  class LLMModelFactory:
8
  def __init__(self):
9
  pass
@@ -71,34 +125,51 @@ config_sources = [
71
  config = MetaPromptConfig(config_sources=config_sources)
72
 
73
  # Create the Gradio interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  iface = gr.Interface(
75
  fn=process_message,
76
  inputs=[
77
- gr.Textbox(label="User Message", show_copy_button=True),
78
- gr.Textbox(label="Expected Output", show_copy_button=True),
79
- gr.Textbox(label="Acceptance Criteria", show_copy_button=True),
80
  ],
81
  outputs=[
82
- gr.Textbox(label="System Message", show_copy_button=True),
83
- gr.Textbox(label="Output", show_copy_button=True),
84
- gr.Textbox(label="Analysis", show_copy_button=True)
85
  ],
86
  additional_inputs=[
87
- gr.Textbox(label="Initial System Message", show_copy_button=True, value=""),
88
- gr.Number(label="Recursion Limit", value=config.recursion_limit,
89
- precision=0, minimum=1, maximum=config.recursion_limit_max, step=1),
90
- gr.Dropdown(
91
- label="Model Name",
92
- choices=config.llms.keys(),
93
- value=list(config.llms.keys())[0],
94
- )
95
  ],
96
- # stop_btn = gr.Button("Stop", variant="stop", visible=True),
97
  title="MetaPromptGraph Chat Interface",
98
  description="A chat interface for MetaPromptGraph to process user inputs and generate system messages.",
99
  examples=config.examples_path,
100
- allow_flagging="never"
 
 
 
101
  )
 
102
 
103
  # Launch the Gradio app
104
  iface.launch(server_name=config.server_name, server_port=config.server_port)
 
1
+ import csv
2
+ from pathlib import Path
3
+ from typing import Any
4
  import gradio as gr
5
+ from gradio import CSVLogger, utils
6
+ from gradio_client import utils as client_utils
7
  from confz import BaseConfig, CLArgSource, EnvSource, FileSource
8
  from meta_prompt import MetaPromptGraph, AgentState
9
  from langchain_openai import ChatOpenAI
10
  from app.config import MetaPromptConfig
11
 
12
+ class SimplifiedCSVLogger(CSVLogger):
13
+ """
14
+ A subclass of CSVLogger that logs only the components data to a CSV file, excluding
15
+ flag, username, and timestamp information.
16
+ """
17
+
18
+ def flag(
19
+ self,
20
+ flag_data: list[Any],
21
+ flag_option: str = "",
22
+ username: str | None = None,
23
+ ) -> int:
24
+ flagging_dir = self.flagging_dir
25
+ log_filepath = Path(flagging_dir) / "log.csv"
26
+ is_new = not Path(log_filepath).exists()
27
+ headers = [
28
+ getattr(component, "label", None) or f"component {idx}"
29
+ for idx, component in enumerate(self.components)
30
+ ]
31
+
32
+ csv_data = []
33
+ for idx, (component, sample) in enumerate(zip(self.components, flag_data)):
34
+ save_dir = Path(
35
+ flagging_dir
36
+ ) / client_utils.strip_invalid_filename_characters(
37
+ getattr(component, "label", None) or f"component {idx}"
38
+ )
39
+ if utils.is_prop_update(sample):
40
+ csv_data.append(str(sample))
41
+ else:
42
+ data = (
43
+ component.flag(sample, flag_dir=save_dir)
44
+ if sample is not None
45
+ else ""
46
+ )
47
+ if self.simplify_file_data:
48
+ data = utils.simplify_file_data_in_str(data)
49
+ csv_data.append(data)
50
+
51
+ with open(log_filepath, "a", newline="", encoding="utf-8") as csvfile:
52
+ writer = csv.writer(csvfile)
53
+ if is_new:
54
+ writer.writerow(utils.sanitize_list_for_csv(headers))
55
+ writer.writerow(utils.sanitize_list_for_csv(csv_data))
56
+
57
+ with open(log_filepath, encoding="utf-8") as csvfile:
58
+ line_count = len(list(csv.reader(csvfile))) - 1
59
+ return line_count
60
+
61
  class LLMModelFactory:
62
  def __init__(self):
63
  pass
 
125
  config = MetaPromptConfig(config_sources=config_sources)
126
 
127
  # Create the Gradio interface
128
+ user_message_input = gr.Textbox(label="User Message", show_copy_button=True)
129
+ expected_output_input = gr.Textbox(label="Expected Output", show_copy_button=True)
130
+ acceptance_criteria_input = gr.Textbox(label="Acceptance Criteria", show_copy_button=True)
131
+
132
+ system_message_output = gr.Textbox(label="System Message", show_copy_button=True)
133
+ output_output = gr.Textbox(label="Output", show_copy_button=True)
134
+ analysis_output = gr.Textbox(label="Analysis", show_copy_button=True)
135
+
136
+ initial_system_message_input = gr.Textbox(label="Initial System Message", show_copy_button=True, value="")
137
+ recursion_limit_input = gr.Number(label="Recursion Limit", value=config.recursion_limit,
138
+ precision=0, minimum=1, maximum=config.recursion_limit_max, step=1)
139
+ model_name_input = gr.Dropdown(
140
+ label="Model Name",
141
+ choices=config.llms.keys(),
142
+ value=list(config.llms.keys())[0],
143
+ )
144
+
145
+ flagging_callback = SimplifiedCSVLogger()
146
+
147
  iface = gr.Interface(
148
  fn=process_message,
149
  inputs=[
150
+ user_message_input,
151
+ expected_output_input,
152
+ acceptance_criteria_input,
153
  ],
154
  outputs=[
155
+ system_message_output,
156
+ output_output,
157
+ analysis_output
158
  ],
159
  additional_inputs=[
160
+ initial_system_message_input,
161
+ recursion_limit_input,
162
+ model_name_input
 
 
 
 
 
163
  ],
 
164
  title="MetaPromptGraph Chat Interface",
165
  description="A chat interface for MetaPromptGraph to process user inputs and generate system messages.",
166
  examples=config.examples_path,
167
+ allow_flagging=config.allow_flagging,
168
+ flagging_dir=config.examples_path,
169
+ flagging_options=["Example"],
170
+ flagging_callback=flagging_callback
171
  )
172
+ flagging_callback.setup([user_message_input, expected_output_input, acceptance_criteria_input, initial_system_message_input],config.examples_path)
173
 
174
  # Launch the Gradio app
175
  iface.launch(server_name=config.server_name, server_port=config.server_port)
config.yml CHANGED
@@ -36,4 +36,5 @@ examples_path: "app/examples"
36
  server_name: 0.0.0.0
37
  # server_port: 7860
38
  recursion_limit: 16
39
- recursion_limit_max: 20
 
 
36
  server_name: 0.0.0.0
37
  # server_port: 7860
38
  recursion_limit: 16
39
+ recursion_limit_max: 20
40
+ allow_flask_cors: false