# frozen_string_literal: true
require "rails_helper"
module DiscourseAi::Inference
  describe FunctionList do
    let :function_list do
      function =
        Function.new(name: "get_weather", description: "Get the weather in a city (default to c)")
      function.add_parameter(
        name: "location",
        type: "string",
        description: "the city name",
        required: true,
      )
      function.add_parameter(
        name: "unit",
        type: "string",
        description: "the unit of measurement celcius c or fahrenheit f",
        enum: %w[c f],
        required: false,
      )
      list = FunctionList.new
      list << function
      list
    end
    let :image_function_list do
      function = Function.new(name: "image", description: "generates an image")
      function.add_parameter(
        name: "prompts",
        type: "array",
        item_type: "string",
        required: true,
        description: "the prompts",
      )
      list = FunctionList.new
      list << function
      list
    end
    it "can handle function call parsing" do
      raw_prompt = <<~PROMPT
      
      
      image
      
      
      [
      "an oil painting",
      "a cute fluffy orange",
      "3 apple's",
      "a cat"
      ]
      
      
      
      
      PROMPT
      parsed = image_function_list.parse_prompt(raw_prompt)
      expect(parsed).to eq(
        [
          {
            name: "image",
            arguments: {
              prompts: ["an oil painting", "a cute fluffy orange", "3 apple's", "a cat"],
            },
          },
        ],
      )
    end
    it "can generate a general custom system prompt" do
      prompt = function_list.system_prompt
      # this is fragile, by design, we need to test something here
      #
      expected = <<~PROMPT
        
        
        get_weather
        Get the weather in a city (default to c)
        
        
        location
        string
        the city name
        true
        
        
        unit
        string
        the unit of measurement celcius c or fahrenheit f
        false
        c,f
        
        
        
        
      PROMPT
      expect(prompt).to include(expected)
    end
  end
end