autogpt/
message.rs

1/// Parses a key-value formatted payload string into individual values.
2///
3/// The function expects a string in the format:
4/// `input=some text;language=python`, and extracts the `input` and `language` fields.
5///
6/// # Arguments
7///
8/// * `payload` - A string containing key-value pairs separated by semicolons.
9///
10/// # Returns
11///
12/// * A tuple `(input, language)` extracted from the payload. Defaults are empty string and "python" respectively
13///   if the keys are not present.
14pub fn parse_kv(payload: &str) -> (String, String) {
15    let mut input = "".to_string();
16    let mut lang = "python".to_string();
17
18    for part in payload.split(';') {
19        let mut kv = part.splitn(2, '=');
20        let key = kv.next().unwrap_or("");
21        let val = kv.next().unwrap_or("").to_string();
22        if key == "input" {
23            input = val;
24        } else if key == "language" {
25            lang = val;
26        }
27    }
28
29    (input, lang)
30}