Quickstart
Quickstart Guide: Setting Up SeekrFlow API and SDK
The Seekr Python Library is the official Python client for SeekrFlow's API platform. It provides a seamless way to interact with REST APIs, allowing for easy integration into Python 3.9+ applications with both synchronous and asynchronous support.
This guide will walk you through every step of setting up SeekrFlow, from installation to running your first API call. Let’s get started!
To use the Seekr Python Library, you first need to install it via PyPI. Follow these steps:
- Open your terminal or command prompt.
- Run the following command to install the library:
pip install --upgrade seekrai
This command ensures that you have the latest version of the library.
Tip: If you encounter any errors, ensure you have Python 3.9 or higher installed. You can verify your Python version with:
python --version
If your Python version is outdated, update it from Python.org.
-
Setting Up Your SeekrFlow API Key
To use the SeekrFlow platform, you'll first need to create a Seekr account.
Step 1: Create an Account
- Go to Seekr.com and create an account.
- Once your account is created, email [email protected] to obtain an API key.
- Seekr will generate a new API key. Check your email for the key.
Step 2: Store Your API Key
For security, store your API key as an environment variable. Here’s how:
- Open Terminal on your computer.
- Run the following command, replacing
your_api_key
with the key you generated:
export SEEKR_API_KEY=your_api_key
Windows Users:If you are on Windows, use the set
command instead:
set SEEKR_API_KEY=your_api_key
- Confirm the variable is set by running:
echo $SEEKR_API_KEY
(or echo %SEEKR_API_KEY%
on Windows).
Once your API key is set, you’re ready to use the Python client.
Step 1: Import the Library
Start by importing the SeekrFlow
client in your Python script:
from seekrai import SeekrFlow
client = SeekrFlow(api_key="your_api_key")
Or, if you’ve set the environment variable:
import os
from seekrai import SeekrFlow
client = SeekrFlow(api_key=os.environ.get("SEEKR_API_KEY"))
Step 2: Make Your First API Call
Let’s make a simple request to the chat.completions
endpoint:
response = client.chat.completions.create(
model="meta-llama/Meta-Llama-3-8B-Instruct",
messages=[{"role": "user", "content": "What is SeekrFlow?"}],
)
print(response.choices[0].message.content)
This will return a response containing the AI’s answer.
Streaming allows you to receive responses in chunks, useful for real-time applications.
stream = client.chat.completions.create(
model="meta-llama/Meta-Llama-3-8B-Instruct",
messages=[{"role": "user", "content": "Tell me about New York"}],
stream=True, # Enables streaming
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="", flush=True)
Tip: Use flush=True
to ensure the output is displayed in real-time.
The Seekr Python Library also supports asynchronous usage for handling multiple requests efficiently.
Step 1: Import the Asynchronous Client
import os, asyncio
from seekrai import AsyncSeekrFlow
async_client = AsyncSeekrFlow(api_key=os.environ.get("SEEKR_API_KEY"))
Step 2: Run Multiple Requests
Here’s an example of running multiple chat completions concurrently:
messages = [
"What are the top things to do in San Francisco?",
"What country is Paris in?",
]
async def async_chat_completion(messages):
tasks = [
async_client.chat.completions.create(
model="meta-llama/Meta-Llama-3-8B-Instruct",
messages=[{"role": "user", "content": message}],
)
for message in messages
]
responses = await asyncio.gather(*tasks)
for response in responses:
print(response.choices[0].message.content)
asyncio.run(async_chat_completion(messages))
The Seekr Python Library also includes a command-line interface (CLI) for quick testing and automation.
Step 1: Ensure Installation
Ensure you have installed the library as described earlier.
Step 2: Run CLI Commands
For example, to test a simple chat completion:
seekr chat-completions create --model "meta-llama/Meta-Llama-3-8B-Instruct" --message "Tell me about SeekrFlow"
Refer to the CLI documentation for additional commands and options.
Invalid API Key: Ensure your API key is correctly set in the environment variable.
Connection Errors: Check your internet connection and firewall settings.
Python Version Issues: Ensure Python 3.9+ is installed and set as the default version.
By following these detailed steps, you’ll be able to set up and start using SeekrFlow with ease. For further assistance, refer to the full documentation or contact support.
Updated about 20 hours ago