File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ defmodule Rag.Generation do
1010 @ type response_function :: ( String . t ( ) , keyword ( ) -> String . t ( ) )
1111 @ type context_builder_function :: ( Generation . t ( ) , keyword ( ) -> String . t ( ) )
1212 @ type context_sources_builder_function :: ( Generation . t ( ) , keyword ( ) -> list ( String . t ( ) ) )
13+ @ type prompt_builder_function :: ( Generation . t ( ) , keyword ( ) -> String . t ( ) )
1314
1415 @ typedoc """
1516 Represents a generation, the main datastructure in `rag`.
@@ -184,4 +185,16 @@ defmodule Rag.Generation do
184185
185186 Generation . put_context_sources ( generation , context_sources )
186187 end
188+
189+ @ doc """
190+ Passes `generation` and `opts` to `prompt_builder_function` to determine the prompt.
191+ Then, puts the prompt in `generation.prompt`.
192+ """
193+ @ spec build_prompt ( t ( ) , prompt_builder_function ( ) , keyword ( ) ) :: t ( )
194+ def build_prompt ( % Generation { } = generation , prompt_builder_function , opts \\ [ ] )
195+ when is_function ( prompt_builder_function , 2 ) do
196+ prompt = prompt_builder_function . ( generation , opts )
197+
198+ Generation . put_prompt ( generation , prompt )
199+ end
187200end
Original file line number Diff line number Diff line change @@ -90,4 +90,15 @@ defmodule Rag.GenerationTest do
9090 Generation . build_context_sources ( generation , builder_fn , [ ] )
9191 end
9292 end
93+
94+ describe "build_prompt/3" do
95+ test "builds prompt according to builder function" do
96+ generation = % Generation { query: "query" }
97+
98+ builder_fn = fn _generation , _opts -> "this is the prompt" end
99+
100+ assert % { prompt: "this is the prompt" } =
101+ Generation . build_prompt ( generation , builder_fn , [ ] )
102+ end
103+ end
93104end
You can’t perform that action at this time.
0 commit comments