1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//! # LangSmith Observability for Wesichain
//!
//! Enable LangSmith tracing with either callback handlers (core callbacks) or the
//! graph observer integration.
//!
//! ## Callback handler
//!
//! ```no_run
//! use std::collections::BTreeMap;
//! use std::sync::Arc;
//!
//! use futures::StreamExt;
//! use secrecy::SecretString;
//! use wesichain_core::{CallbackManager, RunConfig, Runnable, WesichainError};
//! use wesichain_graph::{ExecutionOptions, GraphBuilder, GraphState, StateSchema, StateUpdate};
//! use wesichain_langsmith::{LangSmithCallbackHandler, LangSmithConfig};
//!
//! #[derive(Clone, Default, Debug, serde::Serialize, serde::Deserialize)]
//! struct DemoState {
//! value: usize,
//! }
//!
//! impl StateSchema for DemoState {
//! type Update = Self;
//! fn apply(_: &Self, update: Self) -> Self {
//! update
//! }
//! }
//!
//! struct IncrNode;
//!
//! #[async_trait::async_trait]
//! impl Runnable<GraphState<DemoState>, StateUpdate<DemoState>> for IncrNode {
//! async fn invoke(
//! &self,
//! input: GraphState<DemoState>,
//! ) -> Result<StateUpdate<DemoState>, WesichainError> {
//! Ok(StateUpdate::new(DemoState {
//! value: input.data.value + 1,
//! }))
//! }
//!
//! fn stream(
//! &self,
//! _input: GraphState<DemoState>,
//! ) -> futures::stream::BoxStream<'_, Result<wesichain_core::StreamEvent, WesichainError>> {
//! futures::stream::empty().boxed()
//! }
//! }
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let config = LangSmithConfig::new(SecretString::new("ls-api-key".to_string()), "demo");
//! let handler = Arc::new(LangSmithCallbackHandler::new(config));
//! let manager = CallbackManager::new(vec![handler]);
//!
//! let options = ExecutionOptions {
//! run_config: Some(RunConfig {
//! callbacks: Some(manager),
//! tags: vec!["example".to_string()],
//! metadata: BTreeMap::new(),
//! name_override: Some("demo-graph".to_string()),
//! }),
//! ..Default::default()
//! };
//!
//! let graph = GraphBuilder::new()
//! .add_node("incr", IncrNode)
//! .set_entry("incr")
//! .build();
//! let _ = graph
//! .invoke_with_options(GraphState::new(DemoState::default()), options)
//! .await?;
//! Ok(())
//! }
//! ```
//!
//! ## Graph observer
//!
//! ```rust,no_run
//! use std::sync::Arc;
//! use std::time::Duration;
//!
//! use secrecy::SecretString;
//! use wesichain_graph::{ExecutionOptions, ExecutableGraph, GraphState, StateSchema};
//! use wesichain_langsmith::{LangSmithConfig, LangSmithObserver};
//!
//! #[derive(Clone, Default, Debug, serde::Serialize, serde::Deserialize)]
//! struct DemoState;
//!
//! impl StateSchema for DemoState {
//! type Update = Self;
//! fn apply(_: &Self, update: Self) -> Self {
//! update
//! }
//! }
//!
//! #[tokio::main]
//! async fn main() {
//! let config = LangSmithConfig::new(SecretString::new("key".to_string()), "example");
//! let observer = Arc::new(LangSmithObserver::new(config));
//! let options = ExecutionOptions {
//! observer: Some(observer.clone()),
//! ..Default::default()
//! };
//!
//! let graph: ExecutableGraph<DemoState> = todo!("build with GraphBuilder");
//! let state = GraphState::new(DemoState::default());
//! let _ = graph.invoke_with_options(state, options).await;
//! let _ = observer.flush(Duration::from_secs(5)).await;
//! }
//! ```
pub use ;
pub use LangSmithConfig;
pub use ;
pub use ;
pub use LangSmithCallbackHandler;
pub use LangSmithObserver;
pub use ;
pub use ;
pub use ;