Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Max tokens optional #178

Merged
merged 5 commits into from
Aug 13, 2024
Merged
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
5 changes: 1 addition & 4 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
# We currently only support up to python 3.11
# because aiohttp does not support 3.12 as of yet.
# 3.7 because Google Colab uses 3.7 by default.
python-version: [3.7, 3.11]
python-version: [3.8, 3.12]

steps:
- uses: actions/checkout@v4
Expand Down
11 changes: 11 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 7.3.0

- Maximum token attribute of `CompletionRequest` defaults to None

## 7.2.0

### Python support

- Minimal supported Python version is now 3.8
- Dependency `aiohttp` is specified to be at least of version `3.10`.

## 7.1.0

- Introduce support for internal feature 'tags'
Expand Down
3 changes: 3 additions & 0 deletions aleph_alpha_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
"ImageControl",
"ImagePromptItemExplanation",
"ImageScore",
"load_base64_from_file",
"load_base64_from_url",
"POOLING_OPTIONS",
"Prompt",
"PromptTemplate",
Expand All @@ -102,4 +104,5 @@
"TokenPromptItemExplanation",
"Tokens",
"TokenScore",
"__version__",
]
4 changes: 0 additions & 4 deletions aleph_alpha_client/aleph_alpha_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
Optional,
Dict,
Sequence,
Tuple,
Type,
Union,
Iterator,
)
import aiohttp
import asyncio
Expand All @@ -29,8 +27,6 @@
from aleph_alpha_client.explanation import (
ExplanationRequest,
ExplanationResponse,
ExplanationRequest,
ExplanationResponse,
)
from aleph_alpha_client.summarization import SummarizationRequest, SummarizationResponse
from aleph_alpha_client.qa import QaRequest, QaResponse
Expand Down
8 changes: 5 additions & 3 deletions aleph_alpha_client/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ class CompletionRequest:
Unconditional completion can be started with an empty string (default).
The prompt may contain a zero shot or few shot task.

maximum_tokens (int, optional, default 64):
maximum_tokens (int, optional, default None):
The maximum number of tokens to be generated.
Completion will terminate after the maximum number of tokens is reached. Increase this value to generate longer texts.
A text is split into tokens. Usually there are more tokens than words.
The maximum supported number of tokens depends on the model (for luminous-base, it may not exceed 2048 tokens).
The prompt's tokens plus the maximum_tokens request must not exceed this number.
The prompt's tokens plus the maximum_tokens request must not exceed this number. If set to None, the model will stop
generating tokens either if it outputs a sequence specified in `stop_sequences` or if it reaches its technical limit.
For most models, this means that the sum of input and output tokens is equal to its context window.

temperature (float, optional, default 0.0)
A higher sampling temperature encourages the model to produce less probable outputs ("be more creative"). Values are expected in a range from 0.0 to 1.0. Try high values (e.g. 0.9) for a more "creative" response and the default 0.0 for a well defined and repeatable answer.
Expand Down Expand Up @@ -181,7 +183,7 @@ class CompletionRequest:
"""

prompt: Prompt
maximum_tokens: int = 64
maximum_tokens: Optional[int] = None
temperature: float = 0.0
top_k: int = 0
top_p: float = 0.0
Expand Down
2 changes: 1 addition & 1 deletion aleph_alpha_client/detokenization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass, asdict
from typing import Any, Dict, List, Mapping, Optional, Sequence
from typing import Any, Dict, Mapping, Sequence


@dataclass(frozen=True)
Expand Down
3 changes: 0 additions & 3 deletions aleph_alpha_client/explanation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
Union,
)

# Import Literal with Python 3.7 fallback
from typing_extensions import Literal

from aleph_alpha_client import Text

from aleph_alpha_client.prompt import ControlTokenOverlap, Image, Prompt, PromptItem
Expand Down
3 changes: 1 addition & 2 deletions aleph_alpha_client/prompt_template.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from re import finditer
import re
from typing import Dict, Iterable, Mapping, NewType, Sequence, Tuple, Union
from typing import Dict, Iterable, Mapping, NewType, Tuple, Union
from uuid import UUID, uuid4
from liquid import Template

Expand Down
2 changes: 1 addition & 1 deletion aleph_alpha_client/qa.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import asdict, dataclass
from typing import Any, Dict, Mapping, Optional, Sequence
from typing import Any, Mapping, Optional, Sequence

from aleph_alpha_client.document import Document

Expand Down
2 changes: 1 addition & 1 deletion aleph_alpha_client/summarization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import asdict, dataclass
from typing import Any, Dict, Mapping, Sequence
from typing import Any, Mapping

from aleph_alpha_client.document import Document

Expand Down
4 changes: 2 additions & 2 deletions aleph_alpha_client/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "7.1.0"
MIN_API_VERSION = "1.16.0"
__version__ = "7.3.0"
MIN_API_VERSION = "1.17.0"
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def version():
install_requires=[
"requests >= 2.28",
"urllib3 >= 1.26",
"aiohttp >= 3.8.6",
"aiodns >= 3.0.0",
"aiohttp >= 3.10.2",
"aiodns >= 3.2.0",
"aiohttp-retry >= 2.8.3",
"tokenizers >= 0.13.2",
"typing_extensions >= 4.5.0",
Expand Down
16 changes: 12 additions & 4 deletions tests/test_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
)


# AsyncClient


@pytest.mark.system_test
async def test_can_complete_with_async_client(
async_client: AsyncClient, model_name: str
Expand All @@ -35,7 +32,18 @@ async def test_can_complete_with_async_client(
assert response.model_version is not None


# Client
@pytest.mark.system_test
def test_complete_maximum_tokens_none(sync_client: Client, model_name: str):
request = CompletionRequest(
prompt=Prompt.from_text("Hello, World!"),
maximum_tokens=None,
stop_sequences=[","],
)

response = sync_client.complete(request, model=model_name)
assert len(response.completions) == 1
assert response.completions[0].completion is not None
assert len(response.completions[0].completion) < 100


@pytest.mark.system_test
Expand Down
Loading