Compare commits
3 Commits
1b5e84793a
...
83448fa096
| Author | SHA1 | Date | |
|---|---|---|---|
| 83448fa096 | |||
| 2ac873fd95 | |||
| dc8b225a91 |
@ -11,8 +11,7 @@ from .ais.openai_cmm import OpenAI
|
|||||||
|
|
||||||
def create_ai(args: argparse.Namespace, config: Config) -> AI:
|
def create_ai(args: argparse.Namespace, config: Config) -> AI:
|
||||||
"""
|
"""
|
||||||
Creates an AI subclass instance from the given arguments
|
Creates an AI subclass instance from the given args and configuration.
|
||||||
and configuration file.
|
|
||||||
"""
|
"""
|
||||||
if args.ai:
|
if args.ai:
|
||||||
ai_conf = config.ais[args.ai]
|
ai_conf = config.ais[args.ai]
|
||||||
@ -22,13 +21,6 @@ def create_ai(args: argparse.Namespace, config: Config) -> AI:
|
|||||||
raise AIError("No AI name given and no default exists")
|
raise AIError("No AI name given and no default exists")
|
||||||
|
|
||||||
if ai_conf.name == 'openai':
|
if ai_conf.name == 'openai':
|
||||||
ai = OpenAI(cast(OpenAIConfig, ai_conf))
|
return 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:
|
else:
|
||||||
raise AIError(f"AI '{args.ai}' is not supported")
|
raise AIError(f"AI '{args.ai}' is not supported")
|
||||||
|
|||||||
@ -7,19 +7,6 @@ from ..ai_factory import create_ai
|
|||||||
from ..ai import AI, AIResponse
|
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:
|
def question_cmd(args: argparse.Namespace, config: Config) -> None:
|
||||||
"""
|
"""
|
||||||
Handler for the 'question' command.
|
Handler for the 'question' command.
|
||||||
@ -28,7 +15,12 @@ def question_cmd(args: argparse.Namespace, config: Config) -> None:
|
|||||||
db_path=Path(config.db))
|
db_path=Path(config.db))
|
||||||
# if it's a new question, create and store it immediately
|
# if it's a new question, create and store it immediately
|
||||||
if args.ask or args.create:
|
if args.ask or args.create:
|
||||||
message = create_message(chat, args)
|
# 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])
|
||||||
if args.create:
|
if args.create:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@ -47,16 +47,8 @@ def create_parser() -> argparse.ArgumentParser:
|
|||||||
help='List of output tag names, default is input', metavar='OUTTAGS')
|
help='List of output tag names, default is input', metavar='OUTTAGS')
|
||||||
otag_arg.completer = tags_completer # type: ignore
|
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' command parser
|
||||||
question_cmd_parser = cmdparser.add_parser('question', parents=[tag_parser, ai_parser],
|
question_cmd_parser = cmdparser.add_parser('question', parents=[tag_parser],
|
||||||
help="ask, create and process questions.",
|
help="ask, create and process questions.",
|
||||||
aliases=['q'])
|
aliases=['q'])
|
||||||
question_cmd_parser.set_defaults(func=question_cmd)
|
question_cmd_parser.set_defaults(func=question_cmd)
|
||||||
@ -67,6 +59,12 @@ def create_parser() -> argparse.ArgumentParser:
|
|||||||
question_group.add_argument('-p', '--process', nargs='*', help='Process existing questions')
|
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',
|
question_cmd_parser.add_argument('-O', '--overwrite', help='Overwrite existing messages when repeating them',
|
||||||
action='store_true')
|
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', 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',
|
question_cmd_parser.add_argument('-S', '--source-code-only', help='Add pure source code to the chat history',
|
||||||
action='store_true')
|
action='store_true')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user