mirror of
https://github.com/Hopiu/llm.git
synced 2026-05-03 19:34:44 +00:00
Allow -t and --system to be used together, refs #916
This commit is contained in:
parent
6273bc79ff
commit
4279df23a4
2 changed files with 18 additions and 10 deletions
18
llm/cli.py
18
llm/cli.py
|
|
@ -574,8 +574,6 @@ def prompt(
|
|||
if template:
|
||||
params = dict(param)
|
||||
# Cannot be used with system
|
||||
if system:
|
||||
raise click.ClickException("Cannot use -t/--template and --system together")
|
||||
try:
|
||||
template_obj = load_template(template)
|
||||
except LoadTemplateError as ex:
|
||||
|
|
@ -601,13 +599,15 @@ def prompt(
|
|||
if "input" in template_obj.vars():
|
||||
input_ = read_prompt()
|
||||
try:
|
||||
template_prompt, system = template_obj.evaluate(input_, params)
|
||||
template_prompt, template_system = template_obj.evaluate(input_, params)
|
||||
if template_prompt:
|
||||
# Combine with user prompt
|
||||
if prompt and "input" not in template_obj.vars():
|
||||
prompt = template_prompt + "\n" + prompt
|
||||
else:
|
||||
prompt = template_prompt
|
||||
if template_system and not system:
|
||||
system = template_system
|
||||
except Template.MissingVariables as ex:
|
||||
raise click.ClickException(str(ex))
|
||||
if model_id is None and template_obj.model:
|
||||
|
|
@ -853,9 +853,6 @@ def chat(
|
|||
template_obj = None
|
||||
if template:
|
||||
params = dict(param)
|
||||
# Cannot be used with system
|
||||
if system:
|
||||
raise click.ClickException("Cannot use -t/--template and --system together")
|
||||
try:
|
||||
template_obj = load_template(template)
|
||||
except LoadTemplateError as ex:
|
||||
|
|
@ -929,9 +926,16 @@ def chat(
|
|||
continue
|
||||
if template_obj:
|
||||
try:
|
||||
prompt, system = template_obj.evaluate(prompt, params)
|
||||
template_prompt, template_system = template_obj.evaluate(prompt, params)
|
||||
except Template.MissingVariables as ex:
|
||||
raise click.ClickException(str(ex))
|
||||
if template_system and not system:
|
||||
system = template_system
|
||||
if template_prompt:
|
||||
new_prompt = template_prompt
|
||||
if prompt:
|
||||
new_prompt += "\n" + prompt
|
||||
prompt = new_prompt
|
||||
if prompt.strip() in ("exit", "quit"):
|
||||
break
|
||||
response = conversation.prompt(prompt, system=system, **kwargs)
|
||||
|
|
|
|||
|
|
@ -211,14 +211,18 @@ def test_templates_error_on_missing_schema(templates_path):
|
|||
None,
|
||||
None,
|
||||
),
|
||||
# -s system prompt should over-ride template system prompt
|
||||
pytest.param(
|
||||
"boo",
|
||||
"Input text",
|
||||
["-s", "s"],
|
||||
["-s", "custom system"],
|
||||
"gpt-4o-mini",
|
||||
[
|
||||
{"role": "system", "content": "custom system"},
|
||||
{"role": "user", "content": "boo\nInput text"},
|
||||
],
|
||||
None,
|
||||
None,
|
||||
"Error: Cannot use -t/--template and --system together",
|
||||
None,
|
||||
marks=pytest.mark.httpx_mock(),
|
||||
),
|
||||
pytest.param(
|
||||
|
|
|
|||
Loading…
Reference in a new issue