Tonic commited on
Commit
c285801
1 Parent(s): c4c45b9

Update maker.py

Browse files
Files changed (1) hide show
  1. maker.py +33 -28
maker.py CHANGED
@@ -20,7 +20,6 @@ What would you like to make?
20
 
21
  welcome_preview_message = """
22
  Welcome to **{}**! Say something like:
23
-
24
  "{}"
25
  """
26
 
@@ -47,7 +46,7 @@ Sure, I'd be happy to help you build a bot! I'm generating a title, system promp
47
  # Example input: Risks of setting up a non-profit board
48
 
49
  <|user|>
50
- Make a chatbot that roasts tech ceos"
51
 
52
  <|assistant|>
53
  Sure, I'd be happy to help you build a bot! I'm generating a title, system prompt, and an example input. How do they sound? Feel free to give me feedback!
@@ -57,7 +56,7 @@ Sure, I'd be happy to help you build a bot! I'm generating a title, system promp
57
 
58
  """
59
 
60
- def predict_beta(message, chatbot=[], system_prompt=system_prompt, max_new_tokens=650, temperature=0.4, top_p=0.9, repetition_penalty=0.9, advanced=True):
61
  client = Client(tulu)
62
  try:
63
  result = client.predict(
@@ -82,39 +81,45 @@ def predict_beta(message, chatbot=[], system_prompt=system_prompt, max_new_token
82
  error_msg = f"An error occurred: {str(e)}"
83
  raise gr.Error(error_msg)
84
 
85
-
86
- def extract_title_prompt_example(text, title, system_prompt, example_input):
87
  default_title = "Custom GPT Agent"
88
  default_system_prompt = "This is a custom GPT agent."
89
  default_example_input = "Type your query here."
90
 
91
- # Initialize variables
92
- title_start = -1
93
- prompt_start = -1
94
- example_start = -1
95
- try:
96
- title_start = text.lower().rfind("Title:") + len("Title:")
97
- prompt_start = text.lower().rfind("System prompt:")
98
- title = text[title_start:prompt_start].strip()
99
- except ValueError:
100
- pass
101
- try:
102
- prompt_start = text.lower().rfind("System prompt:") + len("System prompt:")
103
- example_start = text.lower().rfind("Example input:")
104
- system_prompt = text[prompt_start:example_start].strip()
105
- except ValueError:
106
- pass
107
- try:
108
- example_start = text.lower().rfind("Example input:") + len("Example input:")
109
- example_input = text[example_start:].strip()
110
- example_input = example_input[:example_input.index("\n")]
111
- except ValueError:
112
- pass
 
 
 
 
 
 
113
  return text, title, system_prompt, example_input
114
 
 
115
  def make_open_gpt(message, history, current_title, current_system_prompt, current_example_input, system_prompt=system_prompt):
116
  response = predict_beta(message, history, system_prompt)
117
- response, title, system_prompt, example_input = extract_title_prompt_example(response, current_title, current_system_prompt, current_example_input)
118
  return "", history + [(message, response)], title, system_prompt, example_input, [(None, welcome_preview_message.format(title, example_input))], example_input, gr.Column(visible=True), gr.Group(visible=True)
119
 
120
  def set_title_example(title, example):
 
20
 
21
  welcome_preview_message = """
22
  Welcome to **{}**! Say something like:
 
23
  "{}"
24
  """
25
 
 
46
  # Example input: Risks of setting up a non-profit board
47
 
48
  <|user|>
49
+ Make a chatbot that roasts tech ceos
50
 
51
  <|assistant|>
52
  Sure, I'd be happy to help you build a bot! I'm generating a title, system prompt, and an example input. How do they sound? Feel free to give me feedback!
 
56
 
57
  """
58
 
59
+ def predict_beta(message, chatbot=[], system_prompt=system_prompt, max_new_tokens=650, temperature=0.4, top_p=0.90, repetition_penalty=0.90, advanced=True):
60
  client = Client(tulu)
61
  try:
62
  result = client.predict(
 
81
  error_msg = f"An error occurred: {str(e)}"
82
  raise gr.Error(error_msg)
83
 
84
+ def extract_title_prompt_example(text):
 
85
  default_title = "Custom GPT Agent"
86
  default_system_prompt = "This is a custom GPT agent."
87
  default_example_input = "Type your query here."
88
 
89
+ # Find the start indices of each section
90
+ title_start = text.find("# Title:")
91
+ prompt_start = text.find("# System prompt:")
92
+ example_start = text.find("# Example input:")
93
+
94
+ # Extract Title
95
+ if title_start != -1:
96
+ title_start += len("# Title:")
97
+ title_end = prompt_start if prompt_start != -1 else len(text)
98
+ title = text[title_start:title_end].strip()
99
+ else:
100
+ title = default_title
101
+
102
+ # Extract System Prompt
103
+ if prompt_start != -1:
104
+ prompt_start += len("# System prompt:")
105
+ prompt_end = example_start if example_start != -1 else len(text)
106
+ system_prompt = text[prompt_start:prompt_end].strip()
107
+ else:
108
+ system_prompt = default_system_prompt
109
+
110
+ # Extract Example Input
111
+ if example_start != -1:
112
+ example_start += len("# Example input:")
113
+ example_input = text[example_start:].strip().split("\n", 1)[0]
114
+ else:
115
+ example_input = default_example_input
116
+
117
  return text, title, system_prompt, example_input
118
 
119
+
120
  def make_open_gpt(message, history, current_title, current_system_prompt, current_example_input, system_prompt=system_prompt):
121
  response = predict_beta(message, history, system_prompt)
122
+ _, title, system_prompt, example_input = extract_title_prompt_example(response)
123
  return "", history + [(message, response)], title, system_prompt, example_input, [(None, welcome_preview_message.format(title, example_input))], example_input, gr.Column(visible=True), gr.Group(visible=True)
124
 
125
  def set_title_example(title, example):