added typ hints for all functions in 'main.py', 'utils.py', 'storage.py' and 'api_client.py'
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
import openai
|
||||
|
||||
from .utils import ConfigType, ChatType
|
||||
|
||||
|
||||
def openai_api_key(api_key: str) -> None:
|
||||
openai.api_key = api_key
|
||||
|
||||
|
||||
def print_models() -> None:
|
||||
"""
|
||||
Print all models supported by the current AI.
|
||||
"""
|
||||
not_ready = []
|
||||
for engine in sorted(openai.Engine.list()['data'], key=lambda x: x['id']):
|
||||
if engine['ready']:
|
||||
@@ -16,10 +21,16 @@ def print_models() -> None:
|
||||
print('\nNot ready: ' + ', '.join(not_ready))
|
||||
|
||||
|
||||
def ai(chat: list[dict[str, str]],
|
||||
config: dict,
|
||||
def ai(chat: ChatType,
|
||||
config: ConfigType,
|
||||
number: int
|
||||
) -> tuple[list[str], dict[str, int]]:
|
||||
"""
|
||||
Make AI request with the given chat history and configuration.
|
||||
Return AI response and tokens used.
|
||||
"""
|
||||
if not isinstance(config['openai'], dict):
|
||||
raise RuntimeError('Configuration openai is not a dict.')
|
||||
response = openai.ChatCompletion.create(
|
||||
model=config['openai']['model'],
|
||||
messages=chat,
|
||||
|
||||
Reference in New Issue
Block a user