Sha256: a6f389f36a92e28df881fada48d32d52f17dd1920d9bd8d4306a38ecff5e5d9d

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

require 'webmock/rspec'
require_relative '../lib/rubyai/client.rb'

RSpec.describe RubyAI::Client do
  let(:api_key) { 'your_api_key' }
  let(:messages) { 'Hello, how are you?' }
  let(:temperature) { 0.7 }
  let(:model) { 'gpt-3.5-turbo' }

  before do
    RubyAI.configure do |config|
      config.api_key = api_key
      config.messages = messages
    end
  end

  describe '#call' do
    let(:response_body) { { 'choices' => [{ 'message' => { 'content' => 'This is a response from the model.' } }] } }
    let(:status) { 200 }

    before do
      stub_request(:post, RubyAI::Configuration::BASE_URL)
        .to_return(status: status, body: response_body.to_json, headers: { 'Content-Type' => 'application/json' })
    end

    it 'returns parsed JSON response when passing through client via configuration' do
      configuration = { api_key: RubyAI.configuration.api_key, messages: RubyAI.configuration.messages }
      client = described_class.new(configuration)
      result = client.call
      expect(result.dig('choices', 0, 'message', 'content')).to eq('This is a response from the model.')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubyai-0.5 spec/configuration_spec.rb