Class: Braintrust::Resources::Prompts

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Prompts

Returns a new instance of Prompts.



6
7
8
# File 'lib/braintrust/resources/prompts.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

  • :function_type (Symbol)
  • :prompt_data (Braintrust::Models::PromptData)

    The prompt, model, and its parameters

  • :tags (Array<String>)

    A list of tags for the prompt

Returns:



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

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:



120
121
122
123
124
125
126
# File 'lib/braintrust/resources/prompts.rb', line 120

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

#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_id (String)

    Project id

  • :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 prompt at a specific version.

    The version id can either be a transaction id (e.g. '1000192656880881099') or a version identifier (e.g. '81cd05ee665fdfb3').

Returns:



104
105
106
107
108
109
110
111
112
# File 'lib/braintrust/resources/prompts.rb', line 104

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

Create or replace prompt. If there is an existing prompt in the project with the same slug as the one specified in the request, 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

  • :function_type (Symbol)
  • :prompt_data (Braintrust::Models::PromptData)

    The prompt, model, and its parameters

  • :tags (Array<String>)

    A list of tags for the prompt

Returns:



144
145
146
147
148
149
150
151
# File 'lib/braintrust/resources/prompts.rb', line 144

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:



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

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 (Braintrust::Models::PromptData)

    The prompt, model, and its parameters

  • :slug (String)

    Unique identifier for the prompt

  • :tags (Array<String>)

    A list of tags for the prompt

Returns:



65
66
67
68
69
70
71
72
# File 'lib/braintrust/resources/prompts.rb', line 65

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