Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/azure-openai/azure-universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def initialize_client():
print("AZURE_OPENAI_API_KEY found.")

# Create the Azure client
azure_client = AzureOpenAI(api_version="2023-09-15-preview")
azure_client = AzureOpenAI(api_version="2023-09-15-preview", base_url="")

# Initialize the Javelin client and register the Azure client
config = JavelinConfig(javelin_api_key=javelin_api_key)
Expand Down
5 changes: 4 additions & 1 deletion examples/bedrock/bedrock_client_universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def init_bedrock():
)
javelin_client = JavelinClient(config)
javelin_client.register_bedrock(
bedrock_runtime_client=bedrock_runtime_client, bedrock_client=bedrock_client
bedrock_runtime_client=bedrock_runtime_client,
bedrock_client=bedrock_client,
bedrock_session=None,
route_name="amazon",
)
return bedrock_runtime_client

Expand Down
17 changes: 10 additions & 7 deletions examples/bedrock/bedrock_general_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ def get_bedrock_client():
aws_secret_access_key = os.getenv("AWS_SECRET_ACCESS_KEY", "YOUR_SECRET_KEY")
bedrock_api_key = os.getenv("JAVELIN_API_KEY", "YOUR_BEDROCK_API_KEY")

custom_headers = {"x-javelin-apikey": bedrock_api_key}
custom_headers = {
"x-javelin-apikey": bedrock_api_key,
"x-javelin-route": "amazon",
}

client = boto3.client(
service_name="bedrock-runtime",
Expand Down Expand Up @@ -115,15 +118,15 @@ def call_bedrock_model_invoke(client, route_name, input_text):
# -------------------------------


def call_bedrock_model_converse(client, route_name, user_topic):
def call_bedrock_model_converse(client, model_id, user_topic):
"""
Non-streaming call.
Roles must be 'user' or 'assistant'. The user role includes the required
prompt structure.
"""
try:
response = client.converse(
modelId=route_name,
modelId=model_id,
messages=[
{
"role": "user",
Expand Down Expand Up @@ -167,10 +170,10 @@ def main():
# 2) Invoke (non-streaming)
print("\n--- Bedrock: Invoke (non-streaming) ---")
try:
route_invoke = "claude_haiku_invoke" # Adjust if your route name differs
model_id = "anthropic.claude-v2" # Adjust if your route name differs
input_text_invoke = "sunset on a winter evening"
raw_invoke_output = call_bedrock_model_invoke(
bedrock_client, route_invoke, input_text_invoke
bedrock_client, model_id, input_text_invoke
)
final_invoke_text = extract_final_text(raw_invoke_output)
print(final_invoke_text)
Expand All @@ -180,10 +183,10 @@ def main():
# 3) Converse (non-streaming)
print("\n--- Bedrock: Converse (non-streaming) ---")
try:
route_converse = "claude_haiku_converse" # Adjust if your route name differs
model_id = "anthropic.claude-v2" # Adjust if your route name differs
user_topic = "a tranquil mountain pond"
raw_converse_output = call_bedrock_model_converse(
bedrock_client, route_converse, user_topic
bedrock_client, model_id, user_topic
)
final_converse_text = extract_final_text(raw_converse_output)
print(final_converse_text)
Expand Down
4 changes: 2 additions & 2 deletions examples/openai/openai_general_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def init_sync_openai_client():
# This client is configured for chat completions.
return OpenAI(
api_key=openai_api_key,
base_url=f"{os.getenv('JAVELIN_BASE_URL')}/v1/query/openai",
base_url=f"{os.getenv('JAVELIN_BASE_URL')}/v1",
default_headers=javelin_headers,
)
except Exception as e:
Expand All @@ -36,7 +36,7 @@ def init_async_openai_client():
javelin_headers = {"x-javelin-apikey": javelin_api_key}
return AsyncOpenAI(
api_key=openai_api_key,
base_url="https://api-dev.javelin.live/v1/query/openai",
base_url=f"{os.getenv('JAVELIN_BASE_URL')}/v1",
default_headers=javelin_headers,
)
except Exception as e:
Expand Down
Loading