Skip to content

Commit 5cd4756

Browse files
authored
feat(wasm): align LLM and route types with platform-v2 SDK (#16)
* feat(wasm): align LLM and route types with platform-v2 SDK Replace local duplicate type definitions with re-exports from platform_challenge_sdk_wasm to ensure type consistency across the stack. types.rs: - Remove local LlmMessage, LlmRequest (temperature: f64), LlmResponse structs - Remove local RouteDefinition struct (missing requires_auth field) - Remove local WasmRouteRequest struct (missing params/query fields) - Add re-exports: LlmMessage, LlmRequest, LlmResponse from SDK (temperature: f32) - Add re-exports: WasmRouteDefinition, WasmRouteRequest from SDK - Fix cosmetic extra blank line left after struct removal routes.rs: - Update import from RouteDefinition to WasmRouteDefinition - Update get_route_definitions() return type to Vec<WasmRouteDefinition> - Update all 27 route definitions with requires_auth field: GET routes set to false, auth-required POST routes set to true * fix: use SDK re-exports for LlmMessage/LlmRequest/LlmResponse to fix f64/f32 temperature mismatch and ensure serialization compatibility * fix: point all SDK deps to platform-v2 git repo for CI compatibility
1 parent 7e0fc92 commit 5cd4756

File tree

6 files changed

+38
-130
lines changed

6 files changed

+38
-130
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ license = "Apache-2.0"
1111
repository = "https://github.com/PlatformNetwork/term-challenge"
1212

1313
[workspace.dependencies]
14-
platform-challenge-sdk = { git = "https://github.com/PlatformNetwork/platform.git", features = ["http-server"] }
15-
platform-core = { git = "https://github.com/PlatformNetwork/platform.git" }
14+
platform-challenge-sdk = { git = "https://github.com/PlatformNetwork/platform-v2", branch = "main", features = ["http-server"] }
15+
platform-core = { git = "https://github.com/PlatformNetwork/platform-v2", branch = "main" }
1616
sp-core = { version = "31.0", default-features = false, features = ["std"] }
1717
sled = "0.34"
1818
bincode = "1.3"

server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ name = "term-challenge-server"
1414
path = "src/main.rs"
1515

1616
[dependencies]
17-
platform-challenge-sdk = { path = "/workspace/platform-v2/crates/challenge-sdk", features = ["http-server"] }
17+
platform-challenge-sdk = { git = "https://github.com/PlatformNetwork/platform-v2", branch = "main", features = ["http-server"] }
1818

1919
axum = { version = "0.7", features = ["json"] }
2020
tokio = { version = "1.40", features = ["full"] }

server/src/main.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use serde_json::json;
1616
use tracing::info;
1717

1818
#[derive(Parser)]
19-
#[command(name = "term-challenge-server", about = "Terminal Benchmark Challenge Server")]
19+
#[command(
20+
name = "term-challenge-server",
21+
about = "Terminal Benchmark Challenge Server"
22+
)]
2023
struct Cli {
2124
#[arg(long, env = "CHALLENGE_HOST", default_value = "0.0.0.0")]
2225
host: String,
@@ -167,7 +170,11 @@ impl TerminalBenchChallenge {
167170
})
168171
.collect();
169172

170-
entries.sort_by(|a, b| b.score.partial_cmp(&a.score).unwrap_or(std::cmp::Ordering::Equal));
173+
entries.sort_by(|a, b| {
174+
b.score
175+
.partial_cmp(&a.score)
176+
.unwrap_or(std::cmp::Ordering::Equal)
177+
});
171178
for (i, entry) in entries.iter_mut().enumerate() {
172179
entry.rank = (i + 1) as u32;
173180
}
@@ -307,10 +314,7 @@ impl ServerChallenge for TerminalBenchChallenge {
307314
}
308315
}
309316

310-
async fn evaluate(
311-
&self,
312-
req: EvaluationRequest,
313-
) -> Result<EvaluationResponse, ChallengeError> {
317+
async fn evaluate(&self, req: EvaluationRequest) -> Result<EvaluationResponse, ChallengeError> {
314318
let submission: SubmissionData = serde_json::from_value(req.data.clone()).map_err(|e| {
315319
ChallengeError::Evaluation(format!("Failed to parse submission data: {}", e))
316320
})?;
@@ -341,18 +345,17 @@ impl ServerChallenge for TerminalBenchChallenge {
341345
}
342346

343347
let total_tasks = submission.task_results.len() as f64;
344-
let passed_tasks = submission
345-
.task_results
346-
.iter()
347-
.filter(|r| r.passed)
348-
.count() as f64;
348+
let passed_tasks = submission.task_results.iter().filter(|r| r.passed).count() as f64;
349349
let pass_rate = passed_tasks / total_tasks;
350350

351351
let avg_score: f64 =
352352
submission.task_results.iter().map(|r| r.score).sum::<f64>() / total_tasks;
353353

354-
let total_execution_time_ms: u64 =
355-
submission.task_results.iter().map(|r| r.execution_time_ms).sum();
354+
let total_execution_time_ms: u64 = submission
355+
.task_results
356+
.iter()
357+
.map(|r| r.execution_time_ms)
358+
.sum();
356359

357360
let final_score = (pass_rate * 0.7 + avg_score * 0.3).clamp(0.0, 1.0);
358361

@@ -392,10 +395,7 @@ impl ServerChallenge for TerminalBenchChallenge {
392395
))
393396
}
394397

395-
async fn validate(
396-
&self,
397-
req: ValidationRequest,
398-
) -> Result<ValidationResponse, ChallengeError> {
398+
async fn validate(&self, req: ValidationRequest) -> Result<ValidationResponse, ChallengeError> {
399399
let mut errors = Vec::new();
400400
let mut warnings = Vec::new();
401401

@@ -505,8 +505,8 @@ async fn main() -> Result<()> {
505505
Some(id) => ChallengeId::from_str(id)
506506
.ok_or_else(|| anyhow::anyhow!("Invalid challenge ID UUID: {}", id))?,
507507
None => {
508-
let id = ChallengeId::from_str("a1b2c3d4-e5f6-7890-abcd-ef1234567890")
509-
.unwrap_or_default();
508+
let id =
509+
ChallengeId::from_str("a1b2c3d4-e5f6-7890-abcd-ef1234567890").unwrap_or_default();
510510
info!("No challenge ID provided, using default: {}", id);
511511
id
512512
}

wasm/src/routes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn get_route_definitions() -> Vec<WasmRouteDefinition> {
4343
method: String::from("POST"),
4444
path: String::from("/submit"),
4545
description: String::from("Submission endpoint: receives zip package and metadata"),
46-
requires_auth: false,
46+
requires_auth: true,
4747
},
4848
WasmRouteDefinition {
4949
method: String::from("GET"),

wasm/src/types.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -295,21 +295,4 @@ impl Default for WhitelistConfig {
295295
}
296296
}
297297

298-
#[derive(Clone, Debug, Serialize, Deserialize)]
299-
pub struct LlmMessage {
300-
pub role: String,
301-
pub content: String,
302-
}
303-
304-
#[derive(Clone, Debug, Serialize, Deserialize)]
305-
pub struct LlmRequest {
306-
pub model: String,
307-
pub messages: Vec<LlmMessage>,
308-
pub max_tokens: u32,
309-
pub temperature: f64,
310-
}
311-
312-
#[derive(Clone, Debug, Serialize, Deserialize)]
313-
pub struct LlmResponse {
314-
pub content: String,
315-
}
298+
pub use platform_challenge_sdk_wasm::{LlmMessage, LlmRequest, LlmResponse};

0 commit comments

Comments
 (0)