Generate request scenarios based on traffic configuration.
Source code in ccproxy/testing/scenarios.py
| def __init__(self, config: TrafficConfig):
self.config = config
|
generate_scenarios
Generate request scenarios based on configuration.
Source code in ccproxy/testing/scenarios.py
| def generate_scenarios(self) -> list[RequestScenario]:
"""Generate request scenarios based on configuration."""
total_requests = int(
self.config.duration_seconds * self.config.requests_per_second
)
scenarios = []
# Calculate timeframe
start_time = self.config.start_timestamp or datetime.now(UTC)
time_span = self.config.duration_seconds
for i in range(total_requests):
# Determine timing based on pattern
time_offset = self._calculate_time_offset(i, total_requests, time_span)
request_time = start_time + time_offset
# Select random parameters
model = random.choice(self.config.models)
message_type = random.choice(self.config.message_types)
streaming = random.random() < self.config.streaming_probability
# Determine response type
response_type = self._determine_response_type()
# Determine API format based on distribution
api_format = self._determine_api_format()
# Set endpoint path based on format
endpoint_path = (
"/api/v1/chat/completions"
if api_format == "openai"
else "/api/v1/messages"
)
# Generate headers with bypass and format-specific headers
headers = self._generate_headers(api_format, streaming)
scenarios.append(
RequestScenario(
model=model,
message_type=message_type,
streaming=streaming,
response_type=response_type,
timestamp=request_time,
api_format=api_format,
endpoint_path=endpoint_path,
bypass_upstream=self.config.bypass_mode,
use_real_auth=not self.config.bypass_mode,
headers=headers,
target_url=self.config.target_url,
)
)
return scenarios
|