Skip to content

Commit

Permalink
drop default api url for host of clients
Browse files Browse the repository at this point in the history
  • Loading branch information
fgebhart committed Dec 4, 2024
1 parent abdd78f commit b020bd7
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
TEST_API_URL=https://test.api.aleph-alpha.com
TEST_API_URL=https://inference-api.your-domain.com
TEST_TOKEN=
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ jobs:
run: |
poetry run pytest
env:
TEST_API_URL: https://api.aleph-alpha.com
TEST_API_URL: ${{ secrets.TEST_API_URL }}
TEST_TOKEN: ${{ secrets.AA_API_TOKEN }}
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 8.0.0

- Remove default value for `host` parameter in `Client` and `AsyncClient`. Passing a value for
the `host` is now required.

## 7.6.0

- Add `instructable_embed` to `Client` and `AsyncClient`
Expand Down
4 changes: 2 additions & 2 deletions Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ Tests can be run using pytest. Make sure to create a `.env` file with the follow

```env
# test settings
TEST_API_URL=https://test.api.aleph-alpha.com
TEST_API_URL=https://inference-api.your-domain.com
TEST_TOKEN=your_token
```

Instead of a token username and password can be used.

```env
# test settings
TEST_API_URL=https://api.aleph-alpha.com
TEST_API_URL=https://inference-api.your-domain.com
TEST_USERNAME=your_username
TEST_PASSWORD=your_password
```
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ from aleph_alpha_client import Client, CompletionRequest, Prompt
client = Client(token=os.getenv("AA_TOKEN"))
request = CompletionRequest(
prompt=Prompt.from_text("Provide a short description of AI:"),
host="https://inference-api.your-domain.com",
maximum_tokens=64,
)
response = client.complete(request, model="luminous-extended")
response = client.complete(request, model="pharia-1-llm-7b-control")

print(response.completions[0].completion)
```
Expand All @@ -38,9 +39,10 @@ from aleph_alpha_client import AsyncClient, CompletionRequest, Prompt
async with AsyncClient(token=os.environ["AA_TOKEN"]) as client:
request = CompletionRequest(
prompt=Prompt.from_text("Provide a short description of AI:"),
host="https://inference-api.your-domain.com",
maximum_tokens=64,
)
response = client.complete_with_streaming(request, model="luminous-base")
response = client.complete_with_streaming(request, model="pharia-1-llm-7b-control")

async for stream_item in response:
print(stream_item)
Expand Down
19 changes: 10 additions & 9 deletions aleph_alpha_client/aleph_alpha_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class Client:
token (string, required):
The API token that will be used for authentication.
host (string, required, default "https://api.aleph-alpha.com"):
host (string, required):
The hostname of the API host.
hosting(string, optional, default None):
Expand Down Expand Up @@ -164,16 +164,16 @@ class Client:
Example usage:
>>> request = CompletionRequest(
prompt=Prompt.from_text(f"Request"), maximum_tokens=64
prompt=Prompt.from_text(f"Request"), host="https://inference-api.your-domain.com", maximum_tokens=64
)
>>> client = Client(token=os.environ["AA_TOKEN"])
>>> response: CompletionResponse = client.complete(request, "luminous-base")
>>> response: CompletionResponse = client.complete(request, "pharia-1-llm-7b-control")
"""

def __init__(
self,
token: str,
host: str = "https://api.aleph-alpha.com",
host: str,
hosting: Optional[str] = None,
request_timeout_seconds: int = DEFAULT_REQUEST_TIMEOUT,
total_retries: int = 8,
Expand Down Expand Up @@ -706,7 +706,7 @@ class AsyncClient:
token (string, required):
The API token that will be used for authentication.
host (string, required, default "https://api.aleph-alpha.com"):
host (string, required):
The hostname of the API host.
hosting(string, optional, default None):
Expand Down Expand Up @@ -740,15 +740,17 @@ class AsyncClient:
Internal feature.
Example usage:
>>> request = CompletionRequest(prompt=Prompt.from_text(f"Request"), maximum_tokens=64)
>>> request = CompletionRequest(
prompt=Prompt.from_text(f"Request"), host="https://inference-api.your-domain.com", maximum_tokens=64
)
>>> async with AsyncClient(token=os.environ["AA_TOKEN"]) as client:
response: CompletionResponse = await client.complete(request, "luminous-base")
response: CompletionResponse = await client.complete(request, "pharia-1-llm-7b-control")
"""

def __init__(
self,
token: str,
host: str = "https://api.aleph-alpha.com",
host: str,
hosting: Optional[str] = None,
request_timeout_seconds: int = DEFAULT_REQUEST_TIMEOUT,
total_retries: int = 8,
Expand Down Expand Up @@ -846,7 +848,6 @@ async def _post_request(
json_body = self._build_json_body(request, model)

query_params = self._build_query_parameters()

async with self.session.post(
self.host + endpoint, json=json_body, params=query_params
) as response:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "aleph-alpha-client"
version = "7.6.0"
version = "8.0.0"
description = "python client to interact with Aleph Alpha api endpoints"
authors = ["Aleph Alpha <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def model_name() -> str:

@pytest.fixture(scope="session")
def chat_model_name() -> str:
return "llama-3.1-70b-instruct"
return "llama-3.1-8b-instruct"


@pytest.fixture(scope="session")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async def test_can_instructable_embed_with_async_client(
)

response = await async_client.instructable_embed(
request, model="Pharia-1-Embedding-4608-control"
request, model="pharia-1-embedding-4608-control"
)
assert response.model_version is not None
assert response.embedding
Expand Down Expand Up @@ -239,7 +239,7 @@ def test_embed_instructable(sync_client: Client):
)

result = sync_client.instructable_embed(
request=request, model="Pharia-1-Embedding-4608-control"
request=request, model="pharia-1-embedding-4608-control"
)

assert result.model_version is not None
Expand Down
1 change: 0 additions & 1 deletion tests/test_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ async def test_can_qa_with_async_client(async_client: AsyncClient):
query="Who likes pizza?",
documents=[Document.from_text("Andreas likes pizza.")],
)

response = await async_client.qa(request)
assert len(response.answers) == 1
assert response.answers[0].score > 0.0
Expand Down

0 comments on commit b020bd7

Please sign in to comment.