llmclient 0.3.2

Rust LLM client - Gemini, OpenAI, Claude, Mistral, DeepSeek, Groq
Documentation
use llmclient::functions::*;
use llmclient::common::*;
//use evalexpr::eval;

#[tokio::main]
async fn main() {
/*
    let data = r#"{
  "choices": [
    {
      "message": {
        "tool_calls": [
          {
            "function": {
              "name": "${func}",
              "arguments": "${args}"
            }
          }
        ]
      }
    }
  ]
}"#;
    let data2 = r#"{
  "id": "chatcmpl-9KmDSgvDNpdWzZMjNikOFzWyZRi8D",
  "object": "chat.completion",
  "created": 1714738930,
  "model": "gpt-4-turbo-2024-04-09",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": null,
        "tool_calls": [
          {
            "id": "call_lPmkbGFiJkvuXvzs09uUYdzD",
            "type": "function",
            "function": {
              "name": "calc",
              "arguments": "{\"expr\":\"(60 * 24) * 265.251\"}"
            }
          },
          {
            "id": "call_lPmkbGFiJkvuXvzs09uUYdzD",
            "type": "function",
            "function": {
              "name": "calc2",
              "arguments": "{\"expr\":\"(60 * 24)\", \"unit\": \"hours\"}"
            }
          }
        ]
      },
      "logprobs": null,
      "finish_reason": "tool_calls"
    }
  ],
  "usage": {
    "prompt_tokens": 80,
    "completion_tokens": 23,
    "total_tokens": 103
  },
  "system_fingerprint": "fp_3450ce39d5"
}"#;
*/
    let func_def =
r#"
// Derive the value of the arithmetic expression
// expr: An arithmetic expression
fn arithmetic(expr)
"#;
    let _func_def2 =
r#"
// this is another func
// arg10: The first arg
// arg11: The Second arg
fn func(arg10, arg11)
"#;

    let func_call = json_function("gemini", &[func_def]);

    let func_call = match func_call {
        Ok(ref fc) => fc.to_string(),
        Err(e) => e.to_string()
    };
/*
    println!("{func_call}");

    let fc: Result<FunctionCall, _> = serde_json::from_str(&func_call);
    let fc = fc.unwrap();

    println!("{fc:?}");

    let json = serde_json::to_string(&fc).unwrap();

    println!("{json}");
*/

    //let result = call_llm_model_function("gpt", "gpt-4o", "", &["The answer is (60 * 24) * 365.25".to_string()], 0.2, false, true, &[&func_call]).await;
    //let result = call_llm_model_function("groq", "llama3-70b-8192", "", &["The answer is (60 * 24) * 365.25".to_string()], 0.2, false, true, &[&func_call]).await;
    //let result = call_llm_model_function("mistral", "mistral-large-latest", "", &["The answer is (60 * 24) * 365.25".to_string()], 0.2, false, true, &[&func_call]).await;
    //let result = call_llm_model_function("claude", "claude-3-opus-20240229", "", &["The answer is (60 * 24) * 365.25".to_string()], 0.2, false, true, &[&func_call]).await;
    let result = call_llm_model_function("gemini", "gemini-pro", "", &["The answer is (60 * 24) * 365.25".to_string()], 0.2, false, true, &[&func_call]).await;

    println!("result: {result:?}");
    //println!("usage: {:?}", result.unwrap().get("usage"));

    /*
    //println!("{}", func_call);

    // Convert to a string of JSON and print it out
    let v: serde_json::Value = serde_json::from_str(data).unwrap();

    let found = find_function(&v);
    println!("found: {found:?}");

    let f: serde_json::Value = serde_json::from_str(data2).unwrap();

    let h = get_functions(&f, &found);

    println!("hash functions: {h:?}");

    let funcs = unpack_functions(h);

    println!("unpacked functions: {funcs:?}");

    if let Some(fun) = funcs {
        for f in fun {
            let exprs: Vec<&ParseArgument> = f.arguments.iter()
                .filter(|p| p.name == "expr")
                .collect();
            let desc = eval(&exprs[0].desc);

            if let Ok(v) = desc {
                println!("{}: {:?}", &f.function, v.to_string());
            }
        }
    }
    */
}