Skip to content

Commit

Permalink
Merge pull request #35 from jepler/misc-improvements
Browse files Browse the repository at this point in the history
switch openai default to gpt-4-turbo
  • Loading branch information
jepler authored Apr 10, 2024
2 parents 3682753 + 08f3fa8 commit 7999721
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/chap/backends/openai_chatgpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def from_model(cls, model: str) -> "EncodingMeta":
class ChatGPT:
@dataclass
class Parameters:
model: str = "gpt-3.5-turbo"
"""The model to use. The most common alternative value is 'gpt-4'."""
model: str = "gpt-4-turbo"
"""The model to use. The most common alternative value is 'gpt-3.5-turbo'."""

max_request_tokens: int = 1024
"""The approximate greatest number of tokens to send in a request. When the session is long, the system prompt and 1 or more of the most recent interaction steps are sent."""
Expand Down
14 changes: 11 additions & 3 deletions src/chap/commands/ask.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ async def work() -> None:

@command_uses_new_session
@click.option("--print-prompt/--no-print-prompt", default=True)
@click.argument("prompt", nargs=-1, required=True)
def main(obj: Obj, prompt: str, print_prompt: bool) -> None:
@click.option("--stdin/--no-stdin", "use_stdin", default=False)
@click.argument("prompt", nargs=-1)
def main(obj: Obj, prompt: list[str], use_stdin: bool, print_prompt: bool) -> None:
"""Ask a question (command-line argument is passed as prompt)"""
session = obj.session
assert session is not None
Expand All @@ -112,9 +113,16 @@ def main(obj: Obj, prompt: str, print_prompt: bool) -> None:
api = obj.api
assert api is not None

if use_stdin:
if prompt:
raise click.UsageError("Can't use 'prompt' together with --stdin")

joined_prompt = sys.stdin.read()
else:
joined_prompt = " ".join(prompt)
# symlink_session_filename(session_filename)

response = verbose_ask(api, session, " ".join(prompt), print_prompt=print_prompt)
response = verbose_ask(api, session, joined_prompt, print_prompt=print_prompt)

print(f"Saving session to {session_filename}", file=sys.stderr)
if response is not None:
Expand Down
4 changes: 3 additions & 1 deletion src/chap/commands/tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ def main(obj: Obj, replace_system_prompt: bool) -> None:
assert session_filename is not None

if replace_system_prompt:
session[0].content = obj.system_message or api.system_message
session[0].content = (
api.system_message if obj.system_message is None else obj.system_message
)

tui = Tui(api, session)
tui.run()
Expand Down
23 changes: 21 additions & 2 deletions src/chap/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import asyncio
import datetime
import io
import importlib
import os
import pathlib
Expand Down Expand Up @@ -177,12 +178,23 @@ def colonstr(arg: str) -> tuple[str, str]:


def set_system_message(ctx: click.Context, param: click.Parameter, value: str) -> None:
if value and value.startswith("@"):
if value is None:
return
if value.startswith("@"):
with open(value[1:], "r", encoding="utf-8") as f:
value = f.read().rstrip()
value = f.read().strip()
ctx.obj.system_message = value


def set_system_message_from_file(
ctx: click.Context, param: click.Parameter, value: io.TextIOWrapper
) -> None:
if value is None:
return
content = value.read().strip()
ctx.obj.system_message = content


def set_backend(ctx: click.Context, param: click.Parameter, value: str) -> None:
if value == "list":
formatter = ctx.make_formatter()
Expand Down Expand Up @@ -369,6 +381,13 @@ def format_options(
help="Show the version and exit",
callback=version_callback,
),
click.Option(
("--system-message-file", "-@"),
type=click.File("r"),
default=None,
callback=set_system_message_from_file,
expose_value=False,
),
click.Option(
("--system-message", "-S"),
type=str,
Expand Down

0 comments on commit 7999721

Please sign in to comment.