llm_test_bench_core/api/
graphql.rs1use async_graphql::{
10 Context, EmptySubscription, Object, Schema, SimpleObject, InputObject,
11};
12use chrono::{DateTime, Utc};
13
14pub type GraphQLSchema = Schema<Query, Mutation, EmptySubscription>;
16
17#[derive(InputObject)]
19pub struct CompletionInput {
20 pub provider: String,
21 pub model: String,
22 pub prompt: String,
23 pub max_tokens: Option<i32>,
24 pub temperature: Option<f32>,
25}
26
27#[derive(SimpleObject)]
29pub struct CompletionResult {
30 pub text: String,
31 pub model: String,
32 pub request_id: String,
33 pub created_at: DateTime<Utc>,
34}
35
36#[derive(InputObject)]
38pub struct EvaluationInput {
39 pub provider: String,
40 pub model: String,
41 pub input: String,
42 pub output: String,
43 pub expected: Option<String>,
44 pub metrics: Vec<String>,
45}
46
47#[derive(SimpleObject)]
49pub struct EvaluationResult {
50 pub score: f64,
51 pub evaluation_id: String,
52 pub created_at: DateTime<Utc>,
53}
54
55#[derive(SimpleObject)]
57pub struct PluginNode {
58 pub id: String,
59 pub name: String,
60 pub version: String,
61 pub plugin_type: String,
62 pub status: String,
63}
64
65pub struct Query;
67
68#[Object]
69impl Query {
70 async fn version(&self) -> &str {
72 crate::api::API_VERSION
73 }
74
75 async fn health(&self) -> bool {
77 true
78 }
79
80 async fn plugins(&self, _ctx: &Context<'_>) -> Vec<PluginNode> {
82 vec![]
84 }
85
86 async fn plugin(&self, _ctx: &Context<'_>, id: String) -> Option<PluginNode> {
88 Some(PluginNode {
90 id,
91 name: "example".to_string(),
92 version: "1.0.0".to_string(),
93 plugin_type: "evaluator".to_string(),
94 status: "ready".to_string(),
95 })
96 }
97}
98
99pub struct Mutation;
101
102#[Object]
103impl Mutation {
104 async fn create_completion(
106 &self,
107 _ctx: &Context<'_>,
108 input: CompletionInput,
109 ) -> CompletionResult {
110 CompletionResult {
112 text: "Generated response".to_string(),
113 model: input.model,
114 request_id: uuid::Uuid::new_v4().to_string(),
115 created_at: Utc::now(),
116 }
117 }
118
119 async fn create_evaluation(
121 &self,
122 _ctx: &Context<'_>,
123 _input: EvaluationInput,
124 ) -> EvaluationResult {
125 EvaluationResult {
127 score: 0.85,
128 evaluation_id: uuid::Uuid::new_v4().to_string(),
129 created_at: Utc::now(),
130 }
131 }
132}
133
134pub struct GraphQLApi;
136
137impl GraphQLApi {
138 pub fn schema() -> GraphQLSchema {
140 Schema::build(Query, Mutation, EmptySubscription).finish()
141 }
142}