Skip to content

Commit d85260e

Browse files
committed
WIP
1 parent 2c4d30a commit d85260e

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

llms_wrapper/llms_wrapper_webchat.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
Module for the CLI to experiment with chatting using a pre-configured chatbot.
33
"""
44
import argparse
5+
6+
from pyperclip import init_windows_clipboard
7+
58
from llms_wrapper.config import read_config_file as read_config
69
from fasthtml.common import *
710
from loguru import logger
@@ -19,6 +22,7 @@ def get_args():
1922
parser.add_argument('--config', '-c', type=str, help='Configuration file, should contain LLM and prompt config', required=True)
2023
parser.add_argument("--llm", '-l', type=str, help="Alias of LLM to use for chatbot (or use first found in config)", required=False)
2124
parser.add_argument("--promptfile", type=str, help="Prompt file containing prompts, overrides config (or use prompt section in config)", required=False)
25+
parser.add_argument("--pids", nargs="*", help="Prompt ids (pids) to use as initial messages for the chatbot")
2226
parser.add_argument("--max_messages", type=int, default=20,
2327
help="Max number of messages to keep in the chat history (default: 20)", required=False)
2428
parser.add_argument("--clear_page", action="store_true",
@@ -27,6 +31,7 @@ def get_args():
2731
help='Be more verbose', required=False)
2832
parser.add_argument("--debug", action="store_true", help="Debug mode, overrides loglevel", required=False)
2933
args = parser.parse_args()
34+
configure_logging(level="DEBUG" if args.debug else "INFO")
3035
config = {}
3136
config.update(vars(args))
3237
# debug implies verbose
@@ -43,7 +48,7 @@ def get_args():
4348

4449
# if a promptfile is specified, load the prompts from the file and update the config
4550
if args.promptfile is not None:
46-
prompts = load_prompts(args.promptfile, as_messages=True)
51+
prompts = load_prompts(args.promptfile, as_messages=True) # the prompt gets returned as messages!
4752
if "prompts" not in config:
4853
config["prompts"] = {}
4954
elif not isinstance(config["prompts"], dict):
@@ -52,6 +57,15 @@ def get_args():
5257
if pid in config["prompts"]:
5358
logger.warning(f"Prompt {pid} already exists in config file, overriding from the prompt file!")
5459
config["prompts"][pid] = prompt
60+
if args.pids: # if pids are specified, collect them for later
61+
init_messages = []
62+
for pid in args.pids:
63+
if pid in config["prompts"]:
64+
init_messages += config["prompts"][pid]
65+
else:
66+
raise ValueError(f"PID {pid} not found in promptfile")
67+
logger.info(f"Loaded initial messages: {init_messages}")
68+
config["init_messages"] = init_messages
5569

5670
# set the config parameter use_llm to the llm to use
5771
if not "llms" in config or not isinstance(config["llms"], list) or len(config["llms"]) == 0:
@@ -68,7 +82,6 @@ def get_args():
6882
return config
6983

7084
config = get_args()
71-
configure_logging(level="DEBUG" if config["debug"] else "INFO")
7285
llms = LLMS(config)
7386
llm_aliases = [l["alias"] for l in config["llms"]]
7487
llm_used = config["use_llm"]
@@ -78,7 +91,7 @@ def get_args():
7891
chatbot = SimpleSerialChatbot(
7992
llm,
8093
config=config,
81-
initial_message=None, # TODO: add prompt id for system prompt to args and specify here
94+
initial_message=config.get("init_messages"),
8295
message_template=None,
8396
max_messages = config["max_messages"], # Max number of messages to keep in the chat history)
8497
)

test-chatbot-config.hjson

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
{
22
llms:
33
[
4-
{
5-
llm: openai/gpt-4.5-preview
6-
api_key_env: MY_OPENAI_API_KEY
7-
alias: gpt45preview
8-
temperature: 0
9-
}
104
{
115
llm: openai/gpt-4.1
126
api_key_env: MY_OPENAI_API_KEY

0 commit comments

Comments
 (0)