Skip to content

Latest commit

 

History

History
300 lines (244 loc) · 13.4 KB

README.org

File metadata and controls

300 lines (244 loc) · 13.4 KB

idea : create an ocaml functional agent for talking to llms.

 opam install --yes ppx_yojson_conv_lib ppx_yojson_conv
 opam install --yes ppx_yojson lwt_ppx containers lambdasoup uri ezcurl ppx_yojson_conv ppx_yojson_conv_lib ezcurl-lwt yojson
opam pin add --yes openai https://github.com/meta-introspector/openai-ocaml.git#main
 opam install --yes --deps-only .

 dune build .

Optional coq

opam install --yes coq
dune exec bin/argiope.exe "https://writemycode.com/?goal=snakegame" -- -m mistral
dune exec -- ./bin/argiope.exe https://github.com/meta-introspector/lang_agent/blob/3d485ff60e2872cbb920980a5fd2dbde908215ed/bin/argiope.ml#L28?q="argiope is a virtual hyperspace navigation simulator" -m mistral

run from docker

sudo  docker run --mount type=bind,source=/mnt/data1/2024/,target=/mnt/tmp  -it h4ckermike/lang_agent:default bash

chunker

takes two files, the prompt and the tochunk, that is split by \n and process

dune exec bin/chunker.exe -- ./prompt.txt ./separator.txt todo.txt mistral
dune exec bin/chunker.exe -- ./prompt.txt ./separator.txt ~/2024/01/07/ppx-introspector/test/test2b.ml mistral

worker

dune exec bin/worker.exe -- ./prompt.txt ./separator.txt task.txt mistral

scanner

dune exec bin/scanner.exe -- -s ~/experiments/unimath-data-hg/unimath/batch2/ -p "think about this:"
dune exec bin/scanner.exe --  -s ./huggingface/unimath/batch2/data_30/       -p "Consider the following valid trace of a COQ proof in unimath and interpret it creatively:"  --openai -m mistral

wild ideas

hijack urls with an ai in the middle proxy server.

bootstrap on ollama, then to llama.cpp, then embed inside of llama.cpp as well.

use threads, ezcurl-lwt

produce/consume quasi quoted interfaces to other systems using metacoq streams, streams of encoded type declarations, functions, kinds, records, constructors etc.

only allow valid interactions using strong types, and proofs etc

define workflows in ocaml or metacoq streams, even encoded in giant urls

follow urls that contain the requested system encoded in url.

produces urls that describe systems that are the result of the thinking

metacoq urls

postprocess responses and insert urls with annotations that can be visited

or not by agent, can expand the results significantly. filtered by the user agent.

dune exec bin/scanner.exe --  -s ./huggingface/unimath/batch2/data_30/       -p "Consider the following valid and successful trace of a COQ proof in unimath and interpret it creatively looking for interesting visualizations and metaphors and analogies and describe possible scenes for a comic book.:"  --openai -m "mixtral" -u "https://dev-hub.agentartificial.com"

dune exec bin/scanner.exe --  -s ./huggingface/unimath/batch2/data_30/       -p "Consider the following valid and successful trace of a COQ proof in unimath and interpret it creatively looking for interesting visualizations and metaphors and analogies and describe possible scenes for a comic book.:"  --ollama -m "mistral" -u "http://localhost:11434"

docker build

sudo docker  build . -t h4ckermike/lang_agent:dev
sudo docker push h4ckermike/lang_agent:dev

second process

this uses the new feature to filter the input and write new files.

dune exec bin/scanner.exe -- -x .out2 -c .out  -s ./huggingface/unimath/batch2/data_30/       -p "Consider the following possible scenes for a comic book and extract a list of characters and desribe one in detail.:"  --openai -m "mistral" -u "https://dev-hub.agentartificial.com"

dune exec bin/scanner.exe -- -x .outlocal2 -c .out  -s ./huggingface/unimath/batch2/data_30/       -p "Consider the following possible scenes for a comic book and extract a list of characters and desribe one in detail.:"  --ollama -m "mistral" -u "http://localhost:11434"

connect the proof

dune exec bin/scanner.exe – -x .con -c .outlocal2 \ -s ./huggingface/unimath/batch2/data_30/ \ -p “Create a list of connection pairs between term in the proof and words in the story.:” –ollama -m “mistral” \ -u “http://localhost:11434”

write a ocaml code to call

  let () =
let pipe = Sys.popen "bash" "-c" "echo hello world" in
let line = try ignore (input_line pipe) with End_of_file -> None in
let _ = Sys.waitpid [] |> ignore in
match line with
| Some(msg) -> Printf.printf "Output: %s\n" msg
| None -> Printf.printf "Error reading output."

simple

try with ‘org-babel-eval-in-repl

dune exec ./bin/simple.exe -- --openai -m "mixtral" -u "https://dev-hub.agentartificial.com" -p "consider a consecutive series of types to describe the universe and universe of universes, what is your ordering?" -n 10
#load "unix.cma";;
let type_terms = [
"set";
"type";
"sort"
                 ] in
let model_name = "mixtral" in
let url= "https://dev-hub.agentartificial.com"
let prompt type_name = "consider a " ^
             "consecutive series "^
             "of " ^ type_name ^
             "to describe " ^
             "the universe and universe of universes" ^
             "what is your ordering?" in

let count= 10 in
let simple = "dune exec ./bin/simple.exe --" in
let binding = "--openai"

let do_apply_list    run_cmd make_args type_terms   =
  List.iter (fun s ->
      let args = make_args s in
      run_cmd args
    ) type_terms;;

let make_args type_name = [
  simple;
  binding;
  "-m";    model;
  "-p";    prompt type_name;
  "-u";    url;
] in
let run_cmd args =
  let cmd =  String.concat " " args in
  let inp = Unix.open_process_in cmd in
  let r = In_channel.input_lines inp in
  In_channel.close inp;
  let out = String.concat " " r in
  Printf.printf "Output: %s\n" out

let () =
  do_apply_list run_cmd make_args type_terms  
  Printf.printf "Args: %s\n" args

recurse

dune exec ./bin/recurse.exe -- --openai -m "mixtral" \
     -u "https://dev-hub.agentartificial.com" \
     -s "recurse2"  \
     -x ".txt" \
     -p "consider a consecutive series of propositions to describe the universe and universe of universes. Consider your previous output and continue the thought if there, otherwise start a new thought chain." \
     -n 10

llama.cpp mode

dune exec ./bin/simple.exe -- --llamacpp  -u "http://localhost:8080" -p "consider a consecutive series of types to describe the universe and universe of universes, what is your ordering?"
DEBUG3path
DEBUG4MODEL:mistral
Consider:mistral
OUTPUT:_1.out

Error at `Assoc ([(“content”, `String (“\n\nTo provide an answer, let’s first define some terms and concepts:\n\n1. Universe: The totality of all existence, including all matter, energy, space, and time. It is the sum total of everything that exists or can be observed.\n2. Multiverse: A collection of multiple universes, each with its own set of fields and interactions. This concept arises in theoretical physics as a solution to certain problems, such as the fine-tuning problem or the cosmological constant problem.\n3. Meta-universe: The universe that contains all universes, including the multiverse.”)); (“generation_settings”, `Assoc ([(“dynatemp_exponent”, `Float (1.)); (“dynatemp_range”, `Float (0.)); (“frequency_penalty”, `Float (0.)); (“grammar”, `String (“”)); (“ignore_eos”, `Bool (false)); (“logit_bias”, `List ([])); (“min_p”, `Float (0.0500000007451)); (“mirostat”, `Int (0)); (“mirostat_eta”, `Float (0.10000000149)); (“mirostat_tau”, `Float (5.)); (“model”, `String (”usr/share/ollama.ollama/models/blobs/sha256:e8a35b5937a5e6d5c35d1f2a15f161e07eefe5e5bb0a3cdd42998ee79b057730”)); (“n_ctx”, `Int (512)); (“n_keep”, `Int (0)); (“n_predict”, `Int (128)); (“n_probs”, `Int (0)); (“penalize_nl”, `Bool (true)); (“penalty_prompt_tokens”, `List ([])); (“presence_penalty”, `Float (0.)); (“repeat_last_n”, `Int (64)); (“repeat_penalty”, `Float (1.10000002384)); (“seed”, `Int (4294967295)); (“stop”, `List ([])); (“stream”, `Bool (false)); (“temperature”, `Float (0.800000011921)); (“tfs_z”, `Float (1.)); (“top_k”, `Int (40)); (“top_p”, `Float (0.949999988079)); (“typical_p”, `Float (1.)); (“use_penalty_prompt_tokens”, `Bool (false))])); (“model”, `String (”usr/share/ollama.ollama/models/blobs/sha256:e8a35b5937a5e6d5c35d1f2a15f161e07eefe5e5bb0a3cdd42998ee79b057730”)); (“prompt”, `String (“consider a consecutive series of types to describe the universe and universe of universes, what is your ordering?consider a consecutive series of types to describe the universe and universe of universes, what is your ordering?”)); (“slot_id”, `Int (0)); (“stop”, `Bool (true)); (“stopped_eos”, `Bool (false)); (“stopped_limit”, `Bool (true)); (“stopped_word”, `Bool (false)); (“stopping_word”, `String (“”)); (“timings”, `Assoc ([(“predicted_ms”, `Float (14526.219)); (“predicted_n”, `Int (128)); (“predicted_per_second”, `Float (8.81165291533)); (“predicted_per_token_ms”, `Float (113.486085937)); (“prompt_ms”, `Float (2088.743)); (“prompt_n”, `Int (44)); (“prompt_per_second”, `Float (21.0653009968)); (“prompt_per_token_ms”, `Float (47.4714318182))])); (“tokens_cached”, `Int (171)); (“tokens_evaluated”, `Int (44)); (“tokens_predicted”, `Int (128)); (“truncated”, `Bool (false))])

dune exec ./bin/simple_grammar.exe – –llamacpp -s test4 -u “http://localhost:8080” -p “consider a consecutive series of types to describe the universe and universe of universes, what is your ordering?” -n 4 -g “root ::= (expr "\" ws term \"\n\")+\nexpr :: term ([-+*/] term)*\nterm ::= ident | num | "(" ws expr ")" ws\nident ::= [a-z] [a-z0-9_]* ws\nnum ::= [0-9]+ ws\nws ::= [ \t\n]*” s

grammar

We now take the filename for grammar because of quoting issues.

GRAMMAR=~/experiments/gbnf_parser/grammars/ebnf.ebnf DS=$(date -Iseconds) PROMPT_NAME=prompt_grammar2c.txt

dune exec bin/simple_grammar.exe – \ –llamacpp \ -u “http://localhost:8080” \ -s “grammar_1_${DS}” \ -g $GRAMMAR \ -p $PROMPT_NAME \ -x “.txt” \ -n 6