42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/boxcars/engine/cohere.rb', line 42
def chat(params, cohere_api_key)
raise Boxcars::ConfigurationError('Cohere API key not set') if cohere_api_key.blank?
api_endpoint = 'https://api.cohere.ai/v1/chat'
connection = Faraday.new(api_endpoint) do |faraday|
faraday.request :url_encoded
faraday.['Authorization'] = "Bearer #{cohere_api_key}"
faraday.['Content-Type'] = 'application/json'
end
response = connection.post { |req| req.body = params.to_json }
JSON.parse(response.body, symbolize_names: true)
end
|