Class: Braintrust::Resources::Prompt

Inherits:
Object
  • Object
show all
Defined in:
lib/braintrust/resources/prompt.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Prompt

Returns a new instance of Prompt.



6
7
8
# File 'lib/braintrust/resources/prompt.rb', line 6

def initialize(client:)
  @client = client
end

Instance Method Details

#create(params = {}, opts = {}) ⇒ Braintrust::Models::Prompt

Create a new prompt. If there is an existing prompt in the project with the same slug as the one specified in the request, will return the existing prompt unmodified

Parameters:

  • params (Hash) (defaults to: {})

    Attributes to send in this request.

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Options Hash (params):

  • :name (String)

    Name of the prompt

  • :project_id (String)

    Unique identifier for the project that the prompt belongs under

  • :slug (String)

    Unique identifier for the prompt

  • :description (String)

    Textual description of the prompt

  • :prompt_data (PromptData)

    The prompt, model, and its parameters

  • :tags (Array<String>)

    A list of tags for the prompt

Returns:



25
26
27
28
29
30
31
32
# File 'lib/braintrust/resources/prompt.rb', line 25

def create(params = {}, opts = {})
  req = {}
  req[:method] = :post
  req[:path] = "/v1/prompt"
  req[:body] = params
  req[:model] = Braintrust::Models::Prompt
  @client.request(req, opts)
end

#delete(prompt_id, opts = {}) ⇒ Braintrust::Models::Prompt

Delete a prompt object by its id

Parameters:

  • prompt_id (String)

    Prompt id

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Returns:



118
119
120
121
122
123
124
# File 'lib/braintrust/resources/prompt.rb', line 118

def delete(prompt_id, opts = {})
  req = {}
  req[:method] = :delete
  req[:path] = "/v1/prompt/#{prompt_id}"
  req[:model] = Braintrust::Models::Prompt
  @client.request(req, opts)
end

#feedback(prompt_id, params = {}, opts = {}) ⇒ nil

Log feedback for a set of prompt events

Parameters:

  • prompt_id (String)

    Prompt id

  • params (Hash) (defaults to: {})

    Attributes to send in this request.

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Options Hash (params):

  • :feedback (Array<Feedback>)

    A list of prompt feedback items

Returns:

  • (nil)


136
137
138
139
140
141
142
143
# File 'lib/braintrust/resources/prompt.rb', line 136

def feedback(prompt_id, params = {}, opts = {})
  req = {}
  req[:method] = :post
  req[:path] = "/v1/prompt/#{prompt_id}/feedback"
  req[:body] = params
  req[:model] = NilClass
  @client.request(req, opts)
end

#list(params = {}, opts = {}) ⇒ Braintrust::ListObjects<Braintrust::Models::Prompt>

List out all prompts. The prompts are sorted by creation date, with the most recently-created prompts coming first

Parameters:

  • params (Hash) (defaults to: {})

    Attributes to send in this request.

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Options Hash (params):

  • :ending_before (String)

    Pagination cursor id.

    For example, if the initial item in the last page you fetched had an id of foo, pass ending_before=foo to fetch the previous page. Note: you may only pass one of starting_after and ending_before

  • :ids (Array<String>|String)

    Filter search results to a particular set of object IDs. To specify a list of IDs, include the query param multiple times

  • :limit (Integer)

    Limit the number of objects to return

  • :org_name (String)

    Filter search results to within a particular organization

  • :project_name (String)

    Name of the project to search for

  • :prompt_name (String)

    Name of the prompt to search for

  • :slug (String)

    Retrieve prompt with a specific slug

  • :starting_after (String)

    Pagination cursor id.

    For example, if the final item in the last page you fetched had an id of foo, pass starting_after=foo to fetch the next page. Note: you may only pass one of starting_after and ending_before

  • :version (String)

    Retrieve a snapshot of events from a past time

    The version id is essentially a filter on the latest event transaction id. You can use the max_xact_id returned by a past fetch as the version to reproduce that exact fetch.

Returns:



102
103
104
105
106
107
108
109
110
# File 'lib/braintrust/resources/prompt.rb', line 102

def list(params = {}, opts = {})
  req = {}
  req[:method] = :get
  req[:path] = "/v1/prompt"
  req[:query] = params
  req[:page] = Braintrust::ListObjects
  req[:model] = Braintrust::Models::Prompt
  @client.request(req, opts)
end

#replace(params = {}, opts = {}) ⇒ Braintrust::Models::Prompt

NOTE: This operation is deprecated and will be removed in a future revision of the API. Create or replace a new prompt. If there is an existing prompt in the project with the same slug as the one specified in the request, will return the existing prompt unmodified, will replace the existing prompt with the provided fields

Parameters:

  • params (Hash) (defaults to: {})

    Attributes to send in this request.

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Options Hash (params):

  • :name (String)

    Name of the prompt

  • :project_id (String)

    Unique identifier for the project that the prompt belongs under

  • :slug (String)

    Unique identifier for the prompt

  • :description (String)

    Textual description of the prompt

  • :prompt_data (PromptData)

    The prompt, model, and its parameters

  • :tags (Array<String>)

    A list of tags for the prompt

Returns:



162
163
164
165
166
167
168
169
# File 'lib/braintrust/resources/prompt.rb', line 162

def replace(params = {}, opts = {})
  req = {}
  req[:method] = :put
  req[:path] = "/v1/prompt"
  req[:body] = params
  req[:model] = Braintrust::Models::Prompt
  @client.request(req, opts)
end

#retrieve(prompt_id, opts = {}) ⇒ Braintrust::Models::Prompt

Get a prompt object by its id

Parameters:

  • prompt_id (String)

    Prompt id

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Returns:



40
41
42
43
44
45
46
# File 'lib/braintrust/resources/prompt.rb', line 40

def retrieve(prompt_id, opts = {})
  req = {}
  req[:method] = :get
  req[:path] = "/v1/prompt/#{prompt_id}"
  req[:model] = Braintrust::Models::Prompt
  @client.request(req, opts)
end

#update(prompt_id, params = {}, opts = {}) ⇒ Braintrust::Models::Prompt

Partially update a prompt object. Specify the fields to update in the payload. Any object-type fields will be deep-merged with existing content. Currently we do not support removing fields or setting them to null.

Parameters:

  • prompt_id (String)

    Prompt id

  • params (Hash) (defaults to: {})

    Attributes to send in this request.

  • opts (Hash|RequestOptions) (defaults to: {})

    Options to specify HTTP behaviour for this request.

Options Hash (params):

  • :description (String)

    Textual description of the prompt

  • :name (String)

    Name of the prompt

  • :prompt_data (PromptData)

    The prompt, model, and its parameters

  • :tags (Array<String>)

    A list of tags for the prompt

Returns:



63
64
65
66
67
68
69
70
# File 'lib/braintrust/resources/prompt.rb', line 63

def update(prompt_id, params = {}, opts = {})
  req = {}
  req[:method] = :patch
  req[:path] = "/v1/prompt/#{prompt_id}"
  req[:body] = params
  req[:model] = Braintrust::Models::Prompt
  @client.request(req, opts)
end