Initializing

Using SmartGPT as a library in Rust.

SmartGPT can both be used as a CLI by directly running the program, or as a crate that you can interact with in your programs. Using it as a crate, though, can be very beneficial if you want to integrate it in your applications, or experiment with it in oher ways.

You can install the crate like so:

cargo add smartgpt

Then, try initializing SmartGPT:

let smartgpt = SmartGPT {
    personality: "A superintelligent AI".to_string(),
    context: Arc::new(Mutex::new(CommandContext {
        agents: Agents::same(|| Ok(AgentInfo {
            llm: LLM::from_provider(ChatGPTProvider, ChatGPTConfig {
                api_key: "X".to_string(),
                ..Default::default()
            })?,
            observations: memory_from_provider(LocalProvider, Value::Null)?,
            reflections: memory_from_provider(LocalProvider, Value::Null)?
        }))?,
        plugin_data: PluginStore::new(),
        assets: HashMap::new(),
        plugins: vec![
            create_google(),
            create_browse()
        ],
        disabled_tools: vec![]
    }))
}

The key observation to make is the use of providers. In SmartGPT, LLMs and Models are treated as traits, and they can be initialized through a provider and a config. You can also initialize them directly in the code-base, where config serialization is handled for you.

After initializing your smartgpt instance, you'll want to load the plugin data for each plugin like so:

smartgpt.load_plugin_data("Google", GoogleData {
    cse_id: "CSE ID".to_string(),
    api_key: "API KEY".to_string()
})?;

smartgpt.load_plugin_data("Browse", Value::Null)?;

Last updated