|
647 | 647 | end
|
648 | 648 |
|
649 | 649 | context "with Dall E bot" do
|
650 |
| - let(:bot) do |
651 |
| - persona = |
652 |
| - AiPersona |
653 |
| - .find( |
654 |
| - DiscourseAi::AiBot::Personas::Persona.system_personas[ |
655 |
| - DiscourseAi::AiBot::Personas::DallE3 |
656 |
| - ], |
657 |
| - ) |
658 |
| - .class_instance |
659 |
| - .new |
660 |
| - DiscourseAi::AiBot::Bot.as(bot_user, persona: persona) |
| 650 | + before { SiteSetting.ai_openai_api_key = "123" } |
| 651 | + |
| 652 | + let(:persona) do |
| 653 | + AiPersona.find( |
| 654 | + DiscourseAi::AiBot::Personas::Persona.system_personas[ |
| 655 | + DiscourseAi::AiBot::Personas::DallE3 |
| 656 | + ], |
| 657 | + ) |
661 | 658 | end
|
662 | 659 |
|
663 |
| - it "does not include placeholders in conversation context (simulate DALL-E)" do |
664 |
| - SiteSetting.ai_openai_api_key = "123" |
| 660 | + let(:bot) { DiscourseAi::AiBot::Bot.as(bot_user, persona: persona.class_instance.new) } |
| 661 | + let(:data) do |
| 662 | + image = |
| 663 | + "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==" |
| 664 | + |
| 665 | + [{ b64_json: image, revised_prompt: "a pink cow 1" }] |
| 666 | + end |
665 | 667 |
|
666 |
| - response = (<<~TXT).strip |
| 668 | + let(:response) { (<<~TXT).strip } |
667 | 669 | <function_calls>
|
668 | 670 | <invoke>
|
669 | 671 | <tool_name>dall_e</tool_name>
|
|
675 | 677 | </function_calls>
|
676 | 678 | TXT
|
677 | 679 |
|
678 |
| - image = |
679 |
| - "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==" |
| 680 | + it "properly returns an image when skipping tool details" do |
| 681 | + persona.update!(tool_details: false) |
680 | 682 |
|
681 |
| - data = [{ b64_json: image, revised_prompt: "a pink cow 1" }] |
| 683 | + WebMock.stub_request(:post, SiteSetting.ai_openai_dall_e_3_url).to_return( |
| 684 | + status: 200, |
| 685 | + body: { data: data }.to_json, |
| 686 | + ) |
| 687 | + |
| 688 | + DiscourseAi::Completions::Llm.with_prepared_responses([response]) do |
| 689 | + playground.reply_to(third_post) |
| 690 | + end |
| 691 | + |
| 692 | + last_post = third_post.topic.reload.posts.order(:post_number).last |
682 | 693 |
|
| 694 | + expect(last_post.raw).to include("a pink cow") |
| 695 | + end |
| 696 | + |
| 697 | + it "does not include placeholders in conversation context (simulate DALL-E)" do |
683 | 698 | WebMock.stub_request(:post, SiteSetting.ai_openai_dall_e_3_url).to_return(
|
684 | 699 | status: 200,
|
685 | 700 | body: { data: data }.to_json,
|
|
0 commit comments