Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle prompts with colons but no weights #46

Closed
wants to merge 1 commit into from
Closed

Gracefully handle prompts with colons but no weights #46

wants to merge 1 commit into from

Conversation

mitchellgordon95
Copy link

@mitchellgordon95 mitchellgordon95 commented Dec 3, 2021

When a prompt contains a colon (i.e. "Star Wars: Return of the Sith"), it will currently crash generation. This is a small change to prompt parsing to gracefully handle this case. Before:

>>> parse_prompt("hello world:2")
('hello world', 2.0, -inf)
>>> parse_prompt("hello world:2:15")
('hello world', 2.0, 15.0)
>>> parse_prompt("hello world: my name is Mitchell.")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Volumes/Repos/pixray/pixray.py", line 254, in parse_prompt
    return vals[0], float(vals[1]), float(vals[2])
ValueError: could not convert string to float: ' my name is Mitchell.'

After:

>> parse_prompt("hello world")
('hello world', 1, -inf)
>>> parse_prompt("hello world:2")
('hello world', 2.0, -inf)
>>> parse_prompt("hello world:2:15")
('hello world', 2.0, 15.0)
>>> parse_prompt("hello world: my name is Mitchell")
Warning, failed to parse prompt weights, assuming prompt does not contain weights.
('hello world: my name is Mitchell', 1, -inf)

@dribnet
Copy link
Owner

dribnet commented Dec 4, 2021

This looks solid and I'm very stoked be able to enter text prompts with colons - thanks for the thought put into this and I hope to test it soon.

@dribnet
Copy link
Owner

dribnet commented Dec 4, 2021

I excited with this improvement, but then also reworked it a bit subsequently so that someone didn't have to choose between having a colon in the text part of the prompt or appending a weight - but in fact could flexibly have both. Here's your handy test cases with a couple of extras that show the other cases

>>> import pixray
>>> from pixray import parse_prompt
>>> parse_prompt("hello world")
('hello world', 1, -inf)
>>> parse_prompt("hello world:2")
('hello world', 2.0, -inf)
>>> parse_prompt("hello world:2:15")
('hello world', 2.0, 15.0)
>>> parse_prompt("hello world: my name is Mitchell")
('hello world: my name is Mitchell', 1, -inf)
>>> parse_prompt("hello world: my name is Mitchell:2")
('hello world: my name is Mitchell', 2.0, -inf)
>>> parse_prompt("hello world: my name is Mitchell:2:15")
('hello world: my name is Mitchell', 2.0, 15.0)

The code for that can be seen in this commit now in the pixray/future development branch. Thanks for instigating this change - I have often been frustrated with this myself but never thought to improve the parsing to fix it!

@dribnet dribnet closed this Dec 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants