2 个版本

0.0.1 2024 年 3 月 6 日
0.0.0 2024 年 2 月 19 日

#7#lemon

Download history 46/week @ 2024-03-10 1/week @ 2024-03-17 35/week @ 2024-03-31 1/week @ 2024-04-07

每月 75 次下载
用于 lemon-llm

MIT/Apache

20KB
449

lemon-graph

异步有向计算图,使用 petgraph

使用方法

use lemon_graph::{Graph, Executor, nodes::{NodeWrapper, LogNode}};

#[tokio::main]
async fn main() {
    let mut graph = Graph::new();

    // Create a log node and set its message.
    let log = LogNode::new(&mut graph);
    let message = log.message(&graph).unwrap();
    message.set_value(&mut graph, "Hello, world!".to_string().into());

    // Create a second log node to run after the first.
    let log_2 = LogNode::new(&mut graph);
    log_2.run_after(&mut graph, log.0);

    // Use the first log's message as input to the second log's message.
    let message_2 = log_2.message(&graph).unwrap();
    message_2.set_input(&mut graph, Some(message));

    // Execute the graph.
    Executor::execute(&mut graph, log.0).await.unwrap();
}

lib.rs:

异步有向计算图,使用 petgraph

使用方法

use lemon_graph::{Graph, Executor, nodes::{NodeWrapper, LogNode}};

#[tokio::main]
async fn main() {
    let mut graph = Graph::new();

    // Create a log node and set its message.
    let log = LogNode::new(&mut graph);
    let message = log.message(&graph).unwrap();
    message.set_value(&mut graph, "Hello, world!".to_string().into());

    // Create a second log node to run after the first.
    let log_2 = LogNode::new(&mut graph);
    log_2.run_after(&mut graph, log.0);

    // Use the first log's message as input to the second log's message.
    let message_2 = log_2.message(&graph).unwrap();
    message_2.set_input(&mut graph, Some(message));

    // Execute the graph.
    Executor::execute(&mut graph, log.0).await.unwrap();
}

依赖项

~5–12MB
~110K SLoC