Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ target/
.workspaces/
.beads
.jj/
.codegraph/


# These are backup files generated by rustfmt
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ members = [
"vendor/baml/crates/*",
]

[workspace.package]
edition = "2024"
rust-version = "1.96.0"

[patch.crates-io]
# TODO(dsrs-facet-pin): switch back to upstream main/release once #2040/#2041 are merged and released.
facet = { git = "https://github.com/darinkishore/facet", rev = "cc8613c97cd1ec03e63659db34a947989b45c8a5" }
Expand Down
1 change: 1 addition & 0 deletions crates/bamltype-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "bamltype-derive"
version = "0.1.0"
edition = "2024"
rust-version = "1.96.0"
license = "Apache-2.0"
publish = false
description = "Attribute macro for facet-based BAML type generation (proc-macro crate)"
Expand Down
1 change: 1 addition & 0 deletions crates/bamltype/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "bamltype"
version = "0.1.0"
edition = "2024"
rust-version = "1.96.0"
license = "Apache-2.0"
publish = false
description = "Facet-based BAML type generation"
Expand Down
1 change: 1 addition & 0 deletions crates/dspy-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "dspy-rs"
authors = ["Herumb Shandilya <herumb@stanford.edu>"]
version = "0.7.3"
edition = "2024"
rust-version = "1.96.0"
description = "A DSPy rewrite(not port) to Rust."
readme = "../../README.md"
documentation = "https://dsrs.herumbshandilya.com"
Expand Down
88 changes: 87 additions & 1 deletion crates/dspy-rs/src/core/dyn_predictor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,93 @@ facet::define_attr_grammar! {
}
}

pub(crate) mod dsrs {
macro_rules! __attr {
(@ns { $ns:path } predict_accessor { $field:tt : $ty:ty }) => {{
static __ATTR_DATA: $crate::core::dyn_predictor::Attr =
$crate::core::dyn_predictor::Attr::PredictAccessor(None);
::facet::Attr::new(Some("dsrs"), "predict_accessor", &__ATTR_DATA)
}};
(@ns { $ns:path } predict_accessor { $field:tt : $ty:ty | = $value:expr }) => {{
::facet::Attr::new(
Some("dsrs"),
"predict_accessor",
&const { $crate::core::dyn_predictor::Attr::PredictAccessor(Some($value)) },
)
}};
(@ns { $ns:path } predict_accessor { $field:tt : $ty:ty | $value:expr }) => {{
::facet::Attr::new(
Some("dsrs"),
"predict_accessor",
&const { $crate::core::dyn_predictor::Attr::PredictAccessor(Some($value)) },
)
}};
(@ns { $ns:path } predict_accessor { }) => {{
static __ATTR_DATA: $crate::core::dyn_predictor::Attr =
$crate::core::dyn_predictor::Attr::PredictAccessor(None);
::facet::Attr::new(Some("dsrs"), "predict_accessor", &__ATTR_DATA)
}};
(@ns { $ns:path } predict_accessor { | = $value:expr }) => {{
::facet::Attr::new(
Some("dsrs"),
"predict_accessor",
&const { $crate::core::dyn_predictor::Attr::PredictAccessor(Some($value)) },
)
}};
(@ns { $ns:path } predict_accessor { | $value:expr }) => {{
::facet::Attr::new(
Some("dsrs"),
"predict_accessor",
&const { $crate::core::dyn_predictor::Attr::PredictAccessor(Some($value)) },
)
}};
(@const @ns { $ns:path } predict_accessor { $field:tt : $ty:ty }) => {{
::facet::Attr::new(
Some("dsrs"),
"predict_accessor",
&const { $crate::core::dyn_predictor::Attr::PredictAccessor(None) },
)
}};
(@const @ns { $ns:path } predict_accessor { $field:tt : $ty:ty | = $value:expr }) => {{
::facet::Attr::new(
Some("dsrs"),
"predict_accessor",
&const { $crate::core::dyn_predictor::Attr::PredictAccessor(Some($value)) },
)
}};
(@const @ns { $ns:path } predict_accessor { $field:tt : $ty:ty | $value:expr }) => {{
::facet::Attr::new(
Some("dsrs"),
"predict_accessor",
&const { $crate::core::dyn_predictor::Attr::PredictAccessor(Some($value)) },
)
}};
(@const @ns { $ns:path } predict_accessor { }) => {{
::facet::Attr::new(
Some("dsrs"),
"predict_accessor",
&const { $crate::core::dyn_predictor::Attr::PredictAccessor(None) },
)
}};
(@const @ns { $ns:path } predict_accessor { | = $value:expr }) => {{
::facet::Attr::new(
Some("dsrs"),
"predict_accessor",
&const { $crate::core::dyn_predictor::Attr::PredictAccessor(Some($value)) },
)
}};
(@const @ns { $ns:path } predict_accessor { | $value:expr }) => {{
::facet::Attr::new(
Some("dsrs"),
"predict_accessor",
&const { $crate::core::dyn_predictor::Attr::PredictAccessor(Some($value)) },
)
}};
}

pub(crate) use __attr;
}

/// Error from [`visit_named_predictors_mut`] when the Facet walker encounters an unsupported structure.
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
pub(crate) enum NamedParametersError {
Expand Down Expand Up @@ -396,7 +483,6 @@ fn pointer_name(pointer: Option<KnownPointer>) -> &'static str {
#[cfg(test)]
mod tests {
use super::*;
use crate as dsrs;
use crate::Signature;
use crate::predictors::Predict as RealPredict;
use std::ops::ControlFlow;
Expand Down
2 changes: 1 addition & 1 deletion crates/dspy-rs/src/core/lm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ impl LM {
ChoiceAction::ToolCalls {
calls,
full_content,
assistant_text,
assistant_text: _,
} if tool_loop_mode == ToolLoopMode::Auto && !tools.is_empty() => {
debug!(count = calls.len(), "entering tool loop");
let result = self
Expand Down
5 changes: 3 additions & 2 deletions crates/dspy-rs/src/predictors/predict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use std::ops::ControlFlow;
use std::sync::Arc;
use tracing::{debug, trace};

use crate as dsrs;
use crate::core::{DynPredictor, Module, PredictAccessorFns, PredictState, Signature};
use crate::core::{
DynPredictor, Module, PredictAccessorFns, PredictState, Signature, dyn_predictor::dsrs,
};
use crate::data::example::Example as RawExample;
use crate::{
BamlType, BamlValue, CallMetadata, Chat, ChatAdapter, GLOBAL_SETTINGS, LmError, LmUsage,
Expand Down
4 changes: 1 addition & 3 deletions crates/dspy-rs/tests/test_predict_lm_override.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ async fn predict_uses_per_instance_lm_over_global() {
let (override_lm, _override_client) = make_test_lm(vec![override_response]).await;

// Predict with per-instance LM override
let predict = Predict::<QA>::builder()
.lm(override_lm)
.build();
let predict = Predict::<QA>::builder().lm(override_lm).build();

let result = predict
.call(QAInput {
Expand Down
6 changes: 4 additions & 2 deletions crates/dspy-rs/tests/test_public_api_compile_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ fn run_compile_fail_case(name: &str, source: &str) -> String {
let case_dir = temp.path().join(name);
fs::create_dir_all(case_dir.join("src")).expect("case src dir should be creatable");

let manifest_path = Path::new(env!("CARGO_MANIFEST_DIR"));
let manifest_path = Path::new(env!("CARGO_MANIFEST_DIR"))
.to_string_lossy()
.replace('\\', "/");
let cargo_toml = format!(
"[package]\nname = \"{name}\"\nversion = \"0.1.0\"\nedition = \"2024\"\n\n[dependencies]\ndspy-rs = {{ path = \"{}\" }}\nanyhow = \"1\"\n",
manifest_path.display()
manifest_path
);

fs::write(case_dir.join("Cargo.toml"), cargo_toml).expect("cargo manifest should be writable");
Expand Down
1 change: 1 addition & 0 deletions crates/dsrs-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "dsrs_macros"
version = "0.7.2"
edition = "2024"
rust-version = "1.96.0"
authors = ["Herumb Shandilya <herumb@stanford.edu>"]
description = "Derive macros for DSRs (DSPy Rust)"
readme = "../../README.md"
Expand Down
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "1.96.0"
3 changes: 2 additions & 1 deletion vendor/baml/crates/baml-ids/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[package]
edition = "2021"
edition = "2024"
name = "baml-ids"
version = "0.0.1"
rust-version = "1.96.0"
license = "Apache-2.0"
publish = false
description = "Typesafe IDs for BAML backends and runtime"
Expand Down
3 changes: 2 additions & 1 deletion vendor/baml/crates/baml-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[package]
edition = "2021"
edition = "2024"
name = "baml-types"
version = "0.1.0"
rust-version = "1.96.0"
license = "Apache-2.0"
publish = false
description = "BAML type system and IR"
Expand Down
5 changes: 3 additions & 2 deletions vendor/baml/crates/baml-types/src/baml_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ use std::{
use anyhow::{Context, Result};
use indexmap::IndexMap;
use pretty::RcDoc;
use serde::{de::Visitor, ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer};
use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Visitor, ser::SerializeMap};

use crate::{
BamlMap, BamlMedia, HasType, LiteralValue, ResponseCheck, TypeValue,
ir_type::{
TypeGeneric, TypeIR, TypeNonStreaming, TypeStreaming, UnionConstructor,
UnionTypeViewGeneric,
},
media::BamlMediaType,
type_meta, BamlMap, BamlMedia, HasType, LiteralValue, ResponseCheck, TypeValue,
type_meta,
};

#[derive(Clone, Debug, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion vendor/baml/crates/baml-types/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
use internal_baml_diagnostics::Span;
use itertools::join;

use crate::{ir_type::TypeIR, BamlMap, BamlValueWithMeta};
use crate::{BamlMap, BamlValueWithMeta, ir_type::TypeIR};

/// A BAML expression term.
/// T is the type of the metadata.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::{
StreamingMode, TypeIR, TypeValue,
baml_value::TypeLookups,
ir_type::{ArrowGeneric, TypeNonStreaming, UnionTypeGeneric},
type_meta, StreamingMode, TypeIR, TypeValue,
type_meta,
};

pub fn from_type_ir(r#type: &TypeIR, _lookup: &impl TypeLookups) -> TypeNonStreaming {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::{
BamlMediaType, StreamingMode, TypeIR, TypeValue,
baml_value::TypeLookups,
ir_type::{ArrowGeneric, TypeStreaming, UnionTypeGeneric},
type_meta, BamlMediaType, StreamingMode, TypeIR, TypeValue,
type_meta,
};

pub fn from_type_ir(r#type: &TypeIR, lookup: &impl TypeLookups) -> TypeStreaming {
Expand Down
2 changes: 1 addition & 1 deletion vendor/baml/crates/baml-types/src/ir_type/display.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fmt::{self, Formatter};

use super::{type_meta, ConstraintLevel, TypeGeneric};
use super::{ConstraintLevel, TypeGeneric, type_meta};
use crate::ir_type::UnionTypeViewGeneric;

/// ---------- 1. The helper that prints the *core* type string ----------
Expand Down
Loading