Compare commits
3 Commits
83448fa096
...
1b5e84793a
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b5e84793a | |||
| d1124dd0b3 | |||
| c630a956c6 |
@ -11,7 +11,8 @@ from .ais.openai_cmm import OpenAI
|
||||
|
||||
def create_ai(args: argparse.Namespace, config: Config) -> AI:
|
||||
"""
|
||||
Creates an AI subclass instance from the given args and configuration.
|
||||
Creates an AI subclass instance from the given arguments
|
||||
and configuration file.
|
||||
"""
|
||||
if args.ai:
|
||||
ai_conf = config.ais[args.ai]
|
||||
@ -21,6 +22,13 @@ def create_ai(args: argparse.Namespace, config: Config) -> AI:
|
||||
raise AIError("No AI name given and no default exists")
|
||||
|
||||
if ai_conf.name == 'openai':
|
||||
return OpenAI(cast(OpenAIConfig, ai_conf))
|
||||
ai = OpenAI(cast(OpenAIConfig, ai_conf))
|
||||
if args.max_tokens:
|
||||
ai.config.max_tokens = args.max_tokens
|
||||
if args.config.temperature:
|
||||
ai.config.temperature = args.temperature
|
||||
if args.model:
|
||||
ai.config.model = args.model
|
||||
return ai
|
||||
else:
|
||||
raise AIError(f"AI '{args.ai}' is not supported")
|
||||
|
||||
@ -7,6 +7,19 @@ from ..ai_factory import create_ai
|
||||
from ..ai import AI, AIResponse
|
||||
|
||||
|
||||
def create_message(chat: ChatDB, args: argparse.Namespace) -> Message:
|
||||
"""
|
||||
Creates (and writes) a new message from the given arguments.
|
||||
"""
|
||||
# FIXME: add sources to the question
|
||||
message = Message(question=Question(args.question),
|
||||
tags=args.ouput_tags, # FIXME
|
||||
ai=args.ai,
|
||||
model=args.model)
|
||||
chat.add_to_cache([message])
|
||||
return message
|
||||
|
||||
|
||||
def question_cmd(args: argparse.Namespace, config: Config) -> None:
|
||||
"""
|
||||
Handler for the 'question' command.
|
||||
@ -15,12 +28,7 @@ def question_cmd(args: argparse.Namespace, config: Config) -> None:
|
||||
db_path=Path(config.db))
|
||||
# if it's a new question, create and store it immediately
|
||||
if args.ask or args.create:
|
||||
# FIXME: add sources to the question
|
||||
message = Message(question=Question(args.question),
|
||||
tags=args.ouput_tags, # FIXME
|
||||
ai=args.ai,
|
||||
model=args.model)
|
||||
chat.add_to_cache([message])
|
||||
message = create_message(chat, args)
|
||||
if args.create:
|
||||
return
|
||||
|
||||
|
||||
@ -47,8 +47,16 @@ def create_parser() -> argparse.ArgumentParser:
|
||||
help='List of output tag names, default is input', metavar='OUTTAGS')
|
||||
otag_arg.completer = tags_completer # type: ignore
|
||||
|
||||
# a parent parser for all commands that support AI configuration
|
||||
ai_parser = argparse.ArgumentParser(add_help=False)
|
||||
ai_parser.add_argument('-A', '--AI', help='AI to use')
|
||||
ai_parser.add_argument('-M', '--model', help='Model to use')
|
||||
ai_parser.add_argument('-n', '--num-answers', help='Number of answers to request', type=int, default=1)
|
||||
ai_parser.add_argument('-m', '--max-tokens', help='Max tokens to use', type=int)
|
||||
ai_parser.add_argument('-T', '--temperature', help='Temperature to use', type=float)
|
||||
|
||||
# 'question' command parser
|
||||
question_cmd_parser = cmdparser.add_parser('question', parents=[tag_parser],
|
||||
question_cmd_parser = cmdparser.add_parser('question', parents=[tag_parser, ai_parser],
|
||||
help="ask, create and process questions.",
|
||||
aliases=['q'])
|
||||
question_cmd_parser.set_defaults(func=question_cmd)
|
||||
@ -59,12 +67,6 @@ def create_parser() -> argparse.ArgumentParser:
|
||||
question_group.add_argument('-p', '--process', nargs='*', help='Process existing questions')
|
||||
question_cmd_parser.add_argument('-O', '--overwrite', help='Overwrite existing messages when repeating them',
|
||||
action='store_true')
|
||||
question_cmd_parser.add_argument('-m', '--max-tokens', help='Max tokens to use', type=int)
|
||||
question_cmd_parser.add_argument('-T', '--temperature', help='Temperature to use', type=float)
|
||||
question_cmd_parser.add_argument('-A', '--AI', help='AI to use')
|
||||
question_cmd_parser.add_argument('-M', '--model', help='Model to use')
|
||||
question_cmd_parser.add_argument('-n', '--num-answers', help='Number of answers to produce', type=int,
|
||||
default=1)
|
||||
question_cmd_parser.add_argument('-s', '--source', nargs='+', help='Source add content of a file to the query')
|
||||
question_cmd_parser.add_argument('-S', '--source-code-only', help='Add pure source code to the chat history',
|
||||
action='store_true')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user