mirror of
https://gh-proxy.org/https://github.com/klinsmaya/gateway.git
synced 2026-11-08 00:57:59 +08:00
1.6 MiB
Vendored
1.6 MiB
Vendored
In [ ]:
!pip install -qU crewai portkey-aiIn [4]:
from crewai import LLM
from portkey_ai import createHeaders, PORTKEY_GATEWAY_URL
gpt_llm = LLM(
model="gpt-4o",
base_url=PORTKEY_GATEWAY_URL,
api_key="dummy", # We are using Virtual key
extra_headers=createHeaders(
api_key="YOUR_PORTKEY_API_KEY",
virtual_key="YOUR_VIRTUAL_KEY", # Enter your OpenAI Virtual key from Portkey
)
)
anthropic_llm = LLM(
model="claude-3-5-sonnet-latest",
base_url=PORTKEY_GATEWAY_URL,
api_key="dummy", # We are using Virtual key
extra_headers=createHeaders(
api_key="YOUR_PORTKEY_API_KEY",
virtual_key="YOUR_VIRTUAL_KEY", # Enter your Anthroipc Virtual key from Portkey
config="YOUR_PORTKEY_CONFIG_ID", # All your model parmaeters and routing strategy
trace_id="llm2"
)
)
In [5]:
from crewai import Agent, Task, Crew, Process
# Define your agents with roles and goals
coder = Agent(
role='Software develoepr',
goal='Write clear - concise code on demand',
backstory='An expert coder with a keen eye for software trends.',
llm = gpt_llm
)
# Create tasks for your agents
task1 = Task(
description="Define the HTML for making a simple website with heading- Hello World! Portkey is working! .",
expected_output="A clear and concise HTML code",
agent=coder
)
# Instantiate your crew with a sequential process
crew = Crew(
agents=[coder],
tasks=[task1],
)
# Get your crew to work!
result = crew.kickoff()
print("######################")
print(result)
WARNING:opentelemetry.trace:Overriding of current TracerProvider is not allowed
######################
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Website</title>
</head>
<body>
<h1>Hello World! Portkey is working!</h1>
</body>
</html>
```
In [ ]:
from crewai import Agent, Task, Crew, Process
# Define your agents with roles and goals
product_manager = Agent(
role='Product Manager',
goal='Define requirements for a software product',
backstory="You are an experienced Product Manager skilled in defining clear and concise requirements.",
llm = gpt_llm
)
coder = Agent(
role='Software Developer',
goal='Develop software based on the provided requirements',
backstory="You are a skilled software developer proficient in coding robust and efficient applications.",
llm = anthropic_llm
)
# Create tasks for your agents
task1 = Task(
description="Define the key requirements and features for a classic ping pong game. Be specific and concise.",
expected_output="A clear and concise list of requirements for the ping pong game",
agent=product_manager
)
task2 = Task(
description="Based on the provided requirements, develop the code for the classic ping pong game. Focus on gameplay mechanics and a simple user interface.",
expected_output="Complete code for the ping pong game",
agent=coder
)
# Instantiate your crew with a sequential process
crew = Crew(
agents=[product_manager, coder],
tasks=[task1, task2],
verbose=1,
)
# Get your crew to work!
result = crew.kickoff()
print("######################")
print(result)[1m[95m# Agent:[00m [1m[92mProduct Manager[00m [95m## Task:[00m [92mDefine the key requirements and features for a classic ping pong game. Be specific and concise.[00m [1m[95m# Agent:[00m [1m[92mProduct Manager[00m [95m## Final Answer:[00m [92m 1. Game Interface: - A simple 2D graphical interface displaying the ping pong table, net, paddles, and ball. - Scoreboard displaying current scores for both players. - Option to pause and resume the game. 2. Game Mechanics: - Physics engine to simulate realistic ball movement, including speed, spin, and bounce. - Collision detection for ball interaction with paddles and boundaries. - Two paddles controlled by players or AI opponents. 3. Control Options: - Keyboard controls: arrow keys or WASD for paddle movement. - Option for mouse control for more intuitive paddle movement. - Touch controls for mobile or touchscreen devices. 4[00m [1m[95m# Agent:[00m [1m[92mSoftware Developer[00m [95m## Task:[00m [92mBased on the provided requirements, develop the code for the classic ping pong game. Focus on gameplay mechanics and a simple user interface.[00m [1m[95m# Agent:[00m [1m[92mSoftware Developer[00m [95m## Final Answer:[00m [92m Here's a complete implementation of a simple ping pong game using Python and Pygame, which covers the requirements outlined: ```python import pygame import sys # Initialize Pygame pygame.init() # Constants WIDTH, HEIGHT = 800, 400 WHITE = (255, 255, 255) BLACK = (0, 0, 0) BALL_RADIUS = 10 PADDLE_WIDTH, PADDLE_HEIGHT = 10, 60 PADDLE_SPEED = 5 BALL_SPEED_X, BALL_SPEED_Y = 4, 4 FPS = 60 # Set up display window = pygame.display.set_mode(([00m ###################### Here's a complete implementation of a simple ping pong game using Python and Pygame, which covers the requirements outlined: ```python import pygame import sys # Initialize Pygame pygame.init() # Constants WIDTH, HEIGHT = 800, 400 WHITE = (255, 255, 255) BLACK = (0, 0, 0) BALL_RADIUS = 10 PADDLE_WIDTH, PADDLE_HEIGHT = 10, 60 PADDLE_SPEED = 5 BALL_SPEED_X, BALL_SPEED_Y = 4, 4 FPS = 60 # Set up display window = pygame.display.set_mode((