Quickstart

Quickstart

The Seekr Python Library is the official Python client for SeekrFlow's API platform, providing a convenient way for interacting with the REST APIs and enabling easy integrations with Python 3.9+ applications with easy-to-use synchronous and asynchronous clients.

Installation

To install Seekr Python Library from pypi, simply run:

pip install --upgrade seekrai

Setting up API key

🚧

You will need to create an account with seekr.com to obtain a SeekrFlow API Key.

Setting environment variable

export SEEKR_API_KEY=your_api_key

Using the client

from seekrai import SeekrFlow

client = SeekrFlow(api_key="your_api_key")

This library contains both a python library and a CLI. We demonstrate how to use both below.

Usage: Python client

Chat completions

import os
from seekrai import SeekrFlow

client = SeekrFlow(api_key=os.environ.get("SEEKR_API_KEY"))

response = client.chat.completions.create(
    model="meta-llama/Meta-Llama-3-8B-Instruct",
    messages=[{"role": "user", "content": "tell me about new york"}],
)
print(response.choices[0].message.content)

Streaming

stream = client.chat.completions.create(
    model="meta-llama/Meta-Llama-3-8B-Instruct",
    messages=[{"role": "user", "content": "tell me about new york"}],
    stream=True,  # False by default
)

for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="", flush=True)

Async usage

import os, asyncio
from seekrai import AsyncSeekrFlow

messages = [
    "What are the top things to do in San Francisco?",
    "What country is Paris in?",
]

async def async_chat_completion(messages):
    async_client = AsyncSeekrFlow(api_key=os.environ.get("SEEKR_API_KEY"))
    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))