Skip to main content

Python Client for the Liquid API

📦 Installation

pip install -U liquidai

OpenAI compatible API

For openai and langchain compatible apis like /chat/completions and /embeddings.

Examples:

💬 Other liquid api endpoints

For retrieval augmentation enabled liquidai api endpoints like /complete with files as arguments.

To access these APIs you need to set the environment variables LIQUID_URL and LIQUID_API_KEY to the UR and your API key of your Liquid AI subscription respectively. You can find your API key in the profile tab of the Liquid platform (left bottom icon in the navigation bar).

🔐 API Keys The most secure way to set the environment variables, which the Liquid client will automatically use.

export LIQUID_URL="https://labs.liquid.ai/api/v1"
export LIQUID_API_KEY="9cba1....."

Alternatively, you can also pass the base_url and api_key parameters to the Client constructor.

# Create a client object with the API URL and API key
client = Client()
print("Models: ", client.list_models()) # List all models
# Create a conversation with the model (a list of messages)
chat = [{"role": "user", "content": "Hello world in python!"}]
response = client.complete(chat)
print(f"Response: {response['message']['content']}")

Output:

>>> Models:  ['liquid-beacon-1.0']
>>> Response: Here is how to code a Hello World program in Python: print("Hello, world!")

Multi-turn conversations:

chat.append(response["message"]) # add assistant message to conversation
chat.append({"role": "user", "content": "And in C++?"})
response = client.complete(chat)
print(f"Response: {response['message']['content']}")

Output:

>>> #include <iostream>
>>> 
>>> int main() {
>>>     std::cout << "Hello, World!" << std::endl;
>>>     return 0;
>>> }

📚 Adding Knowledge Bases to the Model

# Let's create an example knowledge base
test_file = "test.txt"
with open(test_file, "w") as f:
    f.write("The name of the CEO of Liquid is Ramin Hasani.")
# Upload the file to the server
response = client.upload_file(test_file)
print(f"Uploaded {test_file} to {response['filename']}")
files = client.list_files()
print(f"Files: {files}")

Output:

>>> Uploaded test.txt to text.txt
>>> Files: ['text.txt']

Next we can tell the model to use the document we just uploaded:

chat = [
    {"role": "user", "content": "Who is the CEO of Liquid?", "files": ["test.txt"]}
]
response = client.complete(chat)
print(f"Response: {response['message']['content']}")

Output:

>>> Response: The CEO of Liquid is Ramin Hasani.

Removing files: Finally we can delete the file from the server:

client.delete_file(test_file)
print(f"Deleted {test_file}")

files = client.list_files()
print(f"Files: {files}")

Output:

>>> Deleted test.txt
>>> Files: []

📌 Full Examples

Release files for liquidai 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for liquidai 1.0.1
File Size Uploaded
liquidai-1.0.1.tar.gz 13.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for liquidai 1.0.1
File Interpreter ABI Platform
liquidai-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 26.1 kB

Release files / liquidai-1.0.1.tar.gz

Download URL liquidai-1.0.1.tar.gz
Size 13.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e287d6a8e95aae8ab33fd4743a1950e909e000f8d5868be6f93eae8d3aab8b1e
BLAKE2b-256 checksum
How to use checksums
38b589673e87aa6177b3a41c19c55faa792d7d69eaf8b557f342087cc6279f4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / liquidai-1.0.1-py3-none-any.whl

Download URL liquidai-1.0.1-py3-none-any.whl
Size 12.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df1a7e22d8bb233460683ebf9dffd12c79e95e4cf89a923a3ee0951aa5917c72
BLAKE2b-256 checksum
How to use checksums
2b8c28219d52437fb36d36470d7dcc31b93aeeb41b8871499c76c9583b039a61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page