Welcome to aleph-alpha-client’s documentation!
Python client for the Aleph Alpha API.
Usage
Synchronous client.
from aleph_alpha_client import Client, CompletionRequest, Prompt
import os
client = Client(token=os.getenv("AA_TOKEN"))
prompt = Prompt.from_text("Provide a short description of AI:")
request = CompletionRequest(prompt=prompt, maximum_tokens=20)
result = client.complete(request, model="luminous-extended")
print(result.completions[0].completion)
Synchronous client with prompt containing an image.
from aleph_alpha_client import Client, CompletionRequest, PromptTemplate, Image
import os
client = Client(token=os.getenv("AA_TOKEN"))
image = Image.from_file("path-to-an-image")
prompt_template = PromptTemplate("{{image}}This picture shows ")
prompt = prompt_template.to_prompt(image=prompt_template.placeholder(image))
request = CompletionRequest(prompt=prompt, maximum_tokens=20)
result = client.complete(request, model="luminous-extended")
print(result.completions[0].completion)
Asynchronous client.
import os
from aleph_alpha_client import AsyncClient, CompletionRequest, Prompt
# Can enter context manager within an async function
async with AsyncClient(token=os.environ["AA_TOKEN"]) as client:
request = CompletionRequest(
prompt=Prompt.from_text("Request"),
maximum_tokens=64,
)
response = await client.complete(request, model="luminous-base")
- aleph_alpha_client
- aleph_alpha_client package
- Module contents
AsyncClient
BatchSemanticEmbeddingRequest
BatchSemanticEmbeddingResponse
BusyError
Client
CompletionRequest
CompletionResponse
ControlTokenOverlap
CustomGranularity
DetokenizationRequest
DetokenizationResponse
Document
EmbeddingRequest
EmbeddingResponse
EvaluationRequest
EvaluationResponse
Explanation
ExplanationPostprocessing
ExplanationRequest
ExplanationResponse
Image
ImageControl
ImagePromptItemExplanation
ImageScore
Prompt
PromptGranularity
PromptTemplate
QaRequest
QaResponse
QuotaError
SemanticEmbeddingRequest
SemanticEmbeddingResponse
SemanticRepresentation
SummarizationRequest
SummarizationResponse
TargetGranularity
TargetPromptItemExplanation
TargetScore
Text
TextControl
TextPromptItemExplanation
TextScore
TokenControl
TokenPromptItemExplanation
TokenScore
TokenizationRequest
TokenizationResponse
Tokens
load_base64_from_file()
load_base64_from_url()
- Module contents
- aleph_alpha_client package