Skip to content

DummyLM should share a trait with LM #77

@darinkishore

Description

@darinkishore

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions