11test_that(" RagnarChat" , {
22 store <- test_store()
3- chat <- chat_ragnar(ellmer :: chat_openai , .store = store )
3+ chat <- chat_ragnar(ellmer :: chat_openai , model = " gpt-4.1-nano " , .store = store )
44
55 out <- chat $ chat(" advanced R" )
66
@@ -12,12 +12,18 @@ test_that("RagnarChat", {
1212 expect_equal(length(chat $ get_turns()), 2 )
1313
1414 out <- chat $ chat(" advanced R" )
15- expect_equal(length(chat $ get_turns()), 2 + 2 )
15+ # 2 turns that were already there + 2 turns of forced tool calls
16+ # + user + LLM
17+ expect_equal(length(chat $ get_turns()), 2 + 2 + 2 )
1618
1719 # the default pruning will clear the previous tool calls.
18- # so we end up with 6 turns
20+ # so we end up with 6 turns + 1 pair
1921 out <- chat $ chat(" more chatting" )
20- expect_equal(length(chat $ get_turns()), 2 + 2 + 2 )
22+ expect_equal(length(chat $ get_turns()), 6 + 2 )
23+
24+ # prune tool calls will clear two turns
25+ chat $ turns_prune_tool_calls()
26+ expect_equal(length(chat $ get_turns()), 6 )
2127})
2228
2329test_that(" Implementing query rewriting" , {
@@ -33,6 +39,7 @@ test_that("Implementing query rewriting", {
3339 store <- test_store()
3440 chat <- chat_ragnar(
3541 ellmer :: chat_openai ,
42+ model = " gpt-4.1-nano" ,
3643 .store = store ,
3744 .on_user_turn = function (self , ... ) {
3845
@@ -55,6 +62,7 @@ test_that("remove chunks by id works", {
5562 store <- test_store()
5663 chat <- chat_ragnar(
5764 ellmer :: chat_openai ,
65+ model = " gpt-4.1-nano" ,
5866 .store = store ,
5967 .on_user_turn = function (self , ... ) {
6068 self $ turns_insert_tool_call_request(
@@ -84,6 +92,7 @@ test_that("duplicated chunks are not returned", {
8492 store <- test_store()
8593 chat <- chat_ragnar(
8694 ellmer :: chat_openai ,
95+ model = " gpt-4.1-nano" ,
8796 .store = store ,
8897 .on_user_turn = function (self , ... ) {
8998 self $ turns_insert_tool_call_request(
@@ -102,3 +111,27 @@ test_that("duplicated chunks are not returned", {
102111
103112 expect_equal(length(unique(new_chunk_ids )), length(new_chunk_ids ))
104113})
114+
115+ test_that(" Can insert chunks premptively in the user chat" , {
116+ store <- test_store()
117+ chat <- chat_ragnar(
118+ ellmer :: chat_openai ,
119+ model = " gpt-4.1-nano" ,
120+ .store = store ,
121+ .on_user_turn = function (self , ... ) {
122+ self $ turns_insert_documents(
123+ ... ,
124+ query = paste(... , collapse = " " )
125+ )
126+ }
127+ )
128+
129+ out <- chat $ chat(" advanced R" )
130+ expect_equal(length(chat $ get_turns()), 2 )
131+ # it adds the documents into the context
132+ expect_equal(length(chat $ get_turns()[[1 ]]@ contents ), 2 )
133+
134+ chat $ turns_prune_chunks()
135+ expect_equal(length(chat $ get_turns()), 2 )
136+ expect_equal(length(chat $ get_turns()[[1 ]]@ contents ), 1 )
137+ })
0 commit comments