Skip to content

Commit fb3fc30

Browse files
authored
chore: Collapse CallModelRequest, remove Context (#341)
Big progress towards refactor in #310 - Replace `CallModelRequest` with passing the fields directly to `call_model`. The extra type wasn't necessary. - Remove `Context`, moving the only field it contained (`algorithm`) into `Driver`. This fixes a TODO in `llm_class.rs` where the Context was missing that value. - Drop the `Arc` on `CallModel`'s `Decision`. Now that `Decision` is a struct, cloning it is cheap (two short strings). - Adds `into_parts` to allow caller to handle the final call. This calls `respond` with an `Abandoned` error to let the algorithm know. Most of the diff is `Arc<Decision>` -> `Decision` and removing param `ctx` from everywhere. Assisted-by: Claude:Opus 5 medium Signed-off-by: Graham King <grahamk@nvidia.com>
1 parent bced06f commit fb3fc30

22 files changed

Lines changed: 436 additions & 733 deletions

File tree

crates/libsy-llm-client/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn build_client() -> switchyard_llm_client::Result<TranslatingLlmClient> {
8080

8181
```rust
8282
use switchyard_llm_client::{LlmClientError, TranslatingLlmClient};
83-
use switchyard_protocol::{completion_text, text_request, Context, LlmResponse, Request};
83+
use switchyard_protocol::{completion_text, text_request, LlmResponse, Request};
8484

8585
async fn ask(client: &TranslatingLlmClient) -> switchyard_llm_client::Result<String> {
8686
let request = Request {
@@ -91,7 +91,7 @@ async fn ask(client: &TranslatingLlmClient) -> switchyard_llm_client::Result<Str
9191

9292
// model_name wins over request.llm_request.model; it is also sent upstream.
9393
let response = client
94-
.call_rewrite_model(Context::default(), request, Some("gpt-4o-mini"))
94+
.call_rewrite_model(request, Some("gpt-4o-mini"))
9595
.await?;
9696

9797
match response.llm_response {
@@ -110,7 +110,7 @@ Set `stream` on the IR request and drive the returned chunk stream:
110110
```rust
111111
use futures_util::StreamExt;
112112
use switchyard_llm_client::TranslatingLlmClient;
113-
use switchyard_protocol::{text_request, Context, LlmResponse, LlmResponseChunk, Request};
113+
use switchyard_protocol::{text_request, LlmResponse, LlmResponseChunk, Request};
114114

115115
async fn stream(
116116
client: &TranslatingLlmClient,
@@ -120,7 +120,7 @@ async fn stream(
120120
let request = Request { llm_request, raw_request: None, metadata: None };
121121

122122
let response = client
123-
.call_rewrite_model(Context::default(), request, Some("gpt-4o-mini"))
123+
.call_rewrite_model(request, Some("gpt-4o-mini"))
124124
.await?;
125125

126126
if let LlmResponse::Stream(mut chunks) = response.llm_response {
@@ -147,7 +147,7 @@ single-provider case:
147147
use std::sync::Arc;
148148
use switchyard_libsy::Algorithm;
149149
use switchyard_llm_client::{ClientRouter, TranslatingLlmClient};
150-
use switchyard_protocol::{Context, Request};
150+
use switchyard_protocol::Request;
151151

152152
async fn route(
153153
algorithm: Arc<dyn Algorithm>,
@@ -156,7 +156,7 @@ async fn route(
156156
) -> switchyard_libsy::Result<String> {
157157
let clients = ClientRouter::single(client);
158158
let (trace, _response) =
159-
switchyard_llm_client::run(algorithm, clients, Context::default(), request, None).await?;
159+
switchyard_llm_client::run(algorithm, clients, request, None).await?;
160160
Ok(trace
161161
.last()
162162
.map(|decision| decision.selected_model_id().to_string())

0 commit comments

Comments
 (0)