-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjavelin_gemini_univ_endpoint.py
59 lines (48 loc) · 1.72 KB
/
javelin_gemini_univ_endpoint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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": "google_univ",
"x-javelin-model": "gemini-1.5-flash",
"x-javelin-provider": "https://generativelanguage.googleapis.com/v1beta/openai",
"x-api-key": os.getenv("JAVELIN_API_KEY"), # Use environment variable for security
"Authorization": f"Bearer {os.getenv('GEMINI_API_KEY')}", # Use environment variable for security
}
async def main():
try:
query_body = {
"messages": messages,
"temperature": 0.7,
"model": "gemini-1.5-flash",
}
gemini_response = await client.aquery_unified_endpoint(
provider_name="gemini",
endpoint_type="chat",
query_body=query_body,
headers=custom_headers,
)
print_response("Gemini", gemini_response)
except Exception as e:
print(f"Gemini query failed: {str(e)}")
# Run the async function
asyncio.run(main())