@@ -227,7 +227,7 @@ def update_playground_with(post)
227227 schedule_bot_reply ( post ) if can_attach? ( post )
228228 end
229229
230- def conversation_context ( post , style : nil )
230+ def post_prompt_messages ( post , style : nil )
231231 # Pay attention to the `post_number <= ?` here.
232232 # We want to inject the last post as context because they are translated differently.
233233
@@ -307,10 +307,10 @@ def conversation_context(post, style: nil)
307307 end
308308
309309 def title_playground ( post , user )
310- context = conversation_context ( post )
310+ messages = post_prompt_messages ( post )
311311
312312 bot
313- . get_updated_title ( context , post , user )
313+ . get_updated_title ( messages , post , user )
314314 . tap do |new_title |
315315 PostRevisor . new ( post . topic . first_post , post . topic ) . revise! (
316316 bot . bot_user ,
@@ -326,7 +326,7 @@ def title_playground(post, user)
326326 )
327327 end
328328
329- def chat_context ( message , channel , persona_user , context_post_ids )
329+ def chat_prompt_messages ( message , channel , persona_user , context_post_ids )
330330 has_vision = bot . persona . class . vision_enabled
331331 include_thread_titles = !channel . direct_message_channel? && !message . thread_id
332332
@@ -411,9 +411,9 @@ def reply_to_chat_message(message, channel, context_post_ids)
411411 context_post_ids = nil if !channel . direct_message_channel?
412412
413413 context =
414- get_context (
415- participants : participants . join ( ", " ) ,
416- conversation_context : chat_context ( message , channel , persona_user , context_post_ids ) ,
414+ BotContext . new (
415+ participants : participants ,
416+ messages : chat_prompt_messages ( message , channel , persona_user , context_post_ids ) ,
417417 user : message . user ,
418418 skip_tool_details : true ,
419419 )
@@ -460,22 +460,6 @@ def reply_to_chat_message(message, channel, context_post_ids)
460460 reply
461461 end
462462
463- def get_context ( participants :, conversation_context :, user :, skip_tool_details : nil )
464- result = {
465- site_url : Discourse . base_url ,
466- site_title : SiteSetting . title ,
467- site_description : SiteSetting . site_description ,
468- time : Time . zone . now ,
469- participants : participants ,
470- conversation_context : conversation_context ,
471- user : user ,
472- }
473-
474- result [ :skip_tool_details ] = true if skip_tool_details
475-
476- result
477- end
478-
479463 def reply_to (
480464 post ,
481465 custom_instructions : nil ,
@@ -510,15 +494,11 @@ def reply_to(
510494 )
511495
512496 context =
513- get_context (
514- participants : post . topic . allowed_users . map ( & :username ) . join ( ", " ) ,
515- conversation_context : conversation_context ( post , style : context_style ) ,
516- user : post . user ,
497+ BotContext . new (
498+ post : post ,
499+ custom_instructions : custom_instructions ,
500+ messages : post_prompt_messages ( post , style : context_style ) ,
517501 )
518- context [ :post_id ] = post . id
519- context [ :topic_id ] = post . topic_id
520- context [ :private_message ] = post . topic . private_message?
521- context [ :custom_instructions ] = custom_instructions
522502
523503 reply_user = bot . bot_user
524504 if bot . persona . class . respond_to? ( :user_id )
@@ -562,7 +542,7 @@ def reply_to(
562542 Discourse . redis . setex ( redis_stream_key , 60 , 1 )
563543 end
564544
565- context [ : skip_tool_details] ||= !bot . persona . class . tool_details
545+ context . skip_tool_details ||= !bot . persona . class . tool_details
566546
567547 post_streamer = PostStreamer . new ( delay : Rails . env . test? ? 0 : 0.5 ) if stream_reply
568548
0 commit comments