zmedelis / bosquet

Tooling to build LLM applications: prompt templating and composition, agents, LLM memory, and other instruments for builders of AI applications.
https://zmedelis.github.io/bosquet/
Eclipse Public License 1.0
280 stars 19 forks source link

Render from nested structures #55

Open lidorcg opened 3 months ago

lidorcg commented 3 months ago

Hello,

I noticed that in Selmer you can render from a nested data structure:

A variables can also be nested data structures, eg:

(render "{{person.name}}" {:person {:name "John Doe"}})

In bosquet trying to render nested structured results in doted keyword:

(generate
   {:sys "You are the best LLM in the world"
    :examples {:example1 "1"}
    :prompt "In one word: How are you?"
    :template ["{{sys}}"
               "Examples:"
               "{{examples.example1}}"
               "{{prompt}}"
               "{{res}}"]
    :res {:llm/service :ollama
          :llm/cache true
          :llm/model-params {:model :llama3:latest}}})
=>
#:bosquet{:completions
          {:sys "You are the best LLM in the world",
           :prompt "In one word: How are you?",
           :template "{{sys}}\nExamples:\n{{examples.example1}}\n{{prompt}}\n{{res}}",
           :examples.example1 nil,
           :res "Exceptional!"},
          :usage
          {:examples.example1 nil,
           :res {:prompt 40, :completion 4, :total 44},
           :bosquet/total {:prompt 40, :completion 4, :total 44}},
          :time 5311}
schneiderlin commented 2 months ago

I'm looking into this. minimal case

(generate 
   {:task "answer: {{sub-task.answer}} + 1 = {{result}}"
    :sub-task {:answer "42"}
    :result (llm :ollama wkk/model-params {:model :llama3})})
#:bosquet{:completions {:task   "answer: {{sub-task.answer}} + 1 = {{result}}"
                        :sub-task.answer nil
                        :result "The answer is:\n\n2"}
          :usage       {:sub-task.answer nil
                        :result          {:prompt 16 :completion 6 :total 22}
                        :bosquet/total   {:prompt 16 :completion 6 :total 22}}
          :time        2601}