Skip to content

Commit

Permalink
Turn system-prompt into str type so it can be specified in a settings…
Browse files Browse the repository at this point in the history
… file.

Rename variable to avoid name clashes.
  • Loading branch information
yaph committed Jan 16, 2025
1 parent 7dc048c commit fa5b49d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions charla/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def run(argv: argparse.Namespace) -> None:
open_location = ''

# Prompt used to give directions to the model at the beginning of the chat.
system_prompt = argv.system_prompt.read() if argv.system_prompt else ''
system_prompt = Path(argv.system_prompt).read_text() if argv.system_prompt else ''

# Determine which Client class to import.
if argv.provider == 'ollama':
Expand All @@ -104,7 +104,7 @@ def run(argv: argparse.Namespace) -> None:
session = prompt_session(argv)
print_fmt('Chat with:', HTML(f'<ansigreen>{argv.model}</ansigreen>'), '\n')
if system_prompt:
print_fmt('Using system prompt:', HTML(f'<ansigreen>{argv.system_prompt.name}</ansigreen>'), '\n')
print_fmt('Using system prompt:', HTML(f'<ansigreen>{argv.system_prompt}</ansigreen>'), '\n')

while True:
try:
Expand Down
2 changes: 1 addition & 1 deletion charla/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def main(args=None) -> None:
)
parser.add_argument('--multiline', action='store_true', help='Use multiline mode.')
parser.add_argument(
'--system-prompt', '-sp', type=argparse.FileType(), help='File that contains system prompt to use.'
'--system-prompt', '-sp', type=str, help='File that contains system prompt to use.'
)
parser.add_argument('--version', action='version', version=f'%(prog)s {__version__}')
parser.set_defaults(**user_settings, func=chat.run)
Expand Down
8 changes: 4 additions & 4 deletions charla/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def manage(argv: argparse.Namespace) -> None:
if argv.location:
print(path_settings)
else:
user_settings = {k: v for k, v in vars(argv).items() if k in default_settings}
out = json.dumps(user_settings, indent=4)
current_settings = {k: v for k, v in vars(argv).items() if k in default_settings}
out = json.dumps(current_settings, indent=4)
if argv.save:
filename = '.charla.json'
Path(filename).write_text(out)
Expand All @@ -54,10 +54,10 @@ def mkdir(path: Path, **kwds):
sys.exit(str(err))


def settings(user_settings: dict) -> dict:
def settings(current_settings: dict) -> dict:
"""Return settings based on user input."""

default_settings.update(user_settings)
default_settings.update(current_settings)
return default_settings


Expand Down

0 comments on commit fa5b49d

Please sign in to comment.