Skip to content

Commit 39e731a

Browse files
aaronvgseawatts
andauthored
More improvements to studio2 publishing (#2333)
- Wire through client details on stream data <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Enhance client details handling in HTTP requests, add new metrics and cost structures, and update protobuf message handling. > > - **Behavior**: > - Add `client_details` to `HTTPRequest` in `events.rs` and `IntermediateData` in `trace_event.rs`. > - Update `ApiKeyEnvironment::environment()` in `api_key.rs` to handle longer environment strings. > - Add new metrics and cost statistics structures in `ui_dashboard.rs` and `ui_dashboard_cost.rs`. > - **Protobuf**: > - Modify `cffi.pb.go` to include `protoimpl.MessageState` in various structs for better message handling. > - **Misc**: > - Add `GetFunctionCallHttpCalls` endpoint in `ui_function_call_http_calls.rs`. > - Add `llm_only` filter to `ListTracesRequest` in `ui_traces.rs`. > - Add cost estimates to `UiUsageEstimate` in `ui_types.rs`. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for df0ed86. You can [customize](https://app.ellipsis.dev/BoundaryML/settings/summaries) this summary. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN --> --------- Co-authored-by: Chris Watts <chris@boundaryml.com>
1 parent e1a8fd5 commit 39e731a

16 files changed

Lines changed: 1109 additions & 1838 deletions

File tree

engine/baml-lib/baml-types/src/tracing/events.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ pub struct HTTPRequest {
389389
#[serde(deserialize_with = "deserialize_headers")]
390390
headers: HashMap<String, String>,
391391
pub body: HTTPBody,
392+
pub client_details: std::sync::Arc<ClientDetails>,
392393
}
393394

394395
impl HTTPRequest {
@@ -398,13 +399,15 @@ impl HTTPRequest {
398399
method: String,
399400
headers: HashMap<String, String>,
400401
body: HTTPBody,
402+
client_details: ClientDetails,
401403
) -> Self {
402404
Self {
403405
id,
404406
url,
405407
method,
406408
headers,
407409
body,
410+
client_details: std::sync::Arc::new(client_details),
408411
}
409412
}
410413

@@ -614,6 +617,11 @@ mod tests {
614617
"POST".to_string(),
615618
headers.clone(),
616619
HTTPBody::new(b"test body".to_vec()),
620+
ClientDetails {
621+
name: "test-client".to_string(),
622+
provider: "test-provider".to_string(),
623+
options: IndexMap::new(),
624+
},
617625
);
618626

619627
// Test that .headers() returns original headers

engine/baml-rpc/src/auth/api_key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl ApiKeyEnvironment {
3939
Self::DEVELOPMENT => "dev",
4040
Self::STAGING => "stg",
4141
Self::PRODUCTION => "prod",
42-
_ => &self.value[..3.min(self.value.len())],
42+
_ => &self.value[..self.value.len().min(4)],
4343
}
4444
}
4545
}

engine/baml-rpc/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,8 @@ pub use ui::{
3030
ListProjectsRequest, ListProjectsResponse, Project, UpdateProject, UpdateProjectRequest,
3131
UpdateProjectResponse,
3232
},
33+
ui_function_call_http_calls::{
34+
GetFunctionCallHttpCalls, GetFunctionCallHttpCallsRequest, GetFunctionCallHttpCallsResponse,
35+
},
3336
ui_function_calls::{ListFunctionCalls, ListFunctionCallsRequest, ListFunctionCallsResponse},
3437
};

engine/baml-rpc/src/runtime_api/trace_event.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ pub enum IntermediateData<'a> {
120120
url: String,
121121
method: String,
122122
headers: HashMap<String, String>,
123+
client_details: RpcClientDetails,
123124
body: HTTPBody<'a>,
124125
},
125126
RawLLMResponse {

engine/baml-rpc/src/ui/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ pub mod ui_baml_src;
22
pub mod ui_control_plane_orgs;
33
pub mod ui_control_plane_projects;
44
pub mod ui_dashboard;
5+
pub mod ui_dashboard_cost;
6+
pub mod ui_function_call_http_calls;
57
pub mod ui_function_calls;
68
pub mod ui_traces;
79
pub mod ui_types;

engine/baml-rpc/src/ui/ui_dashboard.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,48 @@ pub struct StatusCountOverTime {
151151
pub error_count: u64,
152152
}
153153

154+
#[derive(Debug, Serialize, Deserialize, TS)]
155+
#[ts(export)]
156+
pub struct TimeSeriesFloatPoint {
157+
#[ts(type = "number")]
158+
pub interval_start: EpochMsTimestamp,
159+
pub value: f64,
160+
}
161+
162+
#[derive(Debug, Serialize, Deserialize, TS)]
163+
#[ts(export)]
164+
pub struct TimeSeriesIntPoint {
165+
#[ts(type = "number")]
166+
pub interval_start: EpochMsTimestamp,
167+
pub value: u64,
168+
}
169+
170+
#[derive(Debug, Serialize, Deserialize, TS)]
171+
#[ts(export)]
172+
pub struct MetricSeriesFloat {
173+
pub total: f64,
174+
pub series: Vec<TimeSeriesFloatPoint>,
175+
}
176+
177+
#[derive(Debug, Serialize, Deserialize, TS)]
178+
#[ts(export)]
179+
pub struct MetricSeriesInt {
180+
pub total: u64,
181+
pub series: Vec<TimeSeriesIntPoint>,
182+
}
183+
154184
#[derive(Debug, Serialize, Deserialize, TS)]
155185
#[ts(export)]
156186
pub struct GetDashboardDataResponse {
157187
pub status_counts_by_function: Vec<StatusCountByFunction>,
158188
pub parsing_errors_by_client: Vec<ParsingErrorCountByClient>,
159189
pub parsing_errors_by_function: Vec<ParsingErrorCountByFunction>,
160190
pub status_counts: Vec<StatusCountOverTime>,
191+
pub latency_p75_ms: MetricSeriesFloat,
192+
pub latency_p95_ms: MetricSeriesFloat,
193+
pub latency_avg_ms: MetricSeriesFloat,
194+
pub total_llm_calls: MetricSeriesInt,
195+
pub total_traces: MetricSeriesInt,
161196
}
162197

163198
pub struct GetDashboardData;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
use baml_ids::ProjectId;
2+
use serde::{Deserialize, Serialize};
3+
use ts_rs::TS;
4+
5+
use crate::{base::EpochMsTimestamp, rpc::ApiEndpoint};
6+
7+
#[derive(Debug, Serialize, Deserialize, TS)]
8+
#[ts(export)]
9+
pub struct GetCostStatsRequest {
10+
#[ts(type = "string")]
11+
pub project_id: ProjectId,
12+
#[ts(type = "FilterExpression<number>", optional)]
13+
pub start_time:
14+
Option<super::ui_function_calls::FilterExpression<crate::base::EpochMsTimestamp>>,
15+
#[ts(type = "FilterExpression<number>", optional)]
16+
pub end_time: Option<super::ui_function_calls::FilterExpression<crate::base::EpochMsTimestamp>>,
17+
#[ts(optional)]
18+
pub relative_time: Option<super::ui_function_calls::RelativeTime>,
19+
#[ts(optional)]
20+
pub function_name: Option<super::ui_function_calls::FilterExpression<String>>,
21+
#[ts(optional)]
22+
pub status: Option<
23+
super::ui_function_calls::FilterExpression<super::ui_function_calls::FunctionCallStatus>,
24+
>,
25+
#[ts(optional)]
26+
pub tags: Option<Vec<super::ui_function_calls::TagFilter>>,
27+
}
28+
29+
#[derive(Debug, Serialize, Deserialize, TS)]
30+
#[ts(export)]
31+
pub struct TimeSeriesFloatPoint {
32+
#[ts(type = "number")]
33+
pub interval_start: EpochMsTimestamp,
34+
pub value: f64,
35+
}
36+
37+
#[derive(Debug, Serialize, Deserialize, TS)]
38+
#[ts(export)]
39+
pub struct MetricSeriesFloat {
40+
pub total: f64,
41+
pub series: Vec<TimeSeriesFloatPoint>,
42+
}
43+
44+
#[derive(Debug, Serialize, Deserialize, TS)]
45+
#[ts(export)]
46+
pub struct CostByClientBreakdownItem {
47+
pub client_name: String,
48+
pub total_cost: f64,
49+
}
50+
51+
#[derive(Debug, Serialize, Deserialize, TS)]
52+
#[ts(export)]
53+
pub struct GetCostStatsResponse {
54+
pub total_cost: MetricSeriesFloat,
55+
pub cost_by_client: Vec<CostByClientBreakdownItem>,
56+
}
57+
58+
pub struct GetCostStats;
59+
60+
impl ApiEndpoint for GetCostStats {
61+
type Request<'a> = GetCostStatsRequest;
62+
type Response<'a> = GetCostStatsResponse;
63+
64+
const PATH: &'static str = "/v1/dashboard/cost";
65+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use serde::{Deserialize, Serialize};
2+
use ts_rs::TS;
3+
4+
use super::ui_types::UiHttpCall;
5+
use crate::{rpc::ApiEndpoint, FunctionCallId, ProjectId};
6+
7+
#[derive(Debug, Serialize, Deserialize, TS)]
8+
#[ts(export)]
9+
pub struct GetFunctionCallHttpCallsRequest {
10+
#[ts(type = "string")]
11+
pub project_id: ProjectId,
12+
#[ts(type = "string")]
13+
pub function_call_id: FunctionCallId,
14+
}
15+
16+
#[derive(Debug, Serialize, Deserialize, TS)]
17+
#[ts(export)]
18+
pub struct GetFunctionCallHttpCallsResponse {
19+
pub http_calls: Vec<UiHttpCall>,
20+
}
21+
22+
pub struct GetFunctionCallHttpCalls;
23+
24+
impl ApiEndpoint for GetFunctionCallHttpCalls {
25+
type Request<'a> = GetFunctionCallHttpCallsRequest;
26+
type Response<'a> = GetFunctionCallHttpCallsResponse;
27+
28+
const PATH: &'static str = "/v1/function-calls/http-calls";
29+
}

engine/baml-rpc/src/ui/ui_traces.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ pub struct ListTracesRequest {
127127
/// Search term to filter across function_call_id, function_name, tags, error, input (args), and output
128128
#[ts(optional)]
129129
pub search: Option<String>,
130+
/// Filter to only show LLM function calls (function_type = 'baml_llm')
131+
#[ts(optional)]
132+
pub llm_only: Option<FilterExpression<bool>>,
130133
}
131134

132135
impl Default for ListTracesRequest {
@@ -156,6 +159,7 @@ impl Default for ListTracesRequest {
156159
streamed: None,
157160
relative_time: None,
158161
search: None,
162+
llm_only: None,
159163
}
160164
}
161165
}

engine/baml-rpc/src/ui/ui_types.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,13 @@ pub struct UiUsageEstimate {
154154
pub input_tokens: Option<u64>,
155155
#[ts(type = "number | null")]
156156
pub output_tokens: Option<u64>,
157-
// TODO: add cost estimate data here
158-
// This is tricky to do because we need provider & model to effectively
159-
// resolve the token costs. Even restricting to just openai is non-straightforward,
160-
// and frankly I'm skeptical that restricting to just openai is a sufficiently common
161-
// implementation use case.
157+
// Cost estimates calculated from provider-specific pricing
158+
#[ts(type = "number | null")]
159+
pub input_cost: Option<f64>,
160+
#[ts(type = "number | null")]
161+
pub output_cost: Option<f64>,
162+
#[ts(type = "number | null")]
163+
pub total_cost: Option<f64>,
162164
}
163165

164166
#[derive(Debug, Serialize, Deserialize, TS)]

0 commit comments

Comments
 (0)