added typ hints for all functions in 'main.py', 'utils.py', 'storage.py' and 'api_client.py'
This commit is contained in:
@@ -7,15 +7,16 @@ import sys
|
||||
import argcomplete
|
||||
import argparse
|
||||
import pathlib
|
||||
from .utils import terminal_width, print_tag_args, print_chat_hist, display_source_code, print_tags_frequency, ConfigType
|
||||
from .utils import terminal_width, print_tag_args, print_chat_hist, display_source_code, print_tags_frequency, ConfigType, ChatType
|
||||
from .storage import save_answers, create_chat_hist, get_tags, get_tags_unique, read_file, read_config, write_config, dump_data
|
||||
from .api_client import ai, openai_api_key, print_models
|
||||
from itertools import zip_longest
|
||||
from typing import Any
|
||||
|
||||
default_config = '.config.yaml'
|
||||
|
||||
|
||||
def tags_completer(prefix, parsed_args, **kwargs):
|
||||
def tags_completer(prefix: str, parsed_args: Any, **kwargs: Any) -> list[str]:
|
||||
with open(parsed_args.config, 'r') as f:
|
||||
config = yaml.load(f, Loader=yaml.FullLoader)
|
||||
return get_tags_unique(config, prefix)
|
||||
@@ -23,7 +24,7 @@ def tags_completer(prefix, parsed_args, **kwargs):
|
||||
|
||||
def create_question_with_hist(args: argparse.Namespace,
|
||||
config: ConfigType,
|
||||
) -> tuple[list[dict[str, str]], str, list[str]]:
|
||||
) -> tuple[ChatType, str, list[str]]:
|
||||
"""
|
||||
Creates the "AI request", including the question and chat history as determined
|
||||
by the specified tags.
|
||||
@@ -67,7 +68,7 @@ def config_cmd(args: argparse.Namespace, config: ConfigType) -> None:
|
||||
"""
|
||||
Handler for the 'config' command.
|
||||
"""
|
||||
if type(config['openai']) is not dict:
|
||||
if not isinstance(config['openai'], dict):
|
||||
raise RuntimeError('Configuration openai is not a dict.')
|
||||
|
||||
if args.list_models:
|
||||
@@ -83,15 +84,14 @@ def ask_cmd(args: argparse.Namespace, config: ConfigType) -> None:
|
||||
"""
|
||||
Handler for the 'ask' command.
|
||||
"""
|
||||
if type(config['openai']) is not dict:
|
||||
if not isinstance(config['openai'], dict):
|
||||
raise RuntimeError('Configuration openai is not a dict.')
|
||||
config_openai = config['openai']
|
||||
if args.max_tokens:
|
||||
config_openai['max_tokens'] = args.max_tokens
|
||||
config['openai']['max_tokens'] = args.max_tokens
|
||||
if args.temperature:
|
||||
config_openai['temperature'] = args.temperature
|
||||
config['openai']['temperature'] = args.temperature
|
||||
if args.model:
|
||||
config_openai['model'] = args.model
|
||||
config['openai']['model'] = args.model
|
||||
chat, question, tags = create_question_with_hist(args, config)
|
||||
print_chat_hist(chat, False, args.only_source_code)
|
||||
otags = args.output_tags or []
|
||||
|
||||
Reference in New Issue
Block a user