-
-
Notifications
You must be signed in to change notification settings - Fork 368
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
Ability to mess with logit biases #36
Comments
Adding this as CLI options feels messy to me, plus it doesn't necessarily work across other models. One option would be to have this as a template-only feature, refs #23. |
Slight twist: what if you want to use another template at the same time? Might be an argument for supporting combined templates - pass |
So I think this needs a complex version where you set the biases directly, and a simple version where you can just pass in a string of words to suppress and the tool splits on whitespace and augments them (as in that example - uppercase, space prefixed etc) and sets them to -100. Should design this to support more new sugar features in the future. |
I tried to get this working as a prototype for: It didn't seem to work though:
... but that's because I was using token IDs for GPT-3 when I should have been using them for GPT-4. Here's a transcript where I try to block all of the obvious "time" related tokens:
|
Here's my hacky prototype diff for this feature: diff --git a/llm/cli.py b/llm/cli.py
index 97a8449..12ccee5 100644
--- a/llm/cli.py
+++ b/llm/cli.py
@@ -71,6 +71,14 @@ def cli():
type=(str, str),
help="Parameters for template",
)
+@click.option(
+ "options",
+ "-o",
+ "--option",
+ multiple=True,
+ type=(str, str),
+ help="Options to pass to the model",
+)
@click.option("--no-stream", is_flag=True, help="Do not stream output")
@click.option("-n", "--no-log", is_flag=True, help="Don't log to database")
@click.option(
@@ -95,6 +103,7 @@ def prompt(
model,
template,
param,
+ options,
no_stream,
no_log,
_continue,
@@ -166,6 +175,14 @@ def prompt(
if model is None and template_obj.model:
model = template_obj.model
+ options = dict(options)
+ if "logit_bias" in options:
+ options["logit_bias"] = dict(
+ (int(k), v) for k, v in json.loads(options["logit_bias"]).items()
+ )
+ if "temperature" in options:
+ options["temperature"] = float(options["temperature"])
+
messages = []
if _continue:
_continue = -1
@@ -197,6 +214,7 @@ def prompt(
response = openai.ChatCompletion.create(
model=model,
messages=messages,
+ **options,
)
debug["model"] = response.model
debug["usage"] = response.usage
@@ -209,6 +227,7 @@ def prompt(
for chunk in openai.ChatCompletion.create(
model=model,
messages=messages,
+ **options,
stream=True,
):
debug["model"] = chunk.model |
Note that I had to do something custom for |
Here's a good minimal example: llm -m gpt-4 "Once upon a" -o logit_bias '{"1712":-100, "892":-100, "1489":-100}' -o temperature 1.0 |
Inspired by https://twitter.com/goodside/status/1669613516402089984
The text was updated successfully, but these errors were encountered: