Class: Braintrust::Resources::Functions

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Functions



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

def initialize(client:)
  @client = client
end

Instance Method Details

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

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

Options Hash (params):

  • :function_data (FunctionData::UnnamedTypeWithunionParent21|FunctionData::UnnamedTypeWithunionParent22|FunctionData::UnnamedTypeWithunionParent23)
  • :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_schema (FunctionSchema)

    JSON schema for the function's parameters and return type

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

    The prompt, model, and its parameters

  • :tags (Array<String>)

    A list of tags for the prompt



29
30
31
32
33
34
35
36
# File 'lib/braintrust/resources/functions.rb', line 29

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

#delete(function_id, opts = {}) ⇒ Braintrust::Models::Function

Delete a function object by its id



123
124
125
126
127
128
129
# File 'lib/braintrust/resources/functions.rb', line 123

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

#invoke(function_id, params = {}, opts = {}) ⇒ Object

Invoke a function.

Options Hash (params):

  • :input (Object)

    Argument to the function, which can be any JSON serializable value

  • :messages (Array<Message::UnnamedTypeWithunionParent28|Message::UnnamedTypeWithunionParent29|Message::UnnamedTypeWithunionParent30|Message::UnnamedTypeWithunionParent31|Message::UnnamedTypeWithunionParent32|Message::UnnamedTypeWithunionParent33>)

    If the function is an LLM, additional messages to pass along to it

  • :mode (Symbol)

    The mode format of the returned value (defaults to 'auto')

  • :parent (Parent::UnnamedTypeWithunionParent34|String)

    Options for tracing the function call

  • :stream (Boolean)

    Whether to stream the response. If true, results will be returned in the Braintrust SSE format.

  • :version (String)

    The version of the function



147
148
149
150
151
152
153
154
# File 'lib/braintrust/resources/functions.rb', line 147

def invoke(function_id, params = {}, opts = {})
  req = {}
  req[:method] = :post
  req[:path] = "/v1/function/#{function_id}/invoke"
  req[:body] = params
  req[:model] = Braintrust::Unknown
  @client.request(req, opts)
end

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

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

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

  • :function_name (String)

    Name of the function to search for

  • :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

  • :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').



107
108
109
110
111
112
113
114
115
# File 'lib/braintrust/resources/functions.rb', line 107

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

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

Create or replace function. If there is an existing function in the project with the same slug as the one specified in the request, will replace the existing function with the provided fields

Options Hash (params):

  • :function_data (FunctionData::UnnamedTypeWithunionParent35|FunctionData::UnnamedTypeWithunionParent36|FunctionData::UnnamedTypeWithunionParent37)
  • :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_schema (FunctionSchema)

    JSON schema for the function's parameters and return type

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

    The prompt, model, and its parameters

  • :tags (Array<String>)

    A list of tags for the prompt



175
176
177
178
179
180
181
182
# File 'lib/braintrust/resources/functions.rb', line 175

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

#retrieve(function_id, opts = {}) ⇒ Braintrust::Models::Function

Get a function object by its id



44
45
46
47
48
49
50
# File 'lib/braintrust/resources/functions.rb', line 44

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

#update(function_id, params = {}, opts = {}) ⇒ Braintrust::Models::Function

Partially update a function 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.

Options Hash (params):

  • :description (String)

    Textual description of the prompt

  • :function_data (FunctionData::UnnamedTypeWithunionParent24|FunctionData::UnnamedTypeWithunionParent25|FunctionData::UnnamedTypeWithunionParent26|FunctionData::UnnamedTypeWithunionParent27)
  • :name (String)

    Name of the prompt

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

    The prompt, model, and its parameters

  • :tags (Array<String>)

    A list of tags for the prompt



68
69
70
71
72
73
74
75
# File 'lib/braintrust/resources/functions.rb', line 68

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