Python Client Library¶
Full documentation of the reka
python client library.
Generation¶
- reka.chat(human=None, media_url=None, media_filename=None, conversation_history=None, retrieval_dataset=None, model_name='reka-flash', request_output_len=None, temperature=None, random_seed=None, runtime_top_k=None, runtime_top_p=None, frequency_penalty=None, presence_penalty=None, length_penalty=None, stop_words=None, extra_request_args=None)¶
Chat endpoint.
Example usage:
import reka reka.API_KEY = "APIKEY" conversation_history = [ {"type": "human", "text": "Hi, my name is John."}, {"type": "model", "text": "Hi, I'm Reka's assistant."}, ] response = reka.chat( human="What was my name?", conversation_history=conversation_history, ) print(response) # {"type": "model", "text": "Your name is John.\n\n"}
- Parameters:
human (str | None) – latest message from human, this is optional if using
conversation_history
instead.media_url (str | None) – an optional URL for the media (image, video, or audio) to chat about. This may only be set for the first turn (when conversation_history is empty). You can also send base64 media in the format data:image/{image_format};base64,{base64_image}
media_filename (str | None) – alternative to the
media_url
parameter, the location of a local file.``conversation_history (List[HumanTurn | ModelTurn] | None) – list of dicts, where each dict has a key “type” indicating the speaker, either “human” or “model”, and a key “text” containing the message from the speaker. If not set, will default to an empty history. The first turn may also have “media_url” set.
retrieval_dataset (str | None) – Previously uploaded dataset to do retrieval on.
model_name (str) – Name of model. You can check available models with
reka.get_models()
. Defaults to flash.request_output_len (int | None) – Completion length in tokens.
temperature (float | None) – Softmax temperature, higher is more diverse.
random_seed (int | None) – Seed to obtain different results.
runtime_top_k (int | None) – Keep only k top tokens when sampling.
runtime_top_p (float | None) – Keep only top p quantile when sampling.
frequency_penalty (float | None) – Penalize repetitions. 0 means no penalty.
presence_penalty (float | None) – Penalize repetitions. 0 means no penalty.
length_penalty (float | None) – Penalize short answers. 1 means no penalty.
stop_words (List[str] | None) – Optional list of words on which to stop generation.
extra_request_args (Dict[str, Any] | None) – Optional extra arguments to include in the request, useful for experimental API features.
- Raises:
InvalidConversationError – if the conversation history is not valid.
- Returns:
- Return type:
ModelTurn
A dict containing
{"type": "model", "text": <response from the model>}
. Ifretrieval_dataset
is set, then this will also contain"retrieved_chunks"
. :rtype: ModelTurn
Datasets¶
Details of valid dataset formats are given in Dataset format.
- reka.add_dataset(filepath, name, description=None)¶
Upload a dataset to run jobs on it later.
NOTE: If the
name
is deemed inappropriate by the server, e.g. “../../etc/shadow”, it will be changed to a secure name, which is returned in the response.- Parameters:
filepath (str) – str, local path to a text file or a zipped collection of text files.
name (str) – str, what should the dataset be called
description (str | None) – Optional[str], optional metadata description
- Returns:
Dictionary object representing what happened with the uploaded file.
- Return type:
Dict[str, Any]
- reka.list_datasets()¶
List all datasets available to the user of the
API_KEY
.- Returns:
List of dataset names.
- Return type:
List[str]
- reka.delete_dataset(name)¶
Delete a dataset with a given name for the user of this API_KEY.
- Parameters:
name (str) – name of the dataset to delete.
- Return type:
Dict[str, Any]
Returns: Dictionary object with keys
name
(str, the dataset name),ok
(bool•), and ``info`` (*str).
Retrieval¶
See the guide on retrieval for more information.
- reka.prepare_retrieval(dataset_name)¶
Prepare dataset_name for retrieval later, creating a
prepare-retrieval
job.- Parameters:
dataset_name (str) – name of previously uploaded dataset to prepare for retrieval
- Raises:
RetrievalError if there is something wrong with retrieval preparation, e.g. –
no such dataset uploaded, or retrieval already prepared –
- Returns:
ID of the
prepare-retrieval
job, to be used for tracking.- Return type:
str
- reka.retrieval_job_status(job_id)¶
Given a prepare retrieval job id, check the status.
- Parameters:
job_id (str) – id of the
prepare-retrieval
job.- Returns:
The current state of the job.
- Return type:
- class reka.PrepareRetrievalStatusResponse(job_status, detail, history)¶
Status of a
prepare-retrieval
job.- Parameters:
job_status (JobStatus) – The current status.
detail (str) – Further details, if any.
history (List[Dict[str, Any]])
- is_complete()¶
Whether the job has completed successfully.
- Return type:
bool
- is_done()¶
Whether the job has completed, either succesfully or with an error.
- Return type:
bool
- is_error()¶
Whether the job has ended with an error.
- Return type:
bool
- is_running()¶
Whether the job is still running.
- Return type:
bool