Skip to main content

Python client for Javelin

Project description

Javelin: an Enterprise-Scale, Fast LLM Gateway

Upload Python Package

This is the Python client package for Javelin.

For more information about Javelin, see https://getjavelin.io
Javelin Documentation: https://docs.getjavelin.io

Development

For local development, Please change version = "RELEASE_VERSION" with any semantic version example : version = "v0.1.10" in pyproject.toml

Make sure that the file pyproject.toml reverted before commit back to main

Installation

  pip install javelin_sdk

Quick Start

from javelin_sdk import (
    JavelinClient,
    JavelinConfig,
    Route,
    NetworkError,
    RouteNotFoundError,
    UnauthorizedError,
)

import os, sys

try:
    javelin_api_key = os.getenv('JAVELIN_API_KEY')
    javelin_virtualapikey = os.getenv('JAVELIN_VIRTUALAPIKEY') #optional
    llm_api_key = os.getenv("OPENAI_API_KEY")

    config = JavelinConfig(
        base_url="https://api-dev.javelin.live",
        javelin_api_key=javelin_api_key,
        javelin_virtualapikey=javelin_virtualapikey, #optional
        llm_api_key=llm_api_key,
    )
    client = JavelinClient(config)

    print('Successfully connected to Javelin Client')

except NetworkError as e:
    print("Failed to create client: Network Error")
    sys.exit()
except UnauthorizedError as e:
    print("Failed to create client: Unauthorized")
    sys.exit()

# Create a route object
route_data = {
    "name": "test_route_1",
    "type": "chat",
    "models": [
        {
            "name": "gpt-3.5-turbo",
            "enabled": True,
            "provider": "openai",
            "suffix": "/v1/chat/completions",
        }
    ],
    "config": {
        "archive": True,
        "organization": "myusers",
        "retries": 3,
        "rate_limit": 7,
    },
}

route = Route.parse_obj(route_data)
try:
    client.create_route(route)
except NetworkError as e:
    print("Failed to create route: Network Error")

query_data = {
    "model": "gpt-3.5-turbo",
    "messages": [
        {"role": "system", "content": "You are a helpful assistant that translates English to French."},
        {"role": "user", "content": "AI has the power to transform humanity and make the world a better place"},
    ],
    "temperature": 0.8,
}

# query the llm
try:
    response = client.query_route("test_route_1", query_data)
except RouteNotFoundError as e:
    print("Route Not Found")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

javelin_sdk-0.2.12.tar.gz (25.0 kB view hashes)

Uploaded Source

Built Distribution

javelin_sdk-0.2.12-py3-none-any.whl (32.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page