Skip to content

Commit

Permalink
Implement separate service classes for each major entity
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhijit L authored and Abhijit L committed Sep 26, 2024
1 parent 55bc920 commit c1d76df
Show file tree
Hide file tree
Showing 17 changed files with 1,515 additions and 1,787 deletions.
13 changes: 11 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
repos:
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 24.3.0
hooks:
- id: black
language_version: python3

- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: "v0.0.265"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/python-poetry/poetry
rev: "1.4.0" # add version here
hooks:
- id: poetry-check
- id: poetry-lock
- id: poetry-lock
8 changes: 5 additions & 3 deletions examples/aexample.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from dotenv import load_dotenv

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

load_dotenv()

import asyncio
import os
import json
import os

# Retrieve environment variables
javelin_api_key = os.getenv("JAVELIN_API_KEY")
Expand Down
35 changes: 20 additions & 15 deletions examples/example.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import json
import os

from javelin_sdk import (
GatewayNotFoundError,
JavelinClient,
JavelinConfig,
Gateway,
Provider,
Route,
NetworkError,
GatewayNotFoundError,
ProviderNotFoundError,
Route,
RouteNotFoundError,
UnauthorizedError,
)

import os
import json

# Retrieve environment variables
javelin_api_key = os.getenv("JAVELIN_API_KEY")
javelin_virtualapikey = os.getenv("JAVELIN_VIRTUALAPIKEY")
Expand All @@ -34,12 +32,15 @@ def pretty_print(obj):
except TypeError:
print(obj)


def handle_gateway(client):
"""
Start the example by cleaning up any pre-existing gateways.
Start the example by cleaning up any pre-existing gateways.
This is done by deleting the gateway if it exists.
"""
print("1. Start clean (by deleting pre-existing gateways): ", "test_sdk_gw_kensho_1")
print(
"1. Start clean (by deleting pre-existing gateways): ", "test_sdk_gw_kensho_1"
)
try:
client.delete_gateway("test_sdk_gw_kensho_1")
except GatewayNotFoundError as e:
Expand All @@ -49,7 +50,7 @@ def handle_gateway(client):
Create a gateway. This is done by creating a Gateway object and passing it to the
create_gateway method of the JavelinClient object.
"""
'''
"""
gateway_data = {
"name": "test_sdk_gw_kensho_1",
"type": "development",
Expand All @@ -70,7 +71,7 @@ def handle_gateway(client):
print("Failed to create gateway: Unauthorized")
except NetworkError as e:
print("Failed to create gateway: Network Error")
'''
"""

"""
List gateways. This is done by calling the list_gateways method of the JavelinClient object.
Expand All @@ -83,9 +84,10 @@ def handle_gateway(client):
except NetworkError as e:
print("Failed to list gateways: Network Error")


def handle_provider(client):
"""
Start the example by cleaning up any pre-existing providers.
Start the example by cleaning up any pre-existing providers.
This is done by deleting the provider if it exists.
"""
print("1. Start clean (by deleting pre-existing providers): ", "test_sdk_openai_1")
Expand All @@ -105,9 +107,10 @@ def handle_provider(client):
except NetworkError as e:
print("Failed to list providers: Network Error")


def handle_route(client):
"""
Start the example by cleaning up any pre-existing routes.
Start the example by cleaning up any pre-existing routes.
This is done by deleting the route if it exists.
"""
print("1. Start clean (by deleting pre-existing routes): ", "test_sdk_route_1")
Expand Down Expand Up @@ -182,14 +185,14 @@ def handle_route(client):
List routes. This is done by calling the list_routes method of the JavelinClient object.
"""
print("4. Listing routes")
'''
"""
try:
pretty_print(client.list_routes())
except UnauthorizedError as e:
print("Failed to list routes: Unauthorized")
except NetworkError as e:
print("Failed to list routes: Network Error")
'''
"""

print("5. Get Route: ", route.name)
try:
Expand Down Expand Up @@ -231,6 +234,7 @@ def handle_route(client):
except RouteNotFoundError as e:
print(e.message, e.response_data)


def main():
print("Javelin Synchronous Example Code")
"""
Expand All @@ -256,5 +260,6 @@ def main():
handle_provider(client)
handle_route(client)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion javelin_cli/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .cli import main

if __name__ == "__main__":
main()
main()
Loading

0 comments on commit c1d76df

Please sign in to comment.