Tonic commited on
Commit
5fe0459
1 Parent(s): 5d0a43b

Update maker.py

Browse files
Files changed (1) hide show
  1. maker.py +22 -24
maker.py CHANGED
@@ -74,32 +74,30 @@ def predict_beta(message, chatbot=[], system_prompt=system_prompt, max_new_token
74
  error_msg = f"An error occurred: {str(e)}"
75
  raise gr.Error(error_msg)
76
 
77
-
78
  def extract_title_prompt_example(text, title, system_prompt, example_input):
79
  try:
80
- # Finding the indices of the key terms
81
- text_start = text.rfind("<|assistant|>", ) + len("<|assistant|>")
82
- text = text[text_start:]
83
- except ValueError:
84
- pass
85
- try:
86
- title_start = text.lower().rfind("title:") + len("title:")
87
- prompt_start = text.lower().rfind("system prompt:")
88
- title = text[title_start:prompt_start].strip()
89
- except ValueError:
90
- pass
91
- try:
92
- prompt_start = text.lower().rfind("system prompt:") + len("system prompt:")
93
- example_start = text.lower().rfind("example input:")
94
- system_prompt = text[prompt_start:example_start].strip()
95
- except ValueError:
96
- pass
97
- try:
98
- example_start = text.lower().rfind("example input:") + len("example input:")
99
- example_input = text[example_start:].strip()
100
- example_input = example_input[:example_input.index("\n")]
101
- except ValueError:
102
- pass
103
  return text, title, system_prompt, example_input
104
 
105
  def make_open_gpt(message, history, current_title, system_prompt, current_example_input):
 
74
  error_msg = f"An error occurred: {str(e)}"
75
  raise gr.Error(error_msg)
76
 
 
77
  def extract_title_prompt_example(text, title, system_prompt, example_input):
78
  try:
79
+ title_start = text.lower().find("title:") + len("title:")
80
+ if title_start >= len("title:"):
81
+ prompt_start = text.lower().find("system prompt:", title_start)
82
+ title = text[title_start:prompt_start].strip() if prompt_start != -1 else ""
83
+ else:
84
+ title = ""
85
+
86
+ if prompt_start >= 0:
87
+ example_start = text.lower().find("example input:", prompt_start)
88
+ system_prompt = text[prompt_start + len("system prompt:"):example_start].strip() if example_start != -1 else ""
89
+ else:
90
+ system_prompt = ""
91
+
92
+ if example_start >= 0:
93
+ example_input = text[example_start + len("example input:"):].strip().split("\n")[0]
94
+ else:
95
+ example_input = ""
96
+ except Exception as e:
97
+ print(f"Error in extract_title_prompt_example: {e}")
98
+ # Return the original values if there's an error
99
+ return text, title, system_prompt, example_input
100
+
 
101
  return text, title, system_prompt, example_input
102
 
103
  def make_open_gpt(message, history, current_title, system_prompt, current_example_input):