Class: PullRequestAi::OpenAi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/pull_request_ai/openAi/client.rb

Overview

A client to communicate with the OpenAI API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(openai_api_key: nil, openai_api_endpoint: nil, api_version: nil, model: nil, temperature: nil) ⇒ Client

Initializes the client.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pull_request_ai/openAi/client.rb', line 16

def initialize(
  openai_api_key: nil,
  openai_api_endpoint: nil,
  api_version: nil,
  model: nil,
  temperature: nil
)
  @openai_api_key = openai_api_key || PullRequestAi.openai_api_key
  @openai_api_endpoint = openai_api_endpoint || PullRequestAi.openai_api_endpoint
  @api_version = api_version || PullRequestAi.api_version
  @model = model || PullRequestAi.model
  @temperature = temperature || PullRequestAi.temperature
  @http_timeout = PullRequestAi.http_timeout
end

Instance Attribute Details

#api_versionObject

Returns the value of attribute api_version.



9
10
11
# File 'lib/pull_request_ai/openAi/client.rb', line 9

def api_version
  @api_version
end

#http_timeoutObject (readonly)

Returns the value of attribute http_timeout.



12
13
14
# File 'lib/pull_request_ai/openAi/client.rb', line 12

def http_timeout
  @http_timeout
end

#modelObject

Returns the value of attribute model.



10
11
12
# File 'lib/pull_request_ai/openAi/client.rb', line 10

def model
  @model
end

#openai_api_endpointObject

Returns the value of attribute openai_api_endpoint.



8
9
10
# File 'lib/pull_request_ai/openAi/client.rb', line 8

def openai_api_endpoint
  @openai_api_endpoint
end

#openai_api_keyObject

Returns the value of attribute openai_api_key.



7
8
9
# File 'lib/pull_request_ai/openAi/client.rb', line 7

def openai_api_key
  @openai_api_key
end

#temperatureObject

Returns the value of attribute temperature.



11
12
13
# File 'lib/pull_request_ai/openAi/client.rb', line 11

def temperature
  @temperature
end

Instance Method Details

#predicted_completions(content) ⇒ Object

Makes the completions request from the OpenAI API. Given a prompt, the model will return one or more predicted completions. platform.openai.com/docs/api-reference/chat



35
36
37
38
# File 'lib/pull_request_ai/openAi/client.rb', line 35

def predicted_completions(content)
  url = build_url
  request(:post, url, body(content))
end