diff --git a/engine/Cargo.lock b/engine/Cargo.lock index fd95a5f29..a2c0ea492 100644 --- a/engine/Cargo.lock +++ b/engine/Cargo.lock @@ -932,6 +932,7 @@ dependencies = [ "axum-extra", "baml-types", "base64 0.22.1", + "btrace", "bytes", "cfg-if", "chrono", @@ -971,7 +972,6 @@ dependencies = [ "mime", "mime_guess", "minijinja", - "nonempty", "notify-debouncer-full", "pin-project-lite", "pretty_assertions", @@ -3217,12 +3217,6 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "nonempty" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "549e471b99ccaf2f89101bec68f4d244457d5a95a9c3d0672e9564124397741d" - [[package]] name = "notify" version = "6.1.1" diff --git a/engine/Cargo.toml b/engine/Cargo.toml index 159e1cd0b..78c2e51f1 100644 --- a/engine/Cargo.toml +++ b/engine/Cargo.toml @@ -35,8 +35,10 @@ anyhow = "1.0" array-macro = "2" askama = "0.12.1" baml-cli = { path = "cli" } +baml-types = { path = "baml-lib/baml-types" } base64 = "0.22.1" bstd = { path = "bstd" } +btrace = { path = "btrace" } bytes = "1.6.0" cfg-if = "1.0.0" clap = { version = "4.4.6", features = ["cargo", "derive"] } @@ -50,6 +52,12 @@ http = "1.1.0" http-body = "1.0.0" indexmap = { version = "2.1.0", features = ["serde"] } indoc = "2.0.5" +jsonish = { path = "baml-lib/jsonish" } +internal-baml-codegen = { path = "language_client_codegen" } +internal-baml-core = { path = "baml-lib/baml-core" } +internal-baml-jinja = { path = "baml-lib/jinja-runtime" } +internal-baml-schema-ast = { path = "baml-lib/schema-ast" } +internal-llm-client = { path = "baml-lib/llm-client" } log = "0.4.20" # TODO: disable imports, etc minijinja = { version = "1.0.16", default-features = false, features = [ @@ -92,11 +100,6 @@ uuid = { version = "1.8.0", features = ["v4", "v7", "serde"] } walkdir = "2.5.0" web-time = "1.1.0" -baml-types = { path = "baml-lib/baml-types" } -internal-baml-codegen = { path = "language_client_codegen" } -internal-baml-core = { path = "baml-lib/baml-core" } -internal-baml-jinja = { path = "baml-lib/jinja" } -internal-baml-schema-ast = { path = "baml-lib/schema-ast" } [workspace.package] version = "0.70.1" diff --git a/engine/baml-runtime/Cargo.toml b/engine/baml-runtime/Cargo.toml index e4433314b..fc08dd52e 100644 --- a/engine/baml-runtime/Cargo.toml +++ b/engine/baml-runtime/Cargo.toml @@ -20,6 +20,7 @@ unused_variables = "allow" [dependencies] anyhow.workspace = true base64.workspace = true +btrace.workspace = true bytes.workspace = true cfg-if.workspace = true clap.workspace = true @@ -37,15 +38,14 @@ indexmap.workspace = true indoc.workspace = true # instant = "0.1" # do not use this or wasm-timer - use web-time instead json_comments = "0.2.2" -jsonish = { path = "../baml-lib/jsonish" } +jsonish.workspace = true internal-baml-codegen.workspace = true -baml-types = { path = "../baml-lib/baml-types" } -internal-llm-client = { path = "../baml-lib/llm-client" } -internal-baml-core = { path = "../baml-lib/baml-core" } -internal-baml-jinja = { path = "../baml-lib/jinja-runtime" } +baml-types.workspace = true +internal-llm-client.workspace = true +internal-baml-core.workspace = true +internal-baml-jinja.workspace = true log.workspace = true minijinja.workspace = true -nonempty = "0.11.0" pin-project-lite.workspace = true reqwest-eventsource = "0.6.0" scopeguard.workspace = true diff --git a/engine/baml-runtime/src/internal/llm_client/orchestrator/mod.rs b/engine/baml-runtime/src/internal/llm_client/orchestrator/mod.rs index 8a9238b60..ff4111c38 100644 --- a/engine/baml-runtime/src/internal/llm_client/orchestrator/mod.rs +++ b/engine/baml-runtime/src/internal/llm_client/orchestrator/mod.rs @@ -4,7 +4,7 @@ mod stream; use serde_json::json; use web_time::Duration; // Add this line -use crate::btrace::WithTraceContext; +use btrace::WithTraceContext; use crate::RenderCurlSettings; use crate::{ internal::prompt_renderer::PromptRenderer, runtime_interface::InternalClientLookup, diff --git a/engine/baml-runtime/src/internal/llm_client/orchestrator/stream.rs b/engine/baml-runtime/src/internal/llm_client/orchestrator/stream.rs index 8561c9424..91570b06a 100644 --- a/engine/baml-runtime/src/internal/llm_client/orchestrator/stream.rs +++ b/engine/baml-runtime/src/internal/llm_client/orchestrator/stream.rs @@ -1,13 +1,13 @@ use anyhow::Result; use async_std::stream::StreamExt; use baml_types::BamlValue; +use btrace::WithTraceContext; use internal_baml_core::ir::repr::IntermediateRepr; use jsonish::BamlValueWithFlags; use serde_json::json; use web_time::Duration; use crate::{ - btrace::{self, WithTraceContext}, internal::{ llm_client::{ parsed_value_to_response, diff --git a/engine/baml-runtime/src/internal/llm_client/primitive/anthropic/anthropic_client.rs b/engine/baml-runtime/src/internal/llm_client/primitive/anthropic/anthropic_client.rs index f947c412a..1109b8642 100644 --- a/engine/baml-runtime/src/internal/llm_client/primitive/anthropic/anthropic_client.rs +++ b/engine/baml-runtime/src/internal/llm_client/primitive/anthropic/anthropic_client.rs @@ -1,10 +1,8 @@ -use crate::{ - btrace::{self, WithTraceContext}, - internal::llm_client::{ - traits::{ToProviderMessage, ToProviderMessageExt, WithClientProperties}, - ResolveMediaUrls, - }, +use crate::internal::llm_client::{ + traits::{ToProviderMessage, ToProviderMessageExt, WithClientProperties}, + ResolveMediaUrls, }; +use btrace::WithTraceContext; use std::collections::HashMap; use anyhow::{Context, Result}; diff --git a/engine/baml-runtime/src/internal/llm_client/primitive/aws/aws_client.rs b/engine/baml-runtime/src/internal/llm_client/primitive/aws/aws_client.rs index 55217f654..2140691fb 100644 --- a/engine/baml-runtime/src/internal/llm_client/primitive/aws/aws_client.rs +++ b/engine/baml-runtime/src/internal/llm_client/primitive/aws/aws_client.rs @@ -23,7 +23,6 @@ use serde_json::{json, Map}; use web_time::Instant; use web_time::SystemTime; -use crate::btrace::WithTraceContext; use crate::client_registry::ClientProperty; use crate::internal::llm_client::traits::{ToProviderMessageExt, WithClientProperties}; use crate::internal::llm_client::{ @@ -35,8 +34,9 @@ use crate::internal::llm_client::{ ErrorCode, LLMCompleteResponse, LLMCompleteResponseMetadata, LLMErrorResponse, LLMResponse, ModelFeatures, ResolveMediaUrls, }; +use btrace::WithTraceContext; -use crate::{btrace, RenderCurlSettings, RuntimeContext}; +use crate::{RenderCurlSettings, RuntimeContext}; // represents client that interacts with the Anthropic API pub struct AwsClient { diff --git a/engine/baml-runtime/src/internal/llm_client/primitive/google/googleai_client.rs b/engine/baml-runtime/src/internal/llm_client/primitive/google/googleai_client.rs index 7002c3d60..d7c785371 100644 --- a/engine/baml-runtime/src/internal/llm_client/primitive/google/googleai_client.rs +++ b/engine/baml-runtime/src/internal/llm_client/primitive/google/googleai_client.rs @@ -1,10 +1,9 @@ -use crate::btrace::WithTraceContext; use crate::client_registry::ClientProperty; use crate::internal::llm_client::traits::{ ToProviderMessage, ToProviderMessageExt, WithClientProperties, }; use crate::internal::llm_client::ResolveMediaUrls; -use crate::{btrace, RuntimeContext}; +use crate::RuntimeContext; use crate::{ internal::llm_client::{ primitive::{ @@ -22,6 +21,7 @@ use crate::{ }; use anyhow::{Context, Result}; use baml_types::{BamlMap, BamlMedia, BamlMediaContent}; +use btrace::WithTraceContext; use eventsource_stream::Eventsource; use futures::StreamExt; use http::header; diff --git a/engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs b/engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs index 6b0b86ec2..0c9a2c129 100644 --- a/engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs +++ b/engine/baml-runtime/src/internal/llm_client/primitive/openai/openai_client.rs @@ -1,9 +1,9 @@ use std::collections::HashMap; -use crate::btrace::WithTraceContext; use crate::internal::llm_client::ResolveMediaUrls; use anyhow::Result; use baml_types::{BamlMap, BamlMedia, BamlMediaContent, BamlMediaType}; +use btrace::WithTraceContext; use internal_baml_core::ir::ClientWalker; use internal_baml_jinja::{ChatMessagePart, RenderContext_Client, RenderedChatMessage}; use internal_llm_client::openai::ResolvedOpenAI; @@ -31,7 +31,7 @@ use crate::internal::llm_client::{ }; use crate::request::create_client; -use crate::{btrace, RuntimeContext}; +use crate::RuntimeContext; use eventsource_stream::Eventsource; use futures::StreamExt; diff --git a/engine/baml-runtime/src/internal/llm_client/primitive/vertex/vertex_client.rs b/engine/baml-runtime/src/internal/llm_client/primitive/vertex/vertex_client.rs index 3825c658b..7c1a2c05c 100644 --- a/engine/baml-runtime/src/internal/llm_client/primitive/vertex/vertex_client.rs +++ b/engine/baml-runtime/src/internal/llm_client/primitive/vertex/vertex_client.rs @@ -1,4 +1,3 @@ -use crate::btrace::WithTraceContext; use crate::client_registry::ClientProperty; use crate::internal::llm_client::traits::{ ToProviderMessage, ToProviderMessageExt, WithClientProperties, @@ -6,7 +5,7 @@ use crate::internal::llm_client::traits::{ use crate::internal::llm_client::ResolveMediaUrls; #[cfg(target_arch = "wasm32")] use crate::internal::wasm_jwt::{encode_jwt, JwtError}; -use crate::{btrace, RuntimeContext}; +use crate::RuntimeContext; use crate::{ internal::llm_client::{ primitive::{ @@ -23,6 +22,7 @@ use crate::{ request::create_client, }; use anyhow::{Context, Result}; +use btrace::WithTraceContext; use chrono::{Duration, Utc}; use futures::StreamExt; use internal_llm_client::vertex::{ResolvedServiceAccountDetails, ResolvedVertex, ServiceAccount}; diff --git a/engine/baml-runtime/src/internal/llm_client/traits/mod.rs b/engine/baml-runtime/src/internal/llm_client/traits/mod.rs index 759020506..b7e0e36f5 100644 --- a/engine/baml-runtime/src/internal/llm_client/traits/mod.rs +++ b/engine/baml-runtime/src/internal/llm_client/traits/mod.rs @@ -12,10 +12,11 @@ pub use self::{ completion::{WithCompletion, WithNoCompletion, WithStreamCompletion}, }; use super::{primitive::request::RequestBuilder, LLMResponse, ModelFeatures}; -use crate::{btrace::WithTraceContext, internal::llm_client::ResolveMediaUrls, RenderCurlSettings}; +use crate::{internal::llm_client::ResolveMediaUrls, RenderCurlSettings}; use crate::{internal::prompt_renderer::PromptRenderer, RuntimeContext}; use baml_types::{BamlMedia, BamlMediaContent, BamlMediaType, BamlValue, MediaBase64, MediaUrl}; use base64::{prelude::BASE64_STANDARD, Engine}; +use btrace::WithTraceContext; use futures::stream::StreamExt; use infer; use internal_baml_core::ir::repr::IntermediateRepr; diff --git a/engine/baml-runtime/src/lib.rs b/engine/baml-runtime/src/lib.rs index 677267030..ec6295d7b 100644 --- a/engine/baml-runtime/src/lib.rs +++ b/engine/baml-runtime/src/lib.rs @@ -5,7 +5,6 @@ pub mod internal; #[cfg(not(feature = "internal"))] pub(crate) mod internal; -pub mod btrace; #[cfg(not(target_arch = "wasm32"))] pub mod cli; pub mod client_registry; diff --git a/engine/baml-runtime/src/runtime/runtime_interface.rs b/engine/baml-runtime/src/runtime/runtime_interface.rs index 59f3188ac..68e3292ce 100644 --- a/engine/baml-runtime/src/runtime/runtime_interface.rs +++ b/engine/baml-runtime/src/runtime/runtime_interface.rs @@ -1,7 +1,6 @@ use std::{collections::HashMap, path::PathBuf, sync::Arc}; use super::InternalBamlRuntime; -use crate::btrace; use crate::internal::llm_client::traits::WithClientProperties; use crate::internal::llm_client::LLMResponse; use crate::{ diff --git a/engine/baml-runtime/src/runtime_interface.rs b/engine/baml-runtime/src/runtime_interface.rs index 2d72648fc..8202c2d00 100644 --- a/engine/baml-runtime/src/runtime_interface.rs +++ b/engine/baml-runtime/src/runtime_interface.rs @@ -10,13 +10,13 @@ use crate::internal::llm_client::llm_provider::LLMProvider; use crate::internal::llm_client::orchestrator::{OrchestrationScope, OrchestratorNode}; use crate::tracing::{BamlTracer, TracingSpan}; use crate::types::on_log_event::LogEventCallbackSync; -use crate::{btrace, RenderCurlSettings, RuntimeContextManager}; use crate::{ internal::{ir_features::IrFeatures, llm_client::retry_policy::CallablePolicy}, runtime::InternalBamlRuntime, types::FunctionResultStream, FunctionResult, RuntimeContext, }; +use crate::{RenderCurlSettings, RuntimeContextManager}; pub(crate) trait RuntimeConstructor { #[cfg(not(target_arch = "wasm32"))] diff --git a/engine/baml-runtime/src/types/stream.rs b/engine/baml-runtime/src/types/stream.rs index fbc34866f..79ae64133 100644 --- a/engine/baml-runtime/src/types/stream.rs +++ b/engine/baml-runtime/src/types/stream.rs @@ -6,7 +6,6 @@ use serde_json::json; use std::sync::Arc; use crate::{ - btrace::{self, WithTraceContext}, client_registry::ClientRegistry, internal::{ llm_client::orchestrator::{orchestrate_stream, OrchestratorNodeIterator}, @@ -16,6 +15,7 @@ use crate::{ type_builder::TypeBuilder, FunctionResult, RuntimeContextManager, }; +use btrace::WithTraceContext; /// Wrapper that holds a stream of responses from a BAML function call. /// diff --git a/engine/btrace/Cargo.toml b/engine/btrace/Cargo.toml index ba936e60b..c1bce32db 100644 --- a/engine/btrace/Cargo.toml +++ b/engine/btrace/Cargo.toml @@ -13,7 +13,7 @@ crate-type = ["cdylib", "rlib"] RSTEST_TIMEOUT = "10" [lints.rust] -dead_code = "deny" +dead_code = "warn" unused_imports = "deny" unused_variables = "deny" diff --git a/engine/btrace/tracer_thread.rs b/engine/btrace/src/tracer_thread.rs similarity index 98% rename from engine/btrace/tracer_thread.rs rename to engine/btrace/src/tracer_thread.rs index 46492868f..81b6bef4f 100644 --- a/engine/btrace/tracer_thread.rs +++ b/engine/btrace/src/tracer_thread.rs @@ -1,5 +1,3 @@ -use crate::btrace::InstrumentationScope; - use super::TraceEvent; pub struct TracerThread { rx: tokio::sync::mpsc::UnboundedReceiver,