-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add support for univ endpoints in javelin sdk
- Loading branch information
javelin
authored and
javelin
committed
Feb 20, 2025
1 parent
a84d4df
commit 7addf8e
Showing
12 changed files
with
190 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import asyncio | ||
import json | ||
import os | ||
from typing import Any, Dict | ||
|
||
from javelin_sdk import JavelinClient, JavelinConfig | ||
|
||
|
||
# Helper function to pretty print responses | ||
def print_response(provider: str, response: Dict[str, Any]) -> None: | ||
print(f"=== Response from {provider} ===") | ||
print(json.dumps(response, indent=2)) | ||
|
||
|
||
# Setup client configuration | ||
config = JavelinConfig( | ||
base_url="https://api-dev.javelin.live", | ||
javelin_api_key=os.getenv("JAVELIN_API_KEY"), | ||
llm_api_key=os.getenv("OPENAI_API_KEY"), | ||
) | ||
client = JavelinClient(config) | ||
|
||
# Example messages in OpenAI format | ||
messages = [ | ||
{"role": "system", "content": "You are a helpful assistant."}, | ||
{"role": "user", "content": "What are the three primary colors?"}, | ||
] | ||
|
||
# Define the headers based on the curl command | ||
custom_headers = { | ||
"Content-Type": "application/json", | ||
"x-javelin-route": "openai_univ", | ||
"x-javelin-model": "gpt-4", | ||
"x-javelin-provider": "https://api.openai.com/v1", | ||
"x-api-key": os.getenv("JAVELIN_API_KEY"), # Use environment variable for security | ||
"Authorization": f"Bearer {os.getenv('OPENAI_API_KEY')}", # Use environment variable for security | ||
} | ||
|
||
|
||
async def main(): | ||
try: | ||
query_body = {"messages": messages, "temperature": 0.7} | ||
openai_response = await client.aquery_unified_endpoint( | ||
provider_name="openai", | ||
endpoint_type="chat", | ||
query_body=query_body, | ||
headers=custom_headers, | ||
) | ||
print_response("OpenAI", openai_response) | ||
except Exception as e: | ||
print(f"OpenAI query failed: {str(e)}") | ||
|
||
|
||
# Run the async function | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
from typing import List | ||
|
||
import httpx | ||
|
||
from javelin_sdk.exceptions import ( | ||
BadRequest, | ||
InternalServerError, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
from typing import List | ||
|
||
import httpx | ||
|
||
from javelin_sdk.exceptions import ( | ||
BadRequest, | ||
InternalServerError, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
from typing import List | ||
|
||
import httpx | ||
|
||
from javelin_sdk.exceptions import ( | ||
BadRequest, | ||
InternalServerError, | ||
|