Problem
LM and DummyLM are structurally separate types with duplicated APIs:
- Both have
call(), inspect_history(), cache_handler, temperature, max_tokens
- But they don't share a trait — code that wants to be generic over "any LM" can't be
DSPy Python has BaseLM as the abstract base class that both real and mock implementations extend.
Proposal
Extract a shared trait:
#[async_trait]
pub trait LanguageModel: Send + Sync {
async fn call(&self, messages: Chat, tools: Vec<Arc<dyn ToolDyn>>) -> Result<LMResponse>;
async fn inspect_history(&self, n: usize) -> Vec<HistoryEntry>;
fn model(&self) -> &str;
}
LM and DummyLM both impl this. GLOBAL_SETTINGS stores Arc<dyn LanguageModel>. Modules reference the trait, not the concrete type.
Related
Problem
LMandDummyLMare structurally separate types with duplicated APIs:call(),inspect_history(),cache_handler,temperature,max_tokensDSPy Python has
BaseLMas the abstract base class that both real and mock implementations extend.Proposal
Extract a shared trait:
LMandDummyLMboth impl this.GLOBAL_SETTINGSstoresArc<dyn LanguageModel>. Modules reference the trait, not the concrete type.Related