Skip to content

Commit

Permalink
fix string split
Browse files Browse the repository at this point in the history
  • Loading branch information
bghira committed Apr 28, 2024
1 parent 4fe682b commit aa04e99
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,28 @@ def _extract_parameters(self, prompts: str) -> tuple:
"""
if type(prompts) is not list:
prompts = [prompts]

def normalize_prompt(prompt):
return prompt.replace('\u00A0', ' ').replace('\u200B', ' ')

for idx, prompt in enumerate(prompts):
prompt = normalize_prompt(prompt)

parameters = {}
if "--" in prompt:
# Improved regular expression for parameter extraction
param_pattern = r"--(\w+)(?:=(.*))?"
param_pattern = r"--(\w+)=?([^--]*)"
matches = re.findall(param_pattern, prompt)

for key, value in matches:
parameters[key] = value or True # Handle values or True flags
# Clean up the value by removing any trailing spaces
parameters[key] = value.strip()

# Reconstruct the prompt without parameters
prompt = re.sub(param_pattern, '', prompt).strip()

prompts[idx] = prompt

logging.debug(f"Prompt parameters extracted from prompt {prompt}: {parameters}")
return prompt, parameters

return prompts[0] if len(prompts) == 1 else prompts, parameters

0 comments on commit aa04e99

Please sign in to comment.