|
622 | 622 | expect(post.topic.posts.last.post_number).to eq(1) |
623 | 623 | end |
624 | 624 |
|
| 625 | + it "allows swapping a llm mid conversation using a mention" do |
| 626 | + SiteSetting.ai_bot_enabled = true |
| 627 | + |
| 628 | + post = nil |
| 629 | + DiscourseAi::Completions::Llm.with_prepared_responses( |
| 630 | + ["Yes I can", "Magic Title"], |
| 631 | + llm: "custom:#{claude_2.id}", |
| 632 | + ) do |
| 633 | + post = |
| 634 | + create_post( |
| 635 | + title: "I just made a PM", |
| 636 | + raw: "Hey there #{persona.user.username}, can you help me?", |
| 637 | + target_usernames: "#{user.username},#{persona.user.username}", |
| 638 | + archetype: Archetype.private_message, |
| 639 | + user: admin, |
| 640 | + ) |
| 641 | + end |
| 642 | + |
| 643 | + post.topic.custom_fields["ai_persona_id"] = persona.id |
| 644 | + post.topic.save_custom_fields |
| 645 | + |
| 646 | + llm2 = Fabricate(:llm_model, enabled_chat_bot: true) |
| 647 | + |
| 648 | + llm2.toggle_companion_user |
| 649 | + |
| 650 | + DiscourseAi::Completions::Llm.with_prepared_responses( |
| 651 | + ["Hi from bot two"], |
| 652 | + llm: "custom:#{llm2.id}", |
| 653 | + ) do |
| 654 | + create_post( |
| 655 | + user: admin, |
| 656 | + raw: "hi @#{llm2.user.username.capitalize} how are you", |
| 657 | + topic_id: post.topic_id, |
| 658 | + ) |
| 659 | + end |
| 660 | + |
| 661 | + last_post = post.topic.reload.posts.order("id desc").first |
| 662 | + expect(last_post.raw).to eq("Hi from bot two") |
| 663 | + expect(last_post.user_id).to eq(persona.user_id) |
| 664 | + |
| 665 | + # tether llm, so it can no longer be switched |
| 666 | + persona.update!(force_default_llm: true, default_llm: "custom:#{claude_2.id}") |
| 667 | + |
| 668 | + DiscourseAi::Completions::Llm.with_prepared_responses( |
| 669 | + ["Hi from bot one"], |
| 670 | + llm: "custom:#{claude_2.id}", |
| 671 | + ) do |
| 672 | + create_post( |
| 673 | + user: admin, |
| 674 | + raw: "hi @#{llm2.user.username.capitalize} how are you", |
| 675 | + topic_id: post.topic_id, |
| 676 | + ) |
| 677 | + end |
| 678 | + |
| 679 | + last_post = post.topic.reload.posts.order("id desc").first |
| 680 | + expect(last_post.raw).to eq("Hi from bot one") |
| 681 | + expect(last_post.user_id).to eq(persona.user_id) |
| 682 | + end |
| 683 | + |
625 | 684 | it "allows PMing a persona even when no particular bots are enabled" do |
626 | 685 | SiteSetting.ai_bot_enabled = true |
627 | 686 | toggle_enabled_bots(bots: []) |
|
0 commit comments