diff --git a/README.md b/README.md index 1d89c68..45df4ad 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ async with AsyncClient(token=os.environ["AA_TOKEN"]) as client: prompt=Prompt.from_text("Provide a short description of AI:"), maximum_tokens=64, ) - response = await client.complete(request, model="luminous-base") + response = await client.complete(request, model="luminous-base") print(response.completions[0].completion) ``` @@ -66,6 +66,27 @@ pip install aleph-alpha-client Get started using the client by first [creating an account](https://app.aleph-alpha.com/signup). Afterwards head over to [your profile](https://app.aleph-alpha.com/profile) to create an API token. Read more about how you can manage your API tokens [here](https://docs.aleph-alpha.com/docs/account). +## Development + +For local development, start by creating a Python virtual environment as follows: + +``` +python3 -m venv venv +. ./venv/bin/activate +``` + +Next, install the `test` and `dev` dependencies: + +``` +pip install -e ".[test,dev]" +``` + +Now you should be able to ... + +* run all the tests using `pytest` or, `pytest -k ` to run a specific test +* typecheck the code and tests using `mypy aleph_alpha_client` resp. `mypy tests` +* format the code using `black .` + ## Links - [HTTP API Docs](https://docs.aleph-alpha.com/api/) diff --git a/aleph_alpha_client/aleph_alpha_client.py b/aleph_alpha_client/aleph_alpha_client.py index 7e1cc34..f3f0231 100644 --- a/aleph_alpha_client/aleph_alpha_client.py +++ b/aleph_alpha_client/aleph_alpha_client.py @@ -149,7 +149,7 @@ def __init__( request_timeout_seconds: int = DEFAULT_REQUEST_TIMEOUT, total_retries: int = 8, nice: bool = False, - verify_ssl = True, + verify_ssl=True, ) -> None: if host[-1] != "/": host += "/" @@ -625,7 +625,7 @@ def __init__( request_timeout_seconds: int = DEFAULT_REQUEST_TIMEOUT, total_retries: int = 8, nice: bool = False, - verify_ssl = True, + verify_ssl=True, ) -> None: if host[-1] != "/": host += "/" @@ -652,7 +652,7 @@ def __init__( "User-Agent": "Aleph-Alpha-Python-Client-" + aleph_alpha_client.__version__, }, - connector=connector + connector=connector, ) async def close(self): diff --git a/tests/test_clients.py b/tests/test_clients.py index 10da424..6f454ba 100644 --- a/tests/test_clients.py +++ b/tests/test_clients.py @@ -33,7 +33,12 @@ def test_nice_flag_on_client(httpserver: HTTPServer): ).respond_with_json( CompletionResponse( "model_version", - [CompletionResult(log_probs=[], completion="foo", )], + [ + CompletionResult( + log_probs=[], + completion="foo", + ) + ], num_tokens_prompt_total=2, num_tokens_generated=1, ).to_json() diff --git a/tests/test_complete.py b/tests/test_complete.py index a248ced..82a9a9a 100644 --- a/tests/test_complete.py +++ b/tests/test_complete.py @@ -128,28 +128,30 @@ def test_complete_with_echo(sync_client: Client, model_name: str, prompt_image: assert completion_result.log_probs is not None assert len(completion_result.log_probs) > 0 + @pytest.mark.system_test def test_num_tokens_prompt_total_with_best_of(sync_client: Client, model_name: str): - tokens = [49222, 2998] # Hello world + tokens = [49222, 2998] # Hello world best_of = 2 request = CompletionRequest( - prompt = Prompt.from_tokens(tokens), - best_of = best_of, - maximum_tokens = 1, + prompt=Prompt.from_tokens(tokens), + best_of=best_of, + maximum_tokens=1, ) response = sync_client.complete(request, model=model_name) assert response.num_tokens_prompt_total == len(tokens) * best_of + @pytest.mark.system_test def test_num_tokens_generated_with_best_of(sync_client: Client, model_name: str): - hello_world = [49222, 2998] # Hello world + hello_world = [49222, 2998] # Hello world best_of = 2 request = CompletionRequest( - prompt = Prompt.from_tokens(hello_world), - best_of = best_of, - maximum_tokens = 1, - tokens = True, + prompt=Prompt.from_tokens(hello_world), + best_of=best_of, + maximum_tokens=1, + tokens=True, ) response = sync_client.complete(request, model=model_name) @@ -157,4 +159,4 @@ def test_num_tokens_generated_with_best_of(sync_client: Client, model_name: str) assert completion_result.completion_tokens is not None number_tokens_completion = len(completion_result.completion_tokens) - assert response.num_tokens_generated == best_of * number_tokens_completion \ No newline at end of file + assert response.num_tokens_generated == best_of * number_tokens_completion diff --git a/tests/test_error_handling.py b/tests/test_error_handling.py index 485f27e..783fb72 100644 --- a/tests/test_error_handling.py +++ b/tests/test_error_handling.py @@ -111,7 +111,13 @@ def expect_retryable_error( def expect_valid_completion(httpserver: HTTPServer) -> None: httpserver.expect_ordered_request("/complete").respond_with_json( - {"model_version": "1", "completions": [], "num_tokens_prompt_total": 0, "num_tokens_generated": 0}) + { + "model_version": "1", + "completions": [], + "num_tokens_prompt_total": 0, + "num_tokens_generated": 0, + } + ) def expect_valid_version(httpserver: HTTPServer) -> None: diff --git a/tests/test_evaluate.py b/tests/test_evaluate.py index 247c732..c6f6f6b 100644 --- a/tests/test_evaluate.py +++ b/tests/test_evaluate.py @@ -30,7 +30,6 @@ async def test_can_evaluate_with_async_client( @pytest.mark.system_test def test_evaluate(sync_client: Client, model_name: str): - request = EvaluationRequest( prompt=Prompt.from_text("hello"), completion_expected="world" ) diff --git a/tests/test_prompt_template.py b/tests/test_prompt_template.py index 36d8de1..db3e307 100644 --- a/tests/test_prompt_template.py +++ b/tests/test_prompt_template.py @@ -164,11 +164,12 @@ def test_to_prompt_works_with_tokens(): assert prompt == user_prompt + def test_to_prompt_resets_cache(prompt_image: Image): user_prompt = Prompt([prompt_image, Text.from_text("Cool"), prompt_image]) - + template = PromptTemplate("{{user_prompt}}") template.to_prompt(user_prompt=template.embed_prompt(user_prompt)) - assert template.non_text_items == {} + assert template.non_text_items == {} diff --git a/tests/test_wildcard_import.py b/tests/test_wildcard_import.py index fe9fffd..552df54 100644 --- a/tests/test_wildcard_import.py +++ b/tests/test_wildcard_import.py @@ -1,4 +1,5 @@ from aleph_alpha_client import * + def test_should_be_able_to_import_with_wildcard(): - pass # Wildcard import can not go into the test itself \ No newline at end of file + pass # Wildcard import can not go into the test itself