XJYNC4STRIEVS6TAJ4ZHIK35KDQD4ANUC534MKRIRKKF55F5BCXAC x
LULbLULULULb
(ocamlc /Users/david/.opam/ant/bin/ocamlc.opt)(ocaml_config_vars (afl_instrument false) (architecture amd64) (asm "cc -c -Wno-trigraphs") (asm_cfi_supported true) (ast_impl_magic_number Caml1999M033) (ast_intf_magic_number Caml1999N033) (bytecomp_c_compiler "cc -O2 -fno-strict-aliasing -fwrapv -pthread -D_FILE_OFFSET_BITS=64 ") (bytecomp_c_libraries "-L/usr/local/Cellar/zstd/1.5.5/lib -lzstd -lpthread") (c_compiler cc) (ccomp_type cc) (cma_magic_number Caml1999A033) (cmi_magic_number Caml1999I033) (cmo_magic_number Caml1999O033) (cmt_magic_number Caml1999T033) (cmx_magic_number Caml1999Y033) (cmxa_magic_number Caml1999Z033) (cmxs_magic_number Caml1999D033) (default_executable_name a.out) (default_safe_string true) (exec_magic_number Caml1999X033) (ext_asm .s) (ext_dll .so) (ext_exe "") (ext_lib .a) (ext_obj .o) (flambda false) (flat_float_array true) (function_sections false) (host x86_64-apple-darwin23.3.0) (int_size 63) (linear_magic_number Caml1999L033) (model default) (naked_pointers false) (native_c_compiler "cc -O2 -fno-strict-aliasing -fwrapv -pthread -D_FILE_OFFSET_BITS=64 ") (native_c_libraries " -lpthread") (native_compiler true) (native_dynlink true) (native_pack_linker "ld -r -o ") (ocamlc_cflags "-O2 -fno-strict-aliasing -fwrapv -pthread ") (ocamlc_cppflags " -D_FILE_OFFSET_BITS=64 ") (ocamlopt_cflags "-O2 -fno-strict-aliasing -fwrapv -pthread ") (ocamlopt_cppflags " -D_FILE_OFFSET_BITS=64 ") (os_type Unix) (safe_string true) (standard_library /Users/david/.opam/ant/lib/ocaml) (standard_library_default /Users/david/.opam/ant/lib/ocaml) (supports_shared_libraries true) (system macosx) (systhread_supported true) (target x86_64-apple-darwin23.3.0) (version 5.1.1) (windows_unicode false) (with_frame_pointers false) (word_size 64))
((6:ocamlc37:/Users/david/.opam/ant/bin/ocamlc.opt)(17:ocaml_config_vars((14:afl_instrument5:false)(12:architecture5:amd64)(3:asm20:cc -c -Wno-trigraphs)(17:asm_cfi_supported4:true)(21:ast_impl_magic_number12:Caml1999M033)(21:ast_intf_magic_number12:Caml1999N033)(19:bytecomp_c_compiler71:cc -O2 -fno-strict-aliasing -fwrapv -pthread -D_FILE_OFFSET_BITS=64 )(20:bytecomp_c_libraries54:-L/usr/local/Cellar/zstd/1.5.5/lib -lzstd -lpthread)(10:c_compiler2:cc)(10:ccomp_type2:cc)(16:cma_magic_number12:Caml1999A033)(16:cmi_magic_number12:Caml1999I033)(16:cmo_magic_number12:Caml1999O033)(16:cmt_magic_number12:Caml1999T033)(16:cmx_magic_number12:Caml1999Y033)(17:cmxa_magic_number12:Caml1999Z033)(17:cmxs_magic_number12:Caml1999D033)(23:default_executable_name5:a.out)(19:default_safe_string4:true)(17:exec_magic_number12:Caml1999X033)(7:ext_asm2:.s)(7:ext_dll3:.so)(7:ext_exe0:)(7:ext_lib2:.a)(7:ext_obj2:.o)(7:flambda5:false)(16:flat_float_array4:true)(17:function_sections5:false)(4:host25:x86_64-apple-darwin23.3.0)(8:int_size2:63)(19:linear_magic_number12:Caml1999L033)(5:model7:default)(14:naked_pointers5:false)(17:native_c_compiler71:cc -O2 -fno-strict-aliasing -fwrapv -pthread -D_FILE_OFFSET_BITS=64 )(18:native_c_libraries12: -lpthread)(15:native_compiler4:true)(14:native_dynlink4:true)(18:native_pack_linker9:ld -r -o )(13:ocamlc_cflags43:-O2 -fno-strict-aliasing -fwrapv -pthread )(15:ocamlc_cppflags24: -D_FILE_OFFSET_BITS=64 )(15:ocamlopt_cflags43:-O2 -fno-strict-aliasing -fwrapv -pthread )(17:ocamlopt_cppflags24: -D_FILE_OFFSET_BITS=64 )(7:os_type4:Unix)(11:safe_string4:true)(16:standard_library32:/Users/david/.opam/ant/lib/ocaml)(24:standard_library_default32:/Users/david/.opam/ant/lib/ocaml)(25:supports_shared_libraries4:true)(6:system6:macosx)(19:systhread_supported4:true)(6:target25:x86_64-apple-darwin23.3.0)(7:version5:5.1.1)(15:windows_unicode5:false)(19:with_frame_pointers5:false)(9:word_size2:64))))
open Cohttpopen Cohttp_lwt_unixopen Lwtopen Yojson.Basic.Utillet read_stdin_to_string () =let rec read_lines acc =trylet line = input_line stdin inread_lines (acc ^ line ^ "\n")with End_of_file -> accinread_lines ""let headers =Header.init () |> fun h ->Header.add h "x-api-key" ant_api_key |> fun h ->Header.add h "anthropic-version" "2023-06-01" |> fun h ->Header.add h "content-type" "application/json"ininlet uri = Uri.of_string "https://cdecary-memos.fly.dev/api/v2/memos" inClient.post ~headers ~body:(`String body) uri >>= fun (resp, _) ->let status = resp |> Response.status inif Code.is_success (Code.code_of_status status) then Lwt.return_unitelse Lwt.fail (Failure "Error posting data to Memos")(* Main function that orchestrates the process *)let main () =let prompt = read_stdin_to_string () inPrintf.printf "(* %s *)\n\n" prompt;get_from_claude prompt () >>= fun text ->Printf.printf "(* %s *)\n\n" text;post_to_memos prompt text >>= fun () -> Lwt.return_unitlet () = Lwt_main.run (main ())let body =`Assoc[("model", `String model);("max_tokens", `Int max_tokens);( "messages",`List[ `Assoc [ ("role", `String "user"); ("content", `String prompt) ] ]);]|> Yojson.Basic.to_stringinClient.post ~headers ~body:(Cohttp_lwt.Body.of_string body) ant_uri>>= fun (resp, body) ->let status = resp |> Response.status inif Code.is_success (Code.code_of_status status) thenbody |> Cohttp_lwt.Body.to_string >|= fun body_str ->let json = Yojson.Basic.from_string body_str inlet content = json |> member "content" inindex 0 content |> member "text" |> to_stringelse Lwt.fail (Failure "Error fetching data from Anthropic")(* Function to post data to Memos *)let post_to_memos prompt text =let memo = prompt ^ "\n\n" ^ text ^ "\n\n#claude" inlet body =`Assoc [ ("content", `String memo); ("visibility", `String "PRIVATE") ]|> Yojson.Basic.to_stringinlet api_key = "Bearer " ^ memos_api_key inlet headers =Header.init () |> fun h ->Header.add h "Authorization" api_key |> fun h ->Header.add h "Content-Type" "application/json"(* Function to make a request to Anthropic *)let get_from_claude prompt () =let model = "claude-3-haiku-20240307" inlet max_tokens = 1024 inlet ant_uri = Uri.of_string "https://api.anthropic.com/v1/messages" in(* Functions to get api keys *)let ant_api_key = get_env "ANTHROPIC_API_KEY" ()let memos_api_key = get_env "MEMOS_API_KEY" ()(* Function to get env variable *)let get_env api () =try Sys.getenv apiwith Not_found -> failwith api ^ " environment variable not found"(* Read from stdin *)
H;LULbLULULULULULHLmLULHLmLHLmLHLmLHLmLULULXLULULmLaLlLYLdLaLULULULULULULUL\LNLULpLXLULULULULULSLSLSLSLSLSLSLSLYLSLSLSLSLSLSLSLSLSLSLSLSLSLVLjLVLVLVLVLVLVLVLVLL\LVLVLVLVLVLVLVLVLVLVLjLVLVLVLVLVLVLVLVLLXLXLULULQLSLULULULULULULXLULULULXLXLULULULULmLID mDlLULULULULULULULsLULaLULQLULULULfLfL[LULULULULULULULjLULULULULwLgLsLULULSLSLjLULfLULULPLSLULULXLXLULULULULULULULULULULULULULXLXLXLXLXLXLXLXLXLXLXLXLOLOLOLOLOLtA0I8G0E4���TLULULULULvLULULULvLTLTLTLULULULULULULQLULULULXLULULSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLVLVLVLVLVLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLVLVLVLVLVLVLbLbLTLdLqLLA@HLoLRLRLRLRL{8D@m8D0[LOLnLxLML[L\LULULfLbLULQL[LULaLULuLuLuLwLwL`AOLqAMLIE@tLOL\EoLXLiLHLULbLXLULULULULULULQLULXLULULULULULULULULXLXLXLfLfLXLXLXLXLXLXLXLXLXLXLeLXLXLlLNLWAGLAOEJAVAGL~L~LGA@]HG@E�������$���LLILKL[LFLnLFLULULULULULXLULiLULHLmLQLULXLLLuLULUL\LUL{LbLULULULVLXLULXLULXLULULULULULULULULXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLX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SLSLSLSLSLSLXLXLXLXLXLULULULULXLXLULULULULHLmLvLQLULLLMLMLILOLOLKLILMLLLJLNLILMLmLQLULULULULULULULULULULULULULULXLXLXLXLXLXLXLXLXLXLI(D0lLD(D yLIAoLMLLLeLI(D0V(D _A YLI(D0V(D oA YLMEY�������V `LJE ALMLILZL`LILKLLLiLOLQLQLQLkLZLNE0BLmLHLmLHLpLXLULXLQLULXLXLXLXLULULULULULULXLULULULXLgLULXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLULXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLQLULXLULULULXLULXLXLULULXLULXLULULULULULULULXLXLXLXLXLXLULULULULULULULULUL]AVLZLCLOLULNLRLXLXLULULXLXLULULXLXLULULXLXLULUL_L\LULULXLXLULULXLULULULSLSLSLSLSLSLSLSLSLSLOLSLSLULXLULXLXLXLXLXLXLXLXLXLXLXLgLgLgLgLULULRLRLNLULULULRLRLRLULULULDA B(G B����������\LXLXLULULQLXLXLXLULULULXLXLXLULULULXLXLXLULULULXLXLXLULULULXLXLXLXLXLULXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLULRLNLULULRLRLULULQAOLQLULNLRLULULULULULULULULULXLQLULULULULULULULULULXLULULULULXLULULULXLRLRLQLSLULULULULULULULULULULULULULXLULULULYL]LXLHLpLHLpLXLVLXLXLULULULULXLULULULBLQLQLULRLRLRLULXLRLULJLRLVLULULULULULULULULULULULULULSLSLSLSLSLSLSLSLSLULULULULXLXLXLXLXLw(G E������4���TLULULULULULULULULULULULULULULULXLHLpLXLXLXLXLXLXLXLXLXLpLXLXLtLHLmLXLXLXLXLNLXLULULXLULULXLULULULULvA0tE0LLlLDA_LULULULULULXLULULXLXLULULULULULULULULULULILQLULULULULULULULULULULULULULUL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SLSLXLXLXLULfLULULXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLHLpLXLXLVLXLXLlLkLRLULULSLSLSLSLSLSLSLSLSLSLSLSLSLVLVLVLVLVLXLXLRLXLXLXLBLBLULULULQLULULULYD pLTLDDRLTL{LVLiLULULULULULdLULULULULULULXLXLXLXLXLXLXLXLXLULULXLQLULXLULXLULXLULULULULULULULULULULXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLHLpL\LXLXLXLXL\LXLXLXLXLXL[LXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULXLXLXLULULULULULULULULXLXLXLXLOLSLVLVLSLSLULULULULULULULULULULXLVLVLXLXLXLXLXLXLXLIA0ULIA0{LIA0iLIA@vLIA0vLIA ZLIA WLQLULULULULUL\LULULXLULULRLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXL[LXLXLXLXLXLXLXLXLXLXLXLULULULULXLXLXLSLULULXLXLULULULULULULULULGA0DL|LXLXLXLXLXLXLXLXLXLXLXLQLULbLULULULULULXLULULULULULULXLXLXLULULXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXL_LXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLGA0DL|�������DXLXLXLXLXLUL_L_LQLULULYLYLULYLXLXLXLUL\LXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLULULULXLXLXLXLULULXLXLULXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLQLULSLULULULULjL1LWHDPZHD@.LwL]LZA0t8G0E������,���Lz(G E����D���<LfLXLQLULULULULULULULXLULULULXLULULULXLULXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLHLpLXLVLXLXLXLXLXLXLULULULULULULULULULULULULXLULXLXLULULXLXLULULULULULULULULULULULULXLULXLXLULULXLXLULULULULULSLULULULULULULULXLXLXLXLULULXLXLMLMLXLXLXLXLULULULULULULULULXLXLXLULULULULULULULELELELIhDp\hD`vLmA`EL^LHLmLHLmLLXLULlLULULULULULULQLULULULULULiLULULULULULULULULULULULULULULULXLOLMLIAOLMLGA~LQLNLGEYLNLiLULULULRLULULRLULULRLULULULULULXLXLXLXLULULULULULULULULXLULVLVLULULULXLXLULXLXLXLXLXLULXLXLXLXLXLULXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLULULQLULULULQLmLULULULQLXLXLULXLXLXLXLXLXLULXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXL[LXL[LXLXLXLXL[LHLpLXLXLXLXLXLXL[L[LXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXL[L[L[L[LXLXLXLXLULULULXLXLXLXLXLULULULULULRLQLULULULULULULULRLmLHLmLHLpLXLXLXLXLXLXLXLULULfLXLXLXLXLULULULQLULULXLXLXLXLULXLXLXLXLXLZLZLfBHLULULHLmLaLULULULULQLULULULULYLUL[LYLULULULULULULULULULULOLKLKLKLXLXLXLVLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLvLXLCLULULULULULULULULULULULULQLULXLULXLRL\LIA@LLIA0uLOLtE@JA@KA@VHG@E��4���LIA@NLIA0zLOLXLXLID [D[D [DHLlLULXLmLXLQLULULXLULULXLXLULXLULULXLXLXLXLXLXLXLXLXLXLXLULXLULXLULXLULULXLULXLULXLXLXLXLmLvLkLSLOL}LQLULULULULULULULULULRA XLRLRLRLXLXLXLRLRLRLRLPLBLTLTLPLTLPLTLTLTLTLRLULuLU(D0s(D QLwLcLRLNL^L{L|LKLULULIAG����,���<LIAG����$���lLMLVLVLQLtLtLtLuLiLjLXLXLXLXLiLiLULULULULULXLULULXLULXLULULULULULXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLXLULXLQLULQLXLULULALILMLMLILSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLXLSLSLSLSLSLSLSLSLSLSLSLSLSLSLSLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLSLYLSLSLSLSLSLSLSLSLSLSLSLSLSLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLSLULSLSLSLSLSLSLSLSLSLSLSLSLSLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLYLULQ%s��h��d��Error: s-expression parsing error;Error: s-expression parsing error;%sError: s-expression conversion error;exception %sError: s-expression conversion error;��l��h��d��0��,�����| ��p��\Lb
open Cohttpopen Cohttp_lwt_unixopen Lwtopen Yojson.Basic.Util(* Read from stdin *)let read_stdin_to_string () =let rec read_lines acc =trylet line = input_line stdin inread_lines (acc ^ line ^ "\n")with End_of_file -> accinread_lines ""(* Function to get env variable *)let get_env api () =trySys.getenv apiwith| Not_found -> failwith api ^ " environment variable not found"(* Functions to get api keys *)let ant_api_key = get_env "ANTHROPIC_API_KEY" ()let headers =Header.init () |> fun h ->Header.add h "x-api-key" ant_api_key |> fun h ->Header.add h "anthropic-version" "2023-06-01" |> fun h ->Header.add h "content-type" "application/json"inlet json = Yojson.Basic.from_string body_str inlet content = json |> member "content" inindex 0 content |> member "text" |> to_stringelseLwt.fail (Failure "Error fetching data from Anthropic")(* Function to post data to Memos *)let post_to_memos prompt text =let memo = prompt ^ "\n\n" ^ text ^ "\n\n#claude" inlet body = `Assoc [("content", `String memo);("visibility", `String "PRIVATE");] |> Yojson.Basic.to_string inlet api_key = "Bearer " ^ memos_api_key inlet headers =Header.init () |> fun h ->Header.add h "Authorization" api_key |> fun h ->Header.add h "Content-Type" "application/json" inlet uri = Uri.of_string "https://cdecary-memos.fly.dev/api/v2/memos" inClient.post ~headers ~body:(`String body) uri >>= fun (resp, _) ->let status = resp |> Response.status inif Code.is_success (Code.code_of_status status) thenLwt.return_unitelseLwt.fail (Failure "Error posting data to Memos")(* Main function that orchestrates the process *)let main () =let prompt = read_stdin_to_string () inPrintf.printf "(* %s *)\n\n" prompt;get_from_claude prompt () >>= fun text ->Printf.printf "(* %s *)\n\n" text;post_to_memos prompt text >>= fun () ->Lwt.return_unitlet () =Lwt_main.run (main ())let body = `Assoc[("model", `String model);("max_tokens", `Int max_tokens);( "messages",`List[ `Assoc [ ("role", `String "user"); ("content", `String prompt) ] ]);] |> Yojson.Basic.to_string inClient.post ~headers ~body:(Cohttp_lwt.Body.of_string body) ant_uri >>= fun (resp, body) ->let status = resp |> Response.status inif Code.is_success (Code.code_of_status status) thenbody |> Cohttp_lwt.Body.to_string >|= fun body_str ->(* Function to make a request to Anthropic *)let get_from_claude prompt () =let model = "claude-3-haiku-20240307" inlet max_tokens = 1024 inlet ant_uri = Uri.of_string "https://api.anthropic.com/v1/messages" inlet memos_api_key = get_env "MEMOS_API_KEY" ()
# OCAMLPARAM: unset# Shared cache: disabled# Shared cache location: /Users/david/.cache/dune/db# Workspace root: /Users/david/ocaml/ant# Auto-detected concurrency: 4# Dune context:# { name = "default"# ; kind = "default"# ; profile = Dev# ; merlin = true# ; fdo_target_exe = None# ; build_dir = In_build_dir "default"# ; installed_env =# map# { "INSIDE_DUNE" : "/Users/david/ocaml/ant/_build/default"# ; "OCAML_COLOR" : "always"# ; "OPAMCOLOR" : "always"# }# ; instrument_with = []# }$ /Users/david/.opam/ant/bin/ocamlc.opt -config > /var/folders/rv/kyhr9kcn4q39_880qd3rp2kr0000gn/T/dune_d0dd73_output$ (cd _build/default && /Users/david/.opam/ant/bin/ocamlformat --impl v1_ant.ml) > _build/default/.formatted/v1_ant.ml$ (cd _build/default && /Users/david/.opam/ant/bin/ocamlformat --impl ant.ml) > _build/default/.formatted/ant.ml$ /usr/local/bin/git --no-pager diff --no-index --color=always -u _build/default/v1_ant.ml _build/default/.formatted/v1_ant.ml> diff --git a/_build/default/v1_ant.ml b/_build/default/.formatted/v1_ant.ml> index 0b18446..5055f01 100644> --- a/_build/default/v1_ant.ml> +++ b/_build/default/.formatted/v1_ant.ml> @@ -13,14 +13,12 @@ let read_stdin_to_string () => read_lines "">> let get_env api () => - try> - Sys.getenv api> - with> - | Not_found -> failwith api ^ " environment variable not found"> + try Sys.getenv api> + with Not_found -> failwith api ^ " environment variable not found">> let ant_api_key = get_env "ANTHROPIC_API_KEY" ()> (* let memos_api_key = get_env "MEMOS_API_KEY" () *)> -> +> let model = "claude-3-haiku-20240307"> let max_tokens = 1024> let ant_uri = Uri.of_string "https://api.anthropic.com/v1/messages"> @@ -43,7 +41,8 @@ let extract_code_block (s : string) : string option => if String.sub s open_pos 3 = triple_backtick then> let close_pos = String.index_from s (open_pos + 3) '`' in> if String.sub s close_pos 3 = triple_backtick then> - Some (String.sub s (open_pos + 3 + 5) (close_pos - open_pos - 3 - 5)) (* here +5 to remove ocaml or julia after ``` and -5 to remove closing backticks *)> + Some (String.sub s (open_pos + 3 + 5) (close_pos - open_pos - 3 - 5))> + (* here +5 to remove ocaml or julia after ``` and -5 to remove closing backticks *)> else None> else None> with Not_found -> None[1]$ /usr/local/bin/git --no-pager diff --no-index --color=always -u _build/default/ant.ml _build/default/.formatted/ant.ml> diff --git a/_build/default/ant.ml b/_build/default/.formatted/ant.ml> index 60df6b7..be1a0e7 100644> --- a/_build/default/ant.ml> +++ b/_build/default/.formatted/ant.ml> @@ -15,10 +15,8 @@ let read_stdin_to_string () =>> (* Function to get env variable *)> let get_env api () => - try> - Sys.getenv api> - with> - | Not_found -> failwith api ^ " environment variable not found"> + try Sys.getenv api> + with Not_found -> failwith api ^ " environment variable not found">> (* Functions to get api keys *)> let ant_api_key = get_env "ANTHROPIC_API_KEY" ()> @@ -35,7 +33,8 @@ let get_from_claude prompt () => Header.add h "anthropic-version" "2023-06-01" |> fun h ->> Header.add h "content-type" "application/json"> in> - let body = `Assoc> + let body => + `Assoc> [> ("model", `String model);> ("max_tokens", `Int max_tokens);> @@ -43,45 +42,44 @@ let get_from_claude prompt () => `List> [ `Assoc [ ("role", `String "user"); ("content", `String prompt) ] ]> );> - ] |> Yojson.Basic.to_string in> - Client.post ~headers ~body:(Cohttp_lwt.Body.of_string body) ant_uri >>= fun (resp, body) ->> + ]> + |> Yojson.Basic.to_string> + in> + Client.post ~headers ~body:(Cohttp_lwt.Body.of_string body) ant_uri> + >>= fun (resp, body) ->> let status = resp |> Response.status in> if Code.is_success (Code.code_of_status status) then> body |> Cohttp_lwt.Body.to_string >|= fun body_str ->> - let json = Yojson.Basic.from_string body_str in> - let content = json |> member "content" in> - index 0 content |> member "text" |> to_string> - else> - Lwt.fail (Failure "Error fetching data from Anthropic")> + let json = Yojson.Basic.from_string body_str in> + let content = json |> member "content" in> + index 0 content |> member "text" |> to_string> + else Lwt.fail (Failure "Error fetching data from Anthropic")>> (* Function to post data to Memos *)> let post_to_memos prompt text => let memo = prompt ^ "\n\n" ^ text ^ "\n\n#claude" in> - let body = `Assoc [> - ("content", `String memo);> - ("visibility", `String "PRIVATE");> - ] |> Yojson.Basic.to_string in> + let body => + `Assoc [ ("content", `String memo); ("visibility", `String "PRIVATE") ]> + |> Yojson.Basic.to_string> + in> let api_key = "Bearer " ^ memos_api_key in> let headers => - Header.init () |> fun h ->> - Header.add h "Authorization" api_key |> fun h ->> - Header.add h "Content-Type" "application/json" in> + Header.init () |> fun h ->> + Header.add h "Authorization" api_key |> fun h ->> + Header.add h "Content-Type" "application/json"> + in> let uri = Uri.of_string "https://cdecary-memos.fly.dev/api/v2/memos" in> Client.post ~headers ~body:(`String body) uri >>= fun (resp, _) ->> let status = resp |> Response.status in> - if Code.is_success (Code.code_of_status status) then> - Lwt.return_unit> - else> - Lwt.fail (Failure "Error posting data to Memos")> + if Code.is_success (Code.code_of_status status) then Lwt.return_unit> + else Lwt.fail (Failure "Error posting data to Memos")>> (* Main function that orchestrates the process *)> let main () => let prompt = read_stdin_to_string () in> Printf.printf "(* %s *)\n\n" prompt;> get_from_claude prompt () >>= fun text ->> - Printf.printf "(* %s *)\n\n" text;> - post_to_memos prompt text >>= fun () ->> - Lwt.return_unit> + Printf.printf "(* %s *)\n\n" text;> + post_to_memos prompt text >>= fun () -> Lwt.return_unit>> -let () => - Lwt_main.run (main ())> \ No newline at end of file> +let () = Lwt_main.run (main ())[1]# dune fmt