KZ6GLIARF2Z26LAFBT2PCW5IQTVOWMYZUQNN4KVONBECXAUBO44QC
let ant_req_body prompt =
`Assoc
[
("model", `String model);
("max_tokens", `Int max_tokens);
( "messages",
`List
[ `Assoc [ ("role", `String "user"); ("content", `String prompt) ] ]
);
]
let extract_code_block (s : string) : string option =
let triple_backtick = "```" in
try
let open_pos = String.index s '`' in
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 *)
else None
else None
with Not_found -> None
let () =
let prompt = read_stdin_to_string () in
Printf.printf "(* %s *)" prompt;
(* Make a request to Anthropic *)
let get_from_claude prompt () =
let model = "claude-3-haiku-20240307" in
let max_tokens = 1024 in
let ant_uri = Uri.of_string "https://api.anthropic.com/v1/messages" in
let body = ant_req_body prompt |> Yojson.Basic.to_string in
let req =
Client.post ~headers ~body:(Cohttp_lwt.Body.of_string body) ant_uri
let body =
`Assoc
[
("model", `String model);
("max_tokens", `Int max_tokens);
( "messages",
`List
[ `Assoc [ ("role", `String "user"); ("content", `String prompt) ] ]
);
]
|> Yojson.Basic.to_string
Lwt_main.run
( req >>= fun (resp, body) ->
let status = resp |> Response.status |> Code.code_of_status in
Printf.printf "\n(* Response status: %d *)" status;
body |> Cohttp_lwt.Body.to_string >|= fun body_str ->
let json = Yojson.Basic.from_string body_str in
let content = json |> member "content" in
let text = index 0 content |> member "text" |> to_string in
match extract_code_block text with
| Some code -> Printf.printf "\n%s\n(* %s *)\n" code text
| None -> Printf.printf "(* No code returned *)\n(* %s *)\n" text )
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")
(* 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 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
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")
(* 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
let () = Lwt_main.run (main ())
$ /Users/david/.opam/ant/bin/ocamlc.opt -config > /var/folders/rv/kyhr9kcn4q39_880qd3rp2kr0000gn/T/dune_19d6a0_output
$ (cd _build/default && /Users/david/.opam/ant/bin/ocamlopt.opt -w @1..3@5..28@31..39@43@46..47@49..57@61..62@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -I .ant.eobjs/byte -I .ant.eobjs/native -I /Users/david/.opam/ant/lib/angstrom -I /Users/david/.opam/ant/lib/astring -I /Users/david/.opam/ant/lib/base64 -I /Users/david/.opam/ant/lib/bigstringaf -I /Users/david/.opam/ant/lib/bytes -I /Users/david/.opam/ant/lib/cohttp -I /Users/david/.opam/ant/lib/cohttp-lwt -I /Users/david/.opam/ant/lib/cohttp-lwt-unix -I /Users/david/.opam/ant/lib/conduit -I /Users/david/.opam/ant/lib/conduit-lwt -I /Users/david/.opam/ant/lib/conduit-lwt-unix -I /Users/david/.opam/ant/lib/domain-name -I /Users/david/.opam/ant/lib/fmt -I /Users/david/.opam/ant/lib/ipaddr -I /Users/david/.opam/ant/lib/ipaddr-sexp -I /Users/david/.opam/ant/lib/ipaddr/unix -I /Users/david/.opam/ant/lib/logs -I /Users/david/.opam/ant/lib/lwt -I /Users/david/.opam/ant/lib/lwt/unix -I /Users/david/.opam/ant/lib/lwt_ssl -I /Users/david/.opam/ant/lib/macaddr -I /Users/david/.opam/ant/lib/magic-mime -I /Users/david/.opam/ant/lib/ocaml/threads -I /Users/david/.opam/ant/lib/ocaml/unix -I /Users/david/.opam/ant/lib/ocplib-endian -I /Users/david/.opam/ant/lib/ocplib-endian/bigstring -I /Users/david/.opam/ant/lib/parsexp -I /Users/david/.opam/ant/lib/ppx_sexp_conv/runtime-lib -I /Users/david/.opam/ant/lib/re -I /Users/david/.opam/ant/lib/seq -I /Users/david/.opam/ant/lib/sexplib -I /Users/david/.opam/ant/lib/sexplib0 -I /Users/david/.opam/ant/lib/ssl -I /Users/david/.opam/ant/lib/stringext -I /Users/david/.opam/ant/lib/uri -I /Users/david/.opam/ant/lib/uri-sexp -I /Users/david/.opam/ant/lib/uri/services -I /Users/david/.opam/ant/lib/yojson -intf-suffix .ml -no-alias-deps -opaque -o .ant.eobjs/native/dune__exe__Ant.cmx -c -impl ant.ml)
$ (cd _build/default && /Users/david/.opam/ant/bin/ocamlopt.opt -w @1..3@5..28@31..39@43@46..47@49..57@61..62@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -o ant.exe /Users/david/.opam/ant/lib/re/re.cmxa /Users/david/.opam/ant/lib/stringext/stringext.cmxa /Users/david/.opam/ant/lib/bigstringaf/bigstringaf.cmxa -I /Users/david/.opam/ant/lib/bigstringaf /Users/david/.opam/ant/lib/angstrom/angstrom.cmxa /Users/david/.opam/ant/lib/uri/uri.cmxa /Users/david/.opam/ant/lib/sexplib0/sexplib0.cmxa /Users/david/.opam/ant/lib/ppx_sexp_conv/runtime-lib/ppx_sexp_conv_lib.cmxa /Users/david/.opam/ant/lib/uri-sexp/uri_sexp.cmxa /Users/david/.opam/ant/lib/base64/base64.cmxa /Users/david/.opam/ant/lib/cohttp/cohttp.cmxa /Users/david/.opam/ant/lib/fmt/fmt.cmxa /Users/david/.opam/ant/lib/logs/logs.cmxa /Users/david/.opam/ant/lib/lwt/lwt.cmxa /Users/david/.opam/ant/lib/logs/logs_lwt.cmxa /Users/david/.opam/ant/lib/parsexp/parsexp.cmxa /Users/david/.opam/ant/lib/sexplib/sexplib.cmxa /Users/david/.opam/ant/lib/macaddr/macaddr.cmxa /Users/david/.opam/ant/lib/domain-name/domain_name.cmxa /Users/david/.opam/ant/lib/ipaddr/ipaddr.cmxa /Users/david/.opam/ant/lib/ipaddr-sexp/ipaddr_sexp.cmxa /Users/david/.opam/ant/lib/astring/astring.cmxa /Users/david/.opam/ant/lib/conduit/conduit.cmxa /Users/david/.opam/ant/lib/conduit-lwt/conduit_lwt.cmxa /Users/david/.opam/ant/lib/magic-mime/magic_mime_library.cmxa /Users/david/.opam/ant/lib/ocplib-endian/ocplib_endian.cmxa /Users/david/.opam/ant/lib/ocplib-endian/bigstring/ocplib_endian_bigstring.cmxa /Users/david/.opam/ant/lib/ocaml/unix/unix.cmxa /Users/david/.opam/ant/lib/ocaml/threads/threads.cmxa /Users/david/.opam/ant/lib/lwt/unix/lwt_unix.cmxa -I /Users/david/.opam/ant/lib/lwt/unix /Users/david/.opam/ant/lib/uri/services/uri_services.cmxa /Users/david/.opam/ant/lib/ipaddr/unix/ipaddr_unix.cmxa /Users/david/.opam/ant/lib/ssl/ssl.cmxa -I /Users/david/.opam/ant/lib/ssl /Users/david/.opam/ant/lib/lwt_ssl/lwt_ssl.cmxa /Users/david/.opam/ant/lib/conduit-lwt-unix/conduit_lwt_unix.cmxa /Users/david/.opam/ant/lib/cohttp-lwt/cohttp_lwt.cmxa /Users/david/.opam/ant/lib/logs/logs_fmt.cmxa /Users/david/.opam/ant/lib/cohttp-lwt-unix/cohttp_lwt_unix.cmxa /Users/david/.opam/ant/lib/yojson/yojson.cmxa .ant.eobjs/native/dune__exe__Ant.cmx)
$ /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]
(* 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"
let ant_req_body prompt =
`Assoc
[
("model", `String model);
("max_tokens", `Int max_tokens);
( "messages",
`List
[ `Assoc [ ("role", `String "user"); ("content", `String prompt) ] ]
);
]
let memos_api_key = get_env "MEMOS_API_KEY" ()
let extract_code_block (s : string) : string option =
let triple_backtick = "```" in
try
let open_pos = String.index s '`' in
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 *)
else None
else None
with Not_found -> None
let () =
let prompt = read_stdin_to_string () in
Printf.printf "(* %s *)" prompt;
(* Function to make a request to Anthropic *)
let get_from_claude prompt () =
let model = "claude-3-haiku-20240307" in
let max_tokens = 1024 in
let ant_uri = Uri.of_string "https://api.anthropic.com/v1/messages" in
let body = ant_req_body prompt |> Yojson.Basic.to_string in
let req =
Client.post ~headers ~body:(Cohttp_lwt.Body.of_string body) ant_uri
in
Lwt_main.run
( req >>= fun (resp, body) ->
let status = resp |> Response.status |> Code.code_of_status in
Printf.printf "\n(* Response status: %d *)" status;
body |> Cohttp_lwt.Body.to_string >|= fun body_str ->
let body = `Assoc
[
("model", `String model);
("max_tokens", `Int max_tokens);
( "messages",
`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) ->
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 text = index 0 content |> member "text" |> to_string in
match extract_code_block text with
| Some code -> Printf.printf "\n%s\n(* %s *)\n" code text
| None -> Printf.printf "(* No code returned *)\n(* %s *)\n" text )
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 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
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")
(* 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
let () =
Lwt_main.run (main ())
%s
(* %s *)
��� ����|=��
un_473�Ї
end�թ
let model = "claude-3-opus-20240229"
let max_tokens = 1024
let ant_uri = Uri.of_string "https://api.anthropic.com/v1/messages"
(* Function to get env variable *)
let get_env api () =
try Sys.getenv api
with Not_found -> failwith api ^ " environment variable not found"
let ant_req_body prompt =
`Assoc
[
("model", `String model);
("max_tokens", `Int max_tokens);
( "messages",
`List
[ `Assoc [ ("role", `String "user"); ("content", `String prompt) ] ]
);
]
let extract_code_block (s : string) : string option =
let triple_backtick = "```" in
try
let open_pos = String.index s '`' in
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))
else None
else None
with Not_found -> None
(* Functions to get api keys *)
let ant_api_key = get_env "ANTHROPIC_API_KEY" ()
let memos_api_key = get_env "MEMOS_API_KEY" ()
let () =
let prompt = read_stdin_to_string () in
Printf.printf "%s\n" prompt;
(* Function to make a request to Anthropic *)
let get_from_claude prompt () =
let model = "claude-3-haiku-20240307" in
let max_tokens = 1024 in
let ant_uri = Uri.of_string "https://api.anthropic.com/v1/messages" in
let body = ant_req_body prompt |> Yojson.Basic.to_string in
let req =
Client.post ~headers ~body:(Cohttp_lwt.Body.of_string body) ant_uri
let body =
`Assoc
[
("model", `String model);
("max_tokens", `Int max_tokens);
( "messages",
`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) ->
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")
(* 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 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"
Lwt_main.run
( req >>= fun (resp, body) ->
let status = resp |> Response.status |> Code.code_of_status in
Printf.printf "(* Response status: %d *)\n" status;
body |> Cohttp_lwt.Body.to_string >|= fun body_str ->
let json = Yojson.Basic.from_string body_str in
let content = json |> member "content" in
let text = index 0 content |> member "text" |> to_string in
match extract_code_block text with
| Some code -> Printf.printf "%s\n" code
| None -> Printf.printf "(* No code returned *)\n%s\n" text )
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")
(* 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
let () = Lwt_main.run (main ())
%s
LF
_build/