package ocaml-ai-sdk
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
OCaml AI SDK - Provider abstraction for AI models
Install
dune-project
Dependency
Authors
Maintainers
Sources
ocaml-ai-sdk-0.1.tbz
sha256=467ed85a42617ce399d0032d81f27f8dd2e8ca9b0753daeb2cbd84bf46761370
sha512=f5e96feea16c6ffdb45f49ee3e84e9cdb5426245c1ac32acc6434c15b949cc576c1007ed463bf1362dce507d10700eb96acf5a42fa7eed4e8e491ae0214a2e4a
doc/src/ocaml-ai-sdk.ai_core/core_tool.ml.html
Source file core_tool.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77type t = { description : string option; parameters : Yojson.Basic.t; execute : (Yojson.Basic.t -> Yojson.Basic.t Lwt.t) option; needs_approval : (Yojson.Basic.t -> bool Lwt.t) option; } let create ?description ?needs_approval ~parameters ~execute () = { description; parameters; execute = Some execute; needs_approval } let create_with_approval ?description ~parameters ~execute () = { description; parameters; execute = Some execute; needs_approval = Some (fun _ -> Lwt.return_true) } let create_client_tool ?description ~parameters () = { description; parameters; execute = None; needs_approval = None } let safe_parse_json_args s = match s with | "" -> `Assoc [] | _ -> try Yojson.Basic.from_string s with Yojson.Json_error _ -> `String s let denied_result = `Assoc [ "type", `String "execution-denied" ] let execute_tool ~tools ~tool_call_id ~tool_name ~args = match List.assoc_opt tool_name tools with | None -> Lwt.return { Generate_text_result.tool_call_id; tool_name; result = `String (Printf.sprintf "Tool '%s' not found" tool_name); is_error = true; } | Some { execute = None; _ } -> Lwt.return { Generate_text_result.tool_call_id; tool_name; result = `String "Client-side tool — no server execute"; is_error = true; } | Some { execute = Some exec; _ } -> Lwt.catch (fun () -> let%lwt result = exec args in Lwt.return { Generate_text_result.tool_call_id; tool_name; result; is_error = false }) (fun exn -> Lwt.return { Generate_text_result.tool_call_id; tool_name; result = `String (Printexc.to_string exn); is_error = true }) (** Partition tool calls into (blocked, executable). Blocked = needs approval OR client-only (no server execute). Executable = has execute and doesn't need approval. *) let evaluate_approvals ~tools tool_calls = let%lwt results = Lwt_list.map_s (fun (tc : Generate_text_result.tool_call) -> let%lwt can_execute = match List.assoc_opt tc.tool_name tools with | Some { execute = None; _ } -> Lwt.return_false | Some { needs_approval = Some check; _ } -> let%lwt needs = check tc.args in Lwt.return (not needs) | Some { execute = Some _; needs_approval = None; _ } -> Lwt.return_true | None -> Lwt.return_false in Lwt.return (tc, can_execute)) tool_calls in let blocked, executable = List.partition_map (fun (tc, can_execute) -> match can_execute with | true -> Right tc | false -> Left tc) results in Lwt.return (blocked, executable)
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>