Python client for Javelin
Project description
Javelin: an Enterprise-Scale, Fast LLM Gateway
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
Release history Release notifications | RSS feed
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)
Built Distribution
Close
Hashes for javelin_sdk-0.2.12-py3-none-any.whl
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 | cf1594cb5d9ca046249fa9dda2bee049633265ad0c3fef86c27c0f583687646f |
|
| MD5 | a19e8d72c54f88b2f32865cf484dc74c |
|
| BLAKE2b-256 | e0f82ed1bbf9c08b0f68dac17b04495514db6efcca45f2f9f005ed132afe7ce2 |