Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: build
on: [push]
jobs:
test:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
include:
- name: 'check'
python: '3.9'
toxpython: 'python3.9'
tox_env: 'check'
os: 'ubuntu-latest'
- name: 'docs'
python: '3.9'
toxpython: 'python3.9'
tox_env: 'docs'
os: 'ubuntu-latest'
- name: 'py39 (ubuntu)'
python: '3.9'
toxpython: 'python3.9'
python_arch: 'x64'
tox_env: 'py39'
os: 'ubuntu-latest'
- name: 'py39 (windows)'
python: '3.9'
toxpython: 'python3.9'
python_arch: 'x64'
tox_env: 'py39'
os: 'windows-latest'
- name: 'py39 (macos)'
python: '3.9'
toxpython: 'python3.9'
python_arch: 'x64'
tox_env: 'py39'
os: 'macos-latest'
- name: 'py310 (ubuntu)'
python: '3.10'
toxpython: 'python3.10'
python_arch: 'x64'
tox_env: 'py310'
os: 'ubuntu-latest'
- name: 'py310 (windows)'
python: '3.10'
toxpython: 'python3.10'
python_arch: 'x64'
tox_env: 'py310'
os: 'windows-latest'
- name: 'py310 (macos)'
python: '3.10'
toxpython: 'python3.10'
python_arch: 'x64'
tox_env: 'py310'
os: 'macos-latest'
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
architecture: ${{ matrix.python_arch }}
- name: install dependencies
run: |
python -mpip install --progress-bar=off -r ci/requirements.txt
virtualenv --version
pip --version
tox --version
pip list --format=freeze
- name: test
env:
TOXPYTHON: '${{ matrix.toxpython }}'
run: >
tox -e ${{ matrix.tox_env }} -v
13 changes: 13 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
graft askai
graft images
graft ci
graft tests


include pytest.ini
include tox.ini
include .github/workflows/github-actions.yml

include README.rst

global-exclude *.py[cod] __pycache__/* *.so *.dylib CNAME
1 change: 0 additions & 1 deletion askai/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from pathlib import Path


ASKAI_PATH = Path.home() / ".askai"
API_KEY_PATH = ASKAI_PATH / "key"
CONFIG_PATH = ASKAI_PATH / "config.yml"
Expand Down
99 changes: 72 additions & 27 deletions askai/entrypoint_askai.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import click
import openai

from .constants import OPENAI_NUM_ANSWERS_MIN, OPENAI_TEMPERATURE_MIN, OPENAI_TEMPERATURE_MAX, OPENAI_MAX_TOKENS_MIN, \
OPENAI_TOP_P_MIN, OPENAI_TOP_P_MAX, OPENAI_FREQUENCY_PENALTY_MIN, OPENAI_FREQUENCY_PENALTY_MAX, \
OPENAI_PRESENCE_PENALTY_MIN, OPENAI_PRESENCE_PENALTY_MAX
from .utils import KeyHelper, ConfigHelper, PrintHelper, AvailableModels
from .constants import (OPENAI_FREQUENCY_PENALTY_MAX,
OPENAI_FREQUENCY_PENALTY_MIN, OPENAI_MAX_TOKENS_MIN,
OPENAI_NUM_ANSWERS_MIN, OPENAI_PRESENCE_PENALTY_MAX,
OPENAI_PRESENCE_PENALTY_MIN, OPENAI_TEMPERATURE_MAX,
OPENAI_TEMPERATURE_MIN, OPENAI_TOP_P_MAX,
OPENAI_TOP_P_MIN)
from .entrypoint_config import config
from .entrypoint_init import init
from .entrypoint_key import key
from .utils import AvailableModels, ConfigHelper, KeyHelper, PrintHelper


class DefaultCommandGroup(click.Group):
Expand All @@ -22,12 +25,13 @@ class DefaultCommandGroup(click.Group):
default_command: bool

def command(self, *args, **kwargs):
default_command = kwargs.pop('default_command', False)
default_command = kwargs.pop("default_command", False)
if default_command and not args:
kwargs['name'] = kwargs.get('name', ' ')
kwargs["name"] = kwargs.get("name", " ")
decorator = super(DefaultCommandGroup, self).command(*args, **kwargs)

if default_command:

def new_decorator(f):
cmd = decorator(f)
self.default_command = cmd.name
Expand All @@ -40,13 +44,11 @@ def new_decorator(f):
def resolve_command(self, ctx, args):
try:
# test if the command parses
return super(
DefaultCommandGroup, self).resolve_command(ctx, args)
return super(DefaultCommandGroup, self).resolve_command(ctx, args)
except click.UsageError:
# command did not parse, assume it is the default command
args.insert(0, self.default_command)
return super(
DefaultCommandGroup, self).resolve_command(ctx, args)
return super(DefaultCommandGroup, self).resolve_command(ctx, args)

def format_help(self, ctx, formatter) -> None:
PrintHelper.logo()
Expand All @@ -65,21 +67,60 @@ def askai() -> None:

@askai.command(default_command=True)
@click.argument("prompt")
@click.option("-n", "--num-answers", type=click.IntRange(min=OPENAI_NUM_ANSWERS_MIN), help="Number of alternative answers")
@click.option("-m", "--model", type=click.Choice(choices=AvailableModels.members_as_list()), help="OpenAI model to use. E.g. `text-ada-001`")
@click.option("-t", "--temperature", type=click.FloatRange(min=OPENAI_TEMPERATURE_MIN, max=OPENAI_TEMPERATURE_MAX), help="Temperature")
@click.option("--max-tokens", type=click.IntRange(min=OPENAI_MAX_TOKENS_MIN), help="Max tokens")
@click.option("--top-p", type=click.FloatRange(min=OPENAI_TOP_P_MIN, max=OPENAI_TOP_P_MAX), help="Top p")
@click.option("--frequency-penalty", type=click.FloatRange(min=OPENAI_FREQUENCY_PENALTY_MIN, max=OPENAI_FREQUENCY_PENALTY_MAX), help="Frequency penalty")
@click.option("--presence-penalty", type=click.FloatRange(min=OPENAI_PRESENCE_PENALTY_MIN, max=OPENAI_PRESENCE_PENALTY_MAX), help="Presence penalty")
def ask(prompt: str,
num_answers: int,
model: str,
temperature: float,
max_tokens: int,
top_p: float,
frequency_penalty: float,
presence_penalty: float) -> None:
@click.option(
"-n",
"--num-answers",
type=click.IntRange(min=OPENAI_NUM_ANSWERS_MIN),
help="Number of alternative answers",
)
@click.option(
"-m",
"--model",
type=click.Choice(choices=AvailableModels.members_as_list()),
help="OpenAI model to use. E.g. `text-ada-001`",
)
@click.option(
"-t",
"--temperature",
type=click.FloatRange(
min=OPENAI_TEMPERATURE_MIN, max=OPENAI_TEMPERATURE_MAX
),
help="Temperature",
)
@click.option(
"--max-tokens",
type=click.IntRange(min=OPENAI_MAX_TOKENS_MIN),
help="Max tokens",
)
@click.option(
"--top-p",
type=click.FloatRange(min=OPENAI_TOP_P_MIN, max=OPENAI_TOP_P_MAX),
help="Top p",
)
@click.option(
"--frequency-penalty",
type=click.FloatRange(
min=OPENAI_FREQUENCY_PENALTY_MIN, max=OPENAI_FREQUENCY_PENALTY_MAX
),
help="Frequency penalty",
)
@click.option(
"--presence-penalty",
type=click.FloatRange(
min=OPENAI_PRESENCE_PENALTY_MIN, max=OPENAI_PRESENCE_PENALTY_MAX
),
help="Presence penalty",
)
def ask(
prompt: str,
num_answers: int,
model: str,
temperature: float,
max_tokens: int,
top_p: float,
frequency_penalty: float,
presence_penalty: float,
) -> None:
openai.api_key = KeyHelper.from_file()
_config = ConfigHelper.from_file()

Expand All @@ -90,8 +131,12 @@ def ask(prompt: str,
max_tokens=max_tokens if max_tokens else _config.max_tokens,
n=num_answers if num_answers else _config.num_answers,
top_p=top_p if top_p else _config.top_p,
frequency_penalty=frequency_penalty if frequency_penalty else _config.frequency_penalty,
presence_penalty=presence_penalty if presence_penalty else _config.presence_penalty
frequency_penalty=frequency_penalty
if frequency_penalty
else _config.frequency_penalty,
presence_penalty=presence_penalty
if presence_penalty
else _config.presence_penalty,
)
PrintHelper.print_response(response=response)

Expand Down
13 changes: 10 additions & 3 deletions askai/entrypoint_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ def config() -> None:

@config.command(help="Reset the config to default")
def reset() -> None:
user_verification = input("Do you want to reset your config to the default values? [y/Y]? ")
user_verification = input(
"Do you want to reset your config to the default values? [y/Y]? "
)

if user_verification.lower() in ["y", "yes"]:
ConfigHelper().reset()
Expand All @@ -38,7 +40,10 @@ def update_all() -> None:
PrintHelper.model()
config_helper.input_model()

PrintHelper.step(step=2, description="SET NUMBER OF ALTERNATIVE ANSWERS GENERATED PER QUESTION")
PrintHelper.step(
step=2,
description="SET NUMBER OF ALTERNATIVE ANSWERS GENERATED PER QUESTION",
)
PrintHelper.num_answers()
config_helper.input_num_answer()

Expand Down Expand Up @@ -73,7 +78,9 @@ def model() -> None:
config_helper.update()


@update.command(help="Update number of altenative answers generated per question")
@update.command(
help="Update number of altenative answers generated per question"
)
def num_answers() -> None:
PrintHelper.num_answers()
config_helper = ConfigHelper.from_file()
Expand Down
2 changes: 1 addition & 1 deletion askai/entrypoint_init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import click

from .utils import KeyHelper, ConfigHelper, PrintHelper
from .utils import ConfigHelper, KeyHelper, PrintHelper


@click.command()
Expand Down
6 changes: 4 additions & 2 deletions askai/entrypoint_key.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import click

from .utils import KeyHelper, PrintHelper
from .constants import API_KEY_PATH
from .utils import KeyHelper, PrintHelper


@click.group()
Expand All @@ -27,7 +27,9 @@ def remove() -> None:
if not API_KEY_PATH.is_file():
PrintHelper.no_key()
else:
user_verification = input("Do you want to remove your API key? [y/Y]? ")
user_verification = input(
"Do you want to remove your API key? [y/Y]? "
)
if user_verification.lower() in ["y", "yes"]:
KeyHelper().remove()
else:
Expand Down
Loading