Skip to content

Commit d7471a9

Browse files
author
Fede Kamelhar
committed
feat: Adding portkey.ai gateway as a custom model
feat: Adding portkey.ai gateway as a custom model
1 parent aff928c commit d7471a9

24 files changed

Lines changed: 1015 additions & 1 deletion

.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ from strands import Agent
118118
from strands.models import BedrockModel
119119
from strands.models.ollama import OllamaModel
120120
from strands.models.llamaapi import LlamaAPIModel
121+
from strands.models.portkey import PortkeyModel
121122

122123
# Bedrock
123124
bedrock_model = BedrockModel(
@@ -142,6 +143,17 @@ llama_model = LlamaAPIModel(
142143
)
143144
agent = Agent(model=llama_model)
144145
response = agent("Tell me about Agentic AI")
146+
147+
# Portkey for all models
148+
portkey_model = PortkeyModel(
149+
api_key="<PORTKEY_API_KEY>",
150+
model_id="anthropic.claude-3-5-sonnet-20241022-v2:0",
151+
virtual_key="<BEDROCK_VIRTUAL_KEY>",
152+
provider="bedrock",
153+
base_url="http://portkey-service-gateway.service.prod.example.com/v1",
154+
)
155+
agent = Agent(model=portkey_model)
156+
response = agent("Tell me about Agentic AI")
145157
```
146158

147159
Built-in providers:

bedrock.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import sys
2+
import os
3+
from strands.models.portkey import PortkeyModel
4+
from strands.agent import Agent
5+
from strands_tools import calculator, file_read, file_write, shell
6+
7+
# Setup the model
8+
model = PortkeyModel(
9+
api_key="9tE30As65QsH7TTIuaQzfpFyFMg8",
10+
model_id="anthropic.claude-3-5-sonnet-20241022-v2:0",
11+
virtual_key="aws-bedrock-83f9b6",
12+
provider="bedrock",
13+
base_url="http://cybertron-service-gateway.service.prod.ddsd:8080/v1",
14+
)
15+
16+
# Get input from CLI
17+
input_arg = sys.argv[1]
18+
19+
# Load prompt: from file if it's a file, otherwise treat as raw prompt
20+
if os.path.isfile(input_arg):
21+
prompt = open(input_arg).read()
22+
else:
23+
prompt = input_arg
24+
25+
# Run the agent
26+
agent = Agent(model=model, tools=[calculator, file_read, file_write, shell])
27+
print(agent(prompt))

chat.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import argparse
2+
from strands.models.portkey import PortkeyModel
3+
from strands.agent import Agent
4+
from strands_tools import calculator, file_read, file_write, shell
5+
6+
# ---- Argument Parsing ----
7+
parser = argparse.ArgumentParser(description="Start a persistent chat with the agent.")
8+
parser.add_argument("prompt", type=str, nargs="?", help="Optional initial prompt to start the chat")
9+
args = parser.parse_args()
10+
11+
# ---- Model Setup ----
12+
portkey_model = PortkeyModel(
13+
api_key="9tE30As65QsH7TTIuaQzfpFyFMg8",
14+
model_id="anthropic.claude-3-5-sonnet-20241022-v2:0",
15+
virtual_key="aws-bedrock-83f9b6",
16+
provider="bedrock",
17+
base_url="http://cybertron-service-gateway.service.prod.ddsd:8080/v1",
18+
)
19+
20+
# ---- Agent Setup ----
21+
agent = Agent(
22+
model=portkey_model,
23+
tools=[calculator, file_read, file_write, shell]
24+
)
25+
26+
# ---- Chat Loop ----
27+
def run_chat(initial_prompt=None):
28+
print("🤖 Agent: Hello! I'm here to help you with tasks using the available tools.")
29+
print("Type `exit` or press Ctrl+C to quit.\n")
30+
31+
if initial_prompt:
32+
print(f"👤 You: {initial_prompt}")
33+
response = agent(initial_prompt)
34+
print(f"🤖 Agent: {response}\n")
35+
36+
while True:
37+
try:
38+
user_input = input("👤 You: ").strip()
39+
if user_input.lower() in ["exit", "quit"]:
40+
print("👋 Exiting chat.")
41+
break
42+
print()
43+
response = agent(user_input)
44+
print(f"🤖 Agent: {response}\n")
45+
46+
except KeyboardInterrupt:
47+
print("\n👋 Exiting chat.")
48+
break
49+
50+
# ---- Run Chat ----
51+
run_chat(initial_prompt=args.prompt)

childrens_story.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
The Friendly Cloud
2+
3+
Once upon a time, there was a little white cloud named Fluffy who loved to float in the bright blue sky. Unlike other clouds that just drifted along, Fluffy liked to make shapes to make children happy.
4+
5+
One day, Fluffy noticed a little girl who looked sad sitting in her backyard. To cheer her up, Fluffy stretched and twisted until he looked just like a happy puppy! The little girl looked up and smiled, pointing at the sky.
6+
7+
Excited by the girl's happiness, Fluffy then transformed into a dancing butterfly, then a majestic castle, and finally a beautiful flower. Soon, other children in the neighborhood noticed the amazing shapes in the sky and gathered to watch Fluffy's wonderful show.
8+
9+
From that day on, Fluffy became known as the happiest cloud in the sky, bringing joy to children everywhere with his magical shapes. And if you look up on a sunny day, you might just see Fluffy creating wonderful shapes just for you!
10+
11+
The End

greeting.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hellocomo estas?

openai.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import sys
2+
from strands.models.portkey import PortkeyModel
3+
from strands.agent import Agent
4+
from strands_tools import calculator, file_read, file_write
5+
6+
# Initialize the Portkey model with proper OpenAI configuration
7+
portkey_model = PortkeyModel(
8+
api_key="9tE30As65QsH7TTIuaQzfpFyFMg8",
9+
virtual_key="openai-merchant-53367b",
10+
model_id="gpt-3.5-turbo",
11+
base_url="http://cybertron-service-gateway.service.prod.ddsd:8080/v1",
12+
provider="openai",
13+
)
14+
15+
# Create agent with calculator, file_read, and file_write tools
16+
agent = Agent(model=portkey_model, tools=[calculator, file_read, file_write])
17+
18+
# Accept prompt from command line argument
19+
if len(sys.argv) < 2:
20+
print("Please provide a prompt as a command line argument.")
21+
sys.exit(1)
22+
23+
prompt = sys.argv[1]
24+
25+
# Call the agent with the external prompt
26+
response = agent(prompt)
27+
print(response)

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ packages = ["src/strands"]
5050
anthropic = [
5151
"anthropic>=0.21.0,<1.0.0",
5252
]
53+
# Optional dependencies for different AI providers
54+
portkey = [
55+
"portkey-ai>=1.0.0,<2.0.0",
56+
]
57+
5358
dev = [
5459
"commitizen>=4.4.0,<5.0.0",
5560
"hatch>=1.0.0,<2.0.0",
@@ -107,7 +112,7 @@ lint-fix = [
107112
]
108113

109114
[tool.hatch.envs.hatch-test]
110-
features = ["anthropic", "litellm", "llamaapi", "ollama", "openai"]
115+
features = ["anthropic", "litellm", "llamaapi", "ollama", "openai", "portkey"]
111116
extra-dependencies = [
112117
"moto>=5.1.0,<6.0.0",
113118
"pytest>=8.0.0,<9.0.0",

0 commit comments

Comments
 (0)