Skip to content

Commit b0c0c23

Browse files
refactor(client): use ModelCallObservation throughout
Signed-off-by: nachiketb <nachiketb@nvidia.com>
1 parent 2a03667 commit b0c0c23

5 files changed

Lines changed: 20 additions & 20 deletions

File tree

‎crates/libsy-llm-client/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ mod system_one;
3232
pub use backend::{Backend, DEFAULT_MAX_RETRIES, HttpBackendConfig};
3333
pub use client::{AuxiliaryOperation, ModelConfig, TranslatingLlmClient};
3434
pub use error::{LlmClientError, Result};
35-
pub use observation::{LlmCallObservation, RunObservation, RunObserver};
35+
pub use observation::{ModelCallObservation, RunObservation, RunObserver};
3636
pub use raw::RawResponse;
3737
pub use run::{ClientRouter, decide, run};
3838
pub use switchyard_translation::RawEventStream;

‎crates/libsy-llm-client/src/observation.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use switchyard_protocol::{ModelId, Usage};
1111

1212
/// One completed model call observed while serving an algorithm run.
1313
#[derive(Clone, Debug)]
14-
pub struct LlmCallObservation {
14+
pub struct ModelCallObservation {
1515
/// Model selected for the completed call.
1616
pub selected_model: ModelId,
1717
/// Whether the call completed successfully.
@@ -28,11 +28,11 @@ pub enum RunObservation {
2828
/// Metadata attached to the completed routing outcome.
2929
Outcome(OutcomeMetadata),
3030
/// A completed model call requested by the algorithm for routing work.
31-
LlmCall(LlmCallObservation),
31+
LlmCall(ModelCallObservation),
3232
/// A completed decision call requested by the algorithm for routing work.
33-
DecisionCall(LlmCallObservation),
33+
DecisionCall(ModelCallObservation),
3434
/// A completed terminal model call made from the routing outcome.
35-
AnswerCall(LlmCallObservation),
35+
AnswerCall(ModelCallObservation),
3636
/// Routing time recorded by the `switchyard.routing_overhead_ms` metric.
3737
RoutingOverhead(Duration),
3838
}

‎crates/libsy-llm-client/src/run.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use switchyard_protocol::{
3737
};
3838
use switchyard_translation::prepare_request_for_target;
3939

40-
use crate::observation::{LlmCallObservation, RunObservation, RunObserver};
40+
use crate::observation::{ModelCallObservation, RunObservation, RunObserver};
4141
use crate::{metrics, observability};
4242

4343
/// Run one request to completion, serving every offloaded model call with `client`.
@@ -169,7 +169,7 @@ async fn serve_decision(
169169
if let Some(observations) = observations {
170170
observations
171171
.lock()
172-
.push(RunObservation::DecisionCall(LlmCallObservation {
172+
.push(RunObservation::DecisionCall(ModelCallObservation {
173173
selected_model: call.model.clone(),
174174
is_success: result.is_ok(),
175175
duration: started.elapsed(),
@@ -249,7 +249,7 @@ async fn call_first_available(
249249
algorithm: &str,
250250
request: &Request,
251251
models: &[ModelId],
252-
observe: &(dyn Fn(LlmCallObservation) + Send + Sync),
252+
observe: &(dyn Fn(ModelCallObservation) + Send + Sync),
253253
) -> Result<Response> {
254254
for (index, target) in models.iter().enumerate() {
255255
let request = clients.prepare_completion_request(request.clone(), target);
@@ -326,7 +326,7 @@ async fn call_one(
326326
model_id: &ModelId,
327327
request: Request,
328328
algorithm: &str,
329-
observe: &(dyn Fn(LlmCallObservation) + Send + Sync),
329+
observe: &(dyn Fn(ModelCallObservation) + Send + Sync),
330330
// index is for span log
331331
index: usize,
332332
// count is for span log
@@ -367,7 +367,7 @@ async fn call_one(
367367
} else {
368368
result
369369
};
370-
observe(LlmCallObservation {
370+
observe(ModelCallObservation {
371371
selected_model: model_id.clone(),
372372
is_success: result.is_ok(),
373373
duration,
@@ -1386,7 +1386,7 @@ mod tests {
13861386
fn answer_observation_keeps_call_order() {
13871387
let pending = Some(Arc::new(Mutex::new(
13881388
["answer", "judge"]
1389-
.map(|model| LlmCallObservation {
1389+
.map(|model| ModelCallObservation {
13901390
selected_model: model.into(),
13911391
is_success: true,
13921392
duration: std::time::Duration::ZERO,

‎crates/switchyard-nemo-relay-plugin/src/runtime.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use nemo_relay_plugin::{
1111
MetricValueType, PluginRuntime,
1212
};
1313
use serde_json::{Map, json};
14-
use switchyard_llm_client::{LlmCallObservation, RunObservation, RunObserver};
14+
use switchyard_llm_client::{ModelCallObservation, RunObservation, RunObserver};
1515
use switchyard_protocol::{
1616
LlmClientError, LlmResponse, LlmResponseChunk, LlmStreamError, Metadata, ProviderExtensions,
1717
Request, Response, Usage, WireFormat,
@@ -390,7 +390,7 @@ impl SwitchyardRuntime {
390390
fn routing_call_events(
391391
&self,
392392
events: &mut Vec<RoutingEvent>,
393-
call: LlmCallObservation,
393+
call: ModelCallObservation,
394394
call_index: usize,
395395
metadata: &Json,
396396
mark_name: &str,
@@ -734,7 +734,7 @@ fn routing_overhead_metric(latency_ms: f64, metadata: Json) -> RoutingEvent {
734734

735735
fn token_usage_metrics(
736736
call_role: &str,
737-
call: &LlmCallObservation,
737+
call: &ModelCallObservation,
738738
metadata: &Json,
739739
) -> Vec<RoutingEvent> {
740740
let Some(usage) = call.usage.as_ref() else {
@@ -1316,7 +1316,7 @@ mod tests {
13161316
runtime.emit_observations(
13171317
&mut events,
13181318
vec![
1319-
RunObservation::LlmCall(LlmCallObservation {
1319+
RunObservation::LlmCall(ModelCallObservation {
13201320
selected_model: ModelId::from("routing-model"),
13211321
is_success: false,
13221322
duration: std::time::Duration::from_millis(12),
@@ -1407,7 +1407,7 @@ mod tests {
14071407

14081408
#[test]
14091409
fn token_usage_metrics_distinguish_routing_and_answer_targets() {
1410-
let call = LlmCallObservation {
1410+
let call = ModelCallObservation {
14111411
selected_model: ModelId::from("judge-model"),
14121412
is_success: true,
14131413
duration: std::time::Duration::from_millis(1),
@@ -1469,13 +1469,13 @@ mod tests {
14691469
runtime.emit_observations(
14701470
&mut events,
14711471
vec![
1472-
RunObservation::AnswerCall(LlmCallObservation {
1472+
RunObservation::AnswerCall(ModelCallObservation {
14731473
selected_model: ModelId::from("weak-target"),
14741474
is_success: false,
14751475
duration: std::time::Duration::from_millis(2),
14761476
usage: None,
14771477
}),
1478-
RunObservation::AnswerCall(LlmCallObservation {
1478+
RunObservation::AnswerCall(ModelCallObservation {
14791479
selected_model: ModelId::from("strong-target"),
14801480
is_success: true,
14811481
duration: std::time::Duration::from_millis(3),

‎crates/switchyard-server/src/lib.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,7 @@ fn endpoint_listing(has_routing_log: bool) -> String {
16851685

16861686
#[cfg(test)]
16871687
mod tests {
1688-
use switchyard_llm_client::LlmCallObservation;
1688+
use switchyard_llm_client::ModelCallObservation;
16891689
use tokio::io::{AsyncReadExt, AsyncWriteExt};
16901690
use tokio::sync::{Notify, oneshot};
16911691

@@ -1706,7 +1706,7 @@ mod tests {
17061706
let observer = stats_observer(StatsAccumulator::default(), Some((log.clone(), context)));
17071707

17081708
let call = |model: &str, answer: bool| {
1709-
let observation = LlmCallObservation {
1709+
let observation = ModelCallObservation {
17101710
selected_model: ModelId::from(model),
17111711
is_success: true,
17121712
duration: Duration::from_millis(3),

0 commit comments

Comments
 (0)