Compare commits
2 Commits
820d938060
...
caf5244d52
| Author | SHA1 | Date | |
|---|---|---|---|
| caf5244d52 | |||
| ca3a53e68b |
@@ -5,6 +5,17 @@ def openai_api_key(api_key: str) -> None:
|
|||||||
openai.api_key = api_key
|
openai.api_key = api_key
|
||||||
|
|
||||||
|
|
||||||
|
def display_models() -> None:
|
||||||
|
not_ready = []
|
||||||
|
for engine in sorted(openai.Engine.list()['data'], key=lambda x: x['id']):
|
||||||
|
if engine['ready']:
|
||||||
|
print(engine['id'])
|
||||||
|
else:
|
||||||
|
not_ready.append(engine['id'])
|
||||||
|
if len(not_ready) > 0:
|
||||||
|
print('\nNot ready: ' + ', '.join(not_ready))
|
||||||
|
|
||||||
|
|
||||||
def ai(chat: list[dict[str, str]],
|
def ai(chat: list[dict[str, str]],
|
||||||
config: dict,
|
config: dict,
|
||||||
number: int
|
number: int
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import argparse
|
|||||||
import pathlib
|
import pathlib
|
||||||
from .utils import terminal_width, process_tags, display_chat, display_source_code, display_tags_frequency
|
from .utils import terminal_width, process_tags, display_chat, display_source_code, display_tags_frequency
|
||||||
from .storage import save_answers, create_chat, get_tags, get_tags_unique, read_file, dump_data
|
from .storage import save_answers, create_chat, get_tags, get_tags_unique, read_file, dump_data
|
||||||
from .api_client import ai, openai_api_key
|
from .api_client import ai, openai_api_key, display_models
|
||||||
from itertools import zip_longest
|
from itertools import zip_longest
|
||||||
|
|
||||||
|
|
||||||
@@ -97,6 +97,7 @@ def create_parser() -> argparse.ArgumentParser:
|
|||||||
group.add_argument('-D', '--chat-dump', help="Print chat history as Python structure", action='store_true')
|
group.add_argument('-D', '--chat-dump', help="Print chat history as Python structure", action='store_true')
|
||||||
group.add_argument('-d', '--chat', help="Print chat history as readable text", action='store_true')
|
group.add_argument('-d', '--chat', help="Print chat history as readable text", action='store_true')
|
||||||
group.add_argument('-l', '--list-tags', help="List all tags and their frequency", action='store_true')
|
group.add_argument('-l', '--list-tags', help="List all tags and their frequency", action='store_true')
|
||||||
|
group.add_argument('-L', '--list-models', help="List all available models", action='store_true')
|
||||||
parser.add_argument('-c', '--config', help='Config file name.', default=default_config)
|
parser.add_argument('-c', '--config', help='Config file name.', default=default_config)
|
||||||
parser.add_argument('-m', '--max-tokens', help='Max tokens to use', type=int)
|
parser.add_argument('-m', '--max-tokens', help='Max tokens to use', type=int)
|
||||||
parser.add_argument('-T', '--temperature', help='Temperature to use', type=float)
|
parser.add_argument('-T', '--temperature', help='Temperature to use', type=float)
|
||||||
@@ -149,6 +150,8 @@ def main() -> int:
|
|||||||
process_and_display_chat(args, config)
|
process_and_display_chat(args, config)
|
||||||
elif args.list_tags:
|
elif args.list_tags:
|
||||||
process_and_display_tags(args, config)
|
process_and_display_tags(args, config)
|
||||||
|
elif args.list_models:
|
||||||
|
display_models()
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ def read_file(fname: pathlib.Path, tags_only: bool = False) -> Dict[str, Any]:
|
|||||||
question = "\n".join(text[question_idx:answer_idx]).strip()
|
question = "\n".join(text[question_idx:answer_idx]).strip()
|
||||||
answer = "\n".join(text[answer_idx + 1:]).strip()
|
answer = "\n".join(text[answer_idx + 1:]).strip()
|
||||||
return {"question": question, "answer": answer, "tags": tags,
|
return {"question": question, "answer": answer, "tags": tags,
|
||||||
"file": pathlib.Path(fname).name}
|
"file": fname.name}
|
||||||
|
|
||||||
|
|
||||||
def dump_data(data: Dict[str, Any]) -> str:
|
def dump_data(data: Dict[str, Any]) -> str:
|
||||||
@@ -74,6 +74,7 @@ def create_chat(question: Optional[str],
|
|||||||
if file.suffix == '.yaml':
|
if file.suffix == '.yaml':
|
||||||
with open(file, 'r') as f:
|
with open(file, 'r') as f:
|
||||||
data = yaml.load(f, Loader=yaml.FullLoader)
|
data = yaml.load(f, Loader=yaml.FullLoader)
|
||||||
|
data['file'] = file.name
|
||||||
elif file.suffix == '.txt':
|
elif file.suffix == '.txt':
|
||||||
data = read_file(file)
|
data = read_file(file)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user