Crate claude_flows

source ·
Expand description

Claude integration for Flows.network

Quick Start

To get started, let’s write a tiny flow function.

use claude_flows::{
    chat,
    ClaudeFlows,
};
use lambda_flows::{request_received, send_response};
use serde_json::Value;
use std::collections::HashMap;

#[no_mangle]
#[tokio::main(flavor = "current_thread")]
pub async fn run() {
    request_received(handler).await;
}

async fn handler(_qry: HashMap<String, Value>, body: Vec<u8>) {
    let cf = ClaudeFlows::new();
    let co = chat::ChatOptions::default();

    let r = match cf.chat_completion(
        "any_conversation_id",
        String::from_utf8_lossy(&body).into_owned().as_str(),
        &co,
    )
    .await
    {
        Ok(c) => c,
        Err(e) => e,
    };
     
    send_response(
        200,
        vec![(
            String::from("content-type"),
            String::from("text/plain; charset=UTF-8"),
        )],
        r.as_bytes().to_vec(),
    );
}

When the Lambda request is received, chat using [chat_completion] then send the response.

Modules

Structs

  • The main struct for setting the basic configuration for Claude interface.

Enums