Tonic commited on
Commit
d91cc69
1 Parent(s): 4f438a9

Update maker.py

Browse files
Files changed (1) hide show
  1. maker.py +17 -27
maker.py CHANGED
@@ -97,31 +97,23 @@ def extract_title_prompt_example(text, title, system_prompt, example_input):
97
  prompt_start = -1
98
  example_start = -1
99
  try:
100
- title_start = text.lower().find("# Title:") + len("# Title:")
101
- if title_start >= len("# Title:"):
102
- prompt_start = text.lower().find("# System prompt:", title_start)
103
- title = text[title_start:prompt_start].strip() if prompt_start != -1 else ""
104
- print("Title:", title)
105
-
106
- else:
107
- title = ""
108
-
109
- if prompt_start >= 0:
110
- example_start = text.lower().find("# Example input:", prompt_start)
111
- system_prompt = text[prompt_start + len("# System prompt:"):example_start].strip() if example_start != -1 else ""
112
- print("System Prompt:", system_prompt)
113
- else:
114
- system_prompt = ""
115
-
116
- if example_start >= 0:
117
- example_input = text[example_start + len("Example input:"):].strip().split("\n")[0]
118
- print("Example Input:", example_input)
119
-
120
- else:
121
- example_input = ""
122
- except Exception as e:
123
- print(f"Error in extract_title_prompt_example: {e}")
124
- return text, title, system_prompt, example_input
125
  return text, title, system_prompt, example_input
126
 
127
  def make_open_gpt(message, history, current_title, system_prompt, current_example_input):
@@ -137,8 +129,6 @@ textbox_preview = gr.Textbox(scale=7, container=False)
137
 
138
  def test_preview_chatbot(message, history, system_prompt):
139
  response = predict_beta(message, history, system_prompt)
140
- text_start = response.rfind("<|assistant|>", ) + len("<|assistant|>")
141
- response = response[text_start:]
142
  return response
143
 
144
 
 
97
  prompt_start = -1
98
  example_start = -1
99
  try:
100
+ title_start = text.lower().rfind("title:") + len("title:")
101
+ prompt_start = text.lower().rfind("system prompt:")
102
+ title = text[title_start:prompt_start].strip()
103
+ except ValueError:
104
+ pass
105
+ try:
106
+ prompt_start = text.lower().rfind("system prompt:") + len("system prompt:")
107
+ example_start = text.lower().rfind("example input:")
108
+ system_prompt = text[prompt_start:example_start].strip()
109
+ except ValueError:
110
+ pass
111
+ try:
112
+ example_start = text.lower().rfind("example input:") + len("example input:")
113
+ example_input = text[example_start:].strip()
114
+ example_input = example_input[:example_input.index("\n")]
115
+ except ValueError:
116
+ pass
 
 
 
 
 
 
 
 
117
  return text, title, system_prompt, example_input
118
 
119
  def make_open_gpt(message, history, current_title, system_prompt, current_example_input):
 
129
 
130
  def test_preview_chatbot(message, history, system_prompt):
131
  response = predict_beta(message, history, system_prompt)
 
 
132
  return response
133
 
134