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 .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[flake8]
max-line-length = 88
exclude = .git,.github,.chglog,__pycache__,docs,venv
exclude = .git,.github,.chglog,__pycache__,docs,venv,env,mypy_cache
max-complexity = 10
1 change: 0 additions & 1 deletion examples/agents/adk_gemini_agent_javelin/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from .agent import root_agent
4 changes: 3 additions & 1 deletion examples/agents/adk_gemini_agent_javelin/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@
# Coordinator agent
root_agent = SequentialAgent(
name="GeminiMultiAgentCoordinator",
sub_agents=[research_agent, summary_agent, report_agent]
sub_agents=[research_agent, summary_agent, report_agent],
)


async def main():
session_service = InMemorySessionService()
session_service.create_session("gemini_multi_agent_app", "user", "sess")
Expand All @@ -93,5 +94,6 @@ async def main():

print("\n--- Final Report ---\n", final_answer)


if __name__ == "__main__":
asyncio.run(main())
1 change: 0 additions & 1 deletion examples/agents/adk_openai_agent_javelin/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from .agent import root_agent
5 changes: 3 additions & 2 deletions examples/agents/adk_openai_agent_javelin/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
# Coordinator agent running all three sequentially
coordinator = SequentialAgent(
name="OpenAI_MultiAgentCoordinator",
sub_agents=[research_agent, summary_agent, report_agent]
sub_agents=[research_agent, summary_agent, report_agent],
)
root_agent = coordinator

Expand All @@ -96,5 +96,6 @@ async def main():

print("\n--- Final Report ---\n", final_answer)


if __name__ == "__main__":
asyncio.run(main())
asyncio.run(main())
23 changes: 14 additions & 9 deletions examples/agents/openai_agents_javelin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@
javelin_base_url = os.getenv("JAVELIN_BASE_URL", "")

if not (openai_api_key and javelin_api_key and javelin_base_url):
raise ValueError("Missing OPENAI_API_KEY, JAVELIN_API_KEY, or JAVELIN_BASE_URL in .env")
raise ValueError(
"Missing OPENAI_API_KEY, JAVELIN_API_KEY, or JAVELIN_BASE_URL in .env"
)

# Create async OpenAI client
async_openai_client = AsyncOpenAI(api_key=openai_api_key)

# Register with Javelin
javelin_client = JavelinClient(JavelinConfig(
javelin_api_key=javelin_api_key,
base_url=javelin_base_url
))
javelin_client.register_openai(async_openai_client, route_name="openai_univ") # Adjust route name if needed
javelin_client = JavelinClient(
JavelinConfig(javelin_api_key=javelin_api_key, base_url=javelin_base_url)
)
# Adjust route name if needed
javelin_client.register_openai(async_openai_client, route_name="openai_univ")

# Let the Agents SDK use this Javelin-patched client globally
set_default_openai_client(async_openai_client)
Expand All @@ -59,7 +61,7 @@
##############################################################################
translator_agent = Agent(
name="TranslatorAgent",
instructions="Translate any English text into Spanish. Keep it concise."
instructions="Translate any English text into Spanish. Keep it concise.",
)

##############################################################################
Expand All @@ -78,18 +80,20 @@
tools=[
faux_search_agent.as_tool(
tool_name="summarize_topic",
tool_description="Produce a concise internal summary of the user’s topic."
tool_description="Produce a concise internal summary of the user’s topic.",
),
translator_agent.as_tool(
tool_name="translate_to_spanish",
tool_description="Translate text into Spanish."
tool_description="Translate text into Spanish.",
),
],
)

##############################################################################
# 5) Demo Usage
##############################################################################


async def main():
user_query = "Why is pollution increasing ?"
print(f"\n=== User Query: {user_query} ===\n")
Expand All @@ -98,5 +102,6 @@ async def main():
print("=== Final Output ===\n")
print(final_result.final_output)


if __name__ == "__main__":
asyncio.run(main())
10 changes: 6 additions & 4 deletions examples/anthropic/anthropic_api_function_calling.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
# Headers
headers = {
"Content-Type": "application/json",
"x-javelin-route": "anthropic_univ", # add your universal route
"x-javelin-model": "claude-3-5-sonnet-20240620", # add any supported model
"x-javelin-route": "anthropic_univ", # add your universal route
"x-javelin-model": "claude-3-5-sonnet-20240620", # add any supported model
"x-javelin-provider": "https://api.anthropic.com/v1",
"x-api-key": os.getenv("ANTHROPIC_API_KEY"),
"x-api-key": os.getenv("ANTHROPIC_API_KEY"),
"anthropic-version": "2023-06-01",
}
client.set_headers(headers)
Expand All @@ -44,7 +44,9 @@
messages = [
{
"role": "user",
"content": [{"type": "text", "text": "What's the weather like in Mumbai in celsius?"}],
"content": [
{"type": "text", "text": "What's the weather like in Mumbai in celsius?"}
],
}
]

Expand Down
12 changes: 9 additions & 3 deletions examples/anthropic/anthropic_function_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# Load environment variables
from dotenv import load_dotenv

load_dotenv()

# Javelin Setup
Expand All @@ -25,7 +26,10 @@

# Messages and dummy tool call (check if tool support throws any error)
messages = [
{"role": "user", "content": "Please call the tool to fetch today's weather in Paris."}
{
"role": "user",
"content": "Please call the tool to fetch today's weather in Paris.",
}
]

tools = [
Expand All @@ -37,11 +41,12 @@
"properties": {
"city": {"type": "string", "description": "Name of the city"},
},
"required": ["city"]
}
"required": ["city"],
},
}
]


async def run_anthropic_test():
print("\n==== Testing Anthropic Function Calling Support via Javelin ====")
try:
Expand All @@ -64,5 +69,6 @@ async def run_anthropic_test():
except Exception as e:
print(f"Function/tool call failed for Anthropic: {str(e)}")


if __name__ == "__main__":
asyncio.run(run_anthropic_test())
5 changes: 4 additions & 1 deletion examples/anthropic/javelin_anthropic_api_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
load_dotenv()

# Helper for pretty print


def print_response(provider: str, response: Dict[str, Any]) -> None:
print(f"=== Response from {provider} ===")
print(json.dumps(response, indent=2))


# Javelin client config
config = JavelinConfig(
base_url=os.getenv("JAVELIN_BASE_URL"),
Expand Down Expand Up @@ -40,7 +43,7 @@ def print_response(provider: str, response: Dict[str, Any]) -> None:
"messages": [
{
"role": "user",
"content": [{"type": "text", "text": "What are the three primary colors?"}]
"content": [{"type": "text", "text": "What are the three primary colors?"}],
}
],
}
Expand Down
23 changes: 13 additions & 10 deletions examples/azure-openai/azure-universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +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")

# Initialize the Javelin client and register the Azure client
config = JavelinConfig(javelin_api_key=javelin_api_key)
Expand Down Expand Up @@ -113,10 +111,14 @@ def main():
print("Client initialization failed.")
return

# Example chat messages
messages = [{"role": "user", "content": "say hello"}]
run_chat_completion_sync(azure_client)
run_chat_completion_stream(azure_client)
run_embeddings(azure_client)
print("\nScript complete.")

# 1) Chat Completion (Synchronous)

def run_chat_completion_sync(azure_client):
messages = [{"role": "user", "content": "say hello"}]
try:
print("\n--- Chat Completion (Non-Streaming) ---")
response_chat_sync = get_chat_completion_sync(azure_client, messages)
Expand All @@ -127,7 +129,9 @@ def main():
except Exception as e:
print("Error in chat completion (sync):", e)

# 2) Chat Completion (Streaming)

def run_chat_completion_stream(azure_client):
messages = [{"role": "user", "content": "say hello"}]
try:
print("\n--- Chat Completion (Streaming) ---")
response_streamed = get_chat_completion_stream(azure_client, messages)
Expand All @@ -138,7 +142,8 @@ def main():
except Exception as e:
print("Error in chat completion (streaming):", e)

# 3) Embeddings

def run_embeddings(azure_client):
try:
print("\n--- Embeddings ---")
embed_text = "Sample text to embed."
Expand All @@ -150,8 +155,6 @@ def main():
except Exception as e:
print("Error in embeddings:", e)

print("\nScript complete.")


if __name__ == "__main__":
main()
31 changes: 19 additions & 12 deletions examples/azure-openai/azure_function_call.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env python
import os
import json
from dotenv import load_dotenv
from openai import AzureOpenAI
from javelin_sdk import JavelinClient, JavelinConfig

load_dotenv()


def init_azure_client_with_javelin():
azure_api_key = os.getenv("AZURE_OPENAI_API_KEY")
javelin_api_key = os.getenv("JAVELIN_API_KEY")
Expand All @@ -18,7 +18,7 @@ def init_azure_client_with_javelin():
azure_client = AzureOpenAI(
api_version="2023-07-01-preview",
azure_endpoint="https://javelinpreview.openai.azure.com",
api_key=azure_api_key
api_key=azure_api_key,
)

# Register with Javelin
Expand All @@ -28,6 +28,7 @@ def init_azure_client_with_javelin():

return azure_client


def run_function_call_test(azure_client):
print("\n==== Azure OpenAI Function Calling via Javelin ====")

Expand All @@ -46,20 +47,21 @@ def run_function_call_test(azure_client):
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "Temperature unit"
}
"description": "Temperature unit",
},
},
"required": ["city"]
}
"required": ["city"],
},
}
],
function_call="auto"
function_call="auto",
)
print("Function Call Output:")
print(response.to_json(indent=2))
except Exception as e:
print("Azure Function Calling Error:", e)


def run_tool_call_test(azure_client):
print("\n==== Azure OpenAI Tool Calling via Javelin ====")

Expand All @@ -76,24 +78,29 @@ def run_tool_call_test(azure_client):
"parameters": {
"type": "object",
"properties": {
"category": {"type": "string", "description": "e.g. success, life"}
"category": {
"type": "string",
"description": "e.g. success, life",
}
},
"required": []
}
}
"required": [],
},
},
}
],
tool_choice="auto"
tool_choice="auto",
)
print("Tool Call Output:")
print(response.to_json(indent=2))
except Exception as e:
print("Azure Tool Calling Error:", e)


def main():
client = init_azure_client_with_javelin()
run_function_call_test(client)
run_tool_call_test(client)


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