Tonic commited on
Commit
b8afcbf
1 Parent(s): 0e87b70

Update maker.py

Browse files
Files changed (1) hide show
  1. maker.py +25 -28
maker.py CHANGED
@@ -108,37 +108,34 @@ def extract_title_prompt_example(text):
108
  default_system_prompt = "This is a custom GPT agent."
109
  default_example_input = "Type your query here."
110
 
111
- # Find the start indices of each section
112
- title_start = text.find("# Title:")
113
- prompt_start = text.find("# System prompt:")
114
- example_start = text.find("# Example input:")
115
-
116
- # Extract Title
117
- if title_start != -1:
118
- title_start += len("# Title:")
119
- title_end = prompt_start if prompt_start != -1 else len(text)
120
- title = text[title_start:title_end].strip()
121
- else:
122
- title = default_title
123
-
124
- # Extract System Prompt
125
- if prompt_start != -1:
126
- prompt_start += len("# System prompt:")
127
- prompt_end = example_start if example_start != -1 else len(text)
128
- system_prompt = text[prompt_start:prompt_end].strip()
129
- else:
130
- system_prompt = default_system_prompt
131
-
132
- # Extract Example Input
133
- if example_start != -1:
134
- example_start += len("# Example input:")
135
- example_input = text[example_start:].strip().split("\n", 1)[0]
136
- else:
137
- example_input = default_example_input
138
 
139
  return text, title, system_prompt, example_input
140
 
141
-
142
  def make_open_gpt(message, history, current_title, current_system_prompt, current_example_input, system_prompt=system_prompt):
143
  try:
144
  response = predict_beta(message, history, system_prompt)
 
108
  default_system_prompt = "This is a custom GPT agent."
109
  default_example_input = "Type your query here."
110
 
111
+ # Split the text into lines and reverse it to start from the end
112
+ lines = text.split('\n')
113
+ lines.reverse()
114
+
115
+ title = default_title
116
+ system_prompt = default_system_prompt
117
+ example_input = default_example_input
118
+
119
+ # Flags to check if we have found the sections
120
+ found_title, found_prompt, found_example = False, False, False
121
+
122
+ for line in lines:
123
+ if not found_example and line.startswith("# Example input:"):
124
+ example_input = line.replace("# Example input:", "").strip()
125
+ found_example = True
126
+ elif not found_prompt and line.startswith("# System prompt:"):
127
+ system_prompt = line.replace("# System prompt:", "").strip()
128
+ found_prompt = True
129
+ elif not found_title and line.startswith("# Title:"):
130
+ title = line.replace("# Title:", "").strip()
131
+ found_title = True
132
+
133
+ # Break the loop if all sections are found
134
+ if found_title and found_prompt and found_example:
135
+ break
 
 
136
 
137
  return text, title, system_prompt, example_input
138
 
 
139
  def make_open_gpt(message, history, current_title, current_system_prompt, current_example_input, system_prompt=system_prompt):
140
  try:
141
  response = predict_beta(message, history, system_prompt)