Pick the best action from a list of actions given an image and context. https://crates.io/crates/pick_action_from_image
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2023-12-17 21:49:43 -06:00
.github/workflows Initial commit 2023-12-10 22:22:16 -06:00
.vscode Break into packages 2023-12-16 21:11:51 -06:00
examples/chatgpt-4v Restructure to be more like other rust projects 2023-12-17 21:11:37 -06:00
src Restructure to be more like other rust projects 2023-12-17 21:11:37 -06:00
templates Restructure to be more like other rust projects 2023-12-17 21:11:37 -06:00
.env.example Initial commit 2023-12-10 22:22:16 -06:00
.gitignore Break into packages 2023-12-16 21:11:51 -06:00
Cargo.lock Restructure to be more like other rust projects 2023-12-17 21:11:37 -06:00
Cargo.toml Bump to 1.0.0 2023-12-17 21:49:43 -06:00
LICENSE Prepare for publishing 2023-12-16 22:12:28 -06:00
README.md Change repo name to match package name 2023-12-17 21:27:14 -06:00

Pick actions from an image

github crates.io docs.rs build status

Pick the best action from a list of actions given an image and context.

This can be used for other AI models, but currently only has a model for ChatGPT-4V.

Usage

Define an ImagePath:

// Picture of a cute dog
let url = Url::parse("https://www.petlandflorida.com/wp-content/uploads/2022/04/shutterstock_1290320698-1-scaled.jpg").unwrap();
let image_path = ImagePath::Url(&url);

Files can also be used:

let path = PathBuf::from("assets/my_image.jpeg");
let image_path = ImagePath::File(&path);

Then provide context for how actions should be picked. This can be a question or a statement.

let context = "What would make them happiest? They haven't eaten."; // Your question

Then define a list of actions to pick from. The description helps the AI understand what the action is and when it should be picked.

let actions = vec![
    Action {
        id: "give bone",
        description: "Give a delicious bone to chew on",
    },
    Action {
        id: "give belly rub",
        description: "Give a belly rub",
    },
    Action {
        id: "none",
        description: "Don't do anything",
    },
];

Then create an AI instance. Currently only ChatGPT-4V is implemented.

dotenv().ok();
let api_key = env::var("OPENAI_API_KEY").expect("API key not found");
let chat_gpt4v = ChatGpt4v { api_key: &api_key };

And finally, ask the AI about the image. You'll get back the best action as a String.

//  Ask the AI about the image
let picked_action = pick_action_from_image(&chat_gpt4v, &context, &actions, &image_path)
    .await
    .unwrap();
println!("Picked action: {}", picked_action);

You can see a full example in the repository's examples folder.

Setup

Make sure that you have Rust installed.

Then you should setup your OPENAI_API_KEY environment variable. To do this, you can copy the .env.example file to .env and fill in the value.

You can find your API key in your User Settings.