braintrust 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/braintrust/api/functions.rb +115 -1
- data/lib/braintrust/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aa149154056d58474a362bf2fba5b27a73670208a278aae56abc193971616de3
|
|
4
|
+
data.tar.gz: 5aeb130d705670e0baab100fa5203782fb3feaa0c39d4b228b54ac77ce581458
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c1c23282dff68a81cf9fd7f7b8509ee73d7050c9ce00b2184b7b8801941c9099e3aac21fdbba144a5d1fcfe93aa78d3bed25f03bce84ca4fbebb0440f3f524ef
|
|
7
|
+
data.tar.gz: f64dda4cf4622f791daa91b3b1a35a83dbb2bb1ac5ad201d41038875a9a1e968d9efbf6f258dbb207ab598869b2b7edcbb66415adada3806ad7b56e7fd0b1ebe
|
|
@@ -10,6 +10,12 @@ module Braintrust
|
|
|
10
10
|
# Functions API namespace
|
|
11
11
|
# Provides methods for creating, invoking, and managing remote functions (prompts)
|
|
12
12
|
class Functions
|
|
13
|
+
TYPE_LLM = "llm"
|
|
14
|
+
TYPE_PROMPT = "prompt"
|
|
15
|
+
TYPE_SCORER = "scorer"
|
|
16
|
+
TYPE_TASK = "task"
|
|
17
|
+
TYPE_TOOL = "tool"
|
|
18
|
+
|
|
13
19
|
def initialize(api)
|
|
14
20
|
@api = api
|
|
15
21
|
@state = api.state
|
|
@@ -43,8 +49,12 @@ module Braintrust
|
|
|
43
49
|
# @param prompt_data [Hash, nil] Prompt configuration (prompt, options, etc.)
|
|
44
50
|
# @param name [String, nil] Optional display name (defaults to slug)
|
|
45
51
|
# @param description [String, nil] Optional description
|
|
52
|
+
# @param function_type [String, nil] Function type ("llm", "scorer", "task", "tool", or nil)
|
|
53
|
+
# @param function_schema [Hash, nil] JSON schema for function parameters and return type
|
|
54
|
+
# @option function_schema [Hash] :parameters JSON schema for input parameters
|
|
55
|
+
# @option function_schema [Hash] :returns JSON schema for return value
|
|
46
56
|
# @return [Hash] Function metadata
|
|
47
|
-
def create(project_name:, slug:, function_data:, prompt_data: nil, name: nil, description: nil)
|
|
57
|
+
def create(project_name:, slug:, function_data:, prompt_data: nil, name: nil, description: nil, function_type: nil, function_schema: nil)
|
|
48
58
|
# Look up project ID
|
|
49
59
|
projects_result = http_get("/v1/project", {"project_name" => project_name})
|
|
50
60
|
project = projects_result["objects"]&.first
|
|
@@ -59,6 +69,8 @@ module Braintrust
|
|
|
59
69
|
}
|
|
60
70
|
payload[:prompt_data] = prompt_data if prompt_data
|
|
61
71
|
payload[:description] = description if description
|
|
72
|
+
payload[:function_type] = function_type if function_type
|
|
73
|
+
payload[:function_schema] = function_schema if function_schema
|
|
62
74
|
|
|
63
75
|
http_post_json("/v1/function", payload)
|
|
64
76
|
end
|
|
@@ -81,8 +93,110 @@ module Braintrust
|
|
|
81
93
|
http_delete("/v1/function/#{id}")
|
|
82
94
|
end
|
|
83
95
|
|
|
96
|
+
# Create a tool function
|
|
97
|
+
# Tools are functions that LLMs can call during execution.
|
|
98
|
+
# @param project_name [String] Project name
|
|
99
|
+
# @param slug [String] Function slug (URL-friendly identifier)
|
|
100
|
+
# @param prompt_data [Hash] Prompt configuration (prompt, options, etc.)
|
|
101
|
+
# @param name [String, nil] Optional display name (defaults to slug)
|
|
102
|
+
# @param description [String, nil] Description of what the tool does (recommended for LLM understanding)
|
|
103
|
+
# @param function_schema [Hash, nil] JSON schema defining the tool's parameters and return type
|
|
104
|
+
# @return [Hash] Function metadata
|
|
105
|
+
def create_tool(project_name:, slug:, prompt_data:, name: nil, description: nil, function_schema: nil)
|
|
106
|
+
validate_prompt_data!(prompt_data)
|
|
107
|
+
create(
|
|
108
|
+
project_name: project_name,
|
|
109
|
+
slug: slug,
|
|
110
|
+
function_data: {type: TYPE_PROMPT},
|
|
111
|
+
prompt_data: prompt_data,
|
|
112
|
+
name: name,
|
|
113
|
+
description: description,
|
|
114
|
+
function_type: TYPE_TOOL,
|
|
115
|
+
function_schema: function_schema
|
|
116
|
+
)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Create a scorer function
|
|
120
|
+
# Scorers evaluate task outputs and return scores (typically 0-1).
|
|
121
|
+
# @param project_name [String] Project name
|
|
122
|
+
# @param slug [String] Function slug (URL-friendly identifier)
|
|
123
|
+
# @param prompt_data [Hash] Prompt configuration for the scoring logic
|
|
124
|
+
# @param name [String, nil] Optional display name (defaults to slug)
|
|
125
|
+
# @param description [String, nil] Optional description
|
|
126
|
+
# @param function_schema [Hash, nil] JSON schema for parameters and return type
|
|
127
|
+
# @return [Hash] Function metadata
|
|
128
|
+
def create_scorer(project_name:, slug:, prompt_data:, name: nil, description: nil, function_schema: nil)
|
|
129
|
+
validate_prompt_data!(prompt_data)
|
|
130
|
+
create(
|
|
131
|
+
project_name: project_name,
|
|
132
|
+
slug: slug,
|
|
133
|
+
function_data: {type: TYPE_PROMPT},
|
|
134
|
+
prompt_data: prompt_data,
|
|
135
|
+
name: name,
|
|
136
|
+
description: description,
|
|
137
|
+
function_type: TYPE_SCORER,
|
|
138
|
+
function_schema: function_schema
|
|
139
|
+
)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# Create a task function
|
|
143
|
+
# Tasks are general-purpose prompt functions.
|
|
144
|
+
# @param project_name [String] Project name
|
|
145
|
+
# @param slug [String] Function slug (URL-friendly identifier)
|
|
146
|
+
# @param prompt_data [Hash] Prompt configuration (prompt, options, etc.)
|
|
147
|
+
# @param name [String, nil] Optional display name (defaults to slug)
|
|
148
|
+
# @param description [String, nil] Optional description
|
|
149
|
+
# @param function_schema [Hash, nil] JSON schema for parameters and return type
|
|
150
|
+
# @return [Hash] Function metadata
|
|
151
|
+
def create_task(project_name:, slug:, prompt_data:, name: nil, description: nil, function_schema: nil)
|
|
152
|
+
validate_prompt_data!(prompt_data)
|
|
153
|
+
create(
|
|
154
|
+
project_name: project_name,
|
|
155
|
+
slug: slug,
|
|
156
|
+
function_data: {type: TYPE_PROMPT},
|
|
157
|
+
prompt_data: prompt_data,
|
|
158
|
+
name: name,
|
|
159
|
+
description: description,
|
|
160
|
+
function_type: TYPE_TASK,
|
|
161
|
+
function_schema: function_schema
|
|
162
|
+
)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# Create an LLM function
|
|
166
|
+
# LLM functions are prompt-based functions categorized as LLM type.
|
|
167
|
+
# @param project_name [String] Project name
|
|
168
|
+
# @param slug [String] Function slug (URL-friendly identifier)
|
|
169
|
+
# @param prompt_data [Hash] Prompt configuration (prompt, options, etc.)
|
|
170
|
+
# @param name [String, nil] Optional display name (defaults to slug)
|
|
171
|
+
# @param description [String, nil] Optional description
|
|
172
|
+
# @param function_schema [Hash, nil] JSON schema for parameters and return type
|
|
173
|
+
# @return [Hash] Function metadata
|
|
174
|
+
def create_llm(project_name:, slug:, prompt_data:, name: nil, description: nil, function_schema: nil)
|
|
175
|
+
validate_prompt_data!(prompt_data)
|
|
176
|
+
create(
|
|
177
|
+
project_name: project_name,
|
|
178
|
+
slug: slug,
|
|
179
|
+
function_data: {type: TYPE_PROMPT},
|
|
180
|
+
prompt_data: prompt_data,
|
|
181
|
+
name: name,
|
|
182
|
+
description: description,
|
|
183
|
+
function_type: TYPE_LLM,
|
|
184
|
+
function_schema: function_schema
|
|
185
|
+
)
|
|
186
|
+
end
|
|
187
|
+
|
|
84
188
|
private
|
|
85
189
|
|
|
190
|
+
# Validate prompt_data structure
|
|
191
|
+
# @param prompt_data [Hash] The prompt data to validate
|
|
192
|
+
# @raise [ArgumentError] If prompt_data is invalid
|
|
193
|
+
def validate_prompt_data!(prompt_data)
|
|
194
|
+
raise ArgumentError, "prompt_data must be a Hash" unless prompt_data.is_a?(Hash)
|
|
195
|
+
|
|
196
|
+
has_prompt = prompt_data.key?(:prompt) || prompt_data.key?(TYPE_PROMPT)
|
|
197
|
+
raise ArgumentError, "prompt_data must contain a :prompt key" unless has_prompt
|
|
198
|
+
end
|
|
199
|
+
|
|
86
200
|
# Core HTTP request method with logging
|
|
87
201
|
# @param method [Symbol] :get, :post, or :delete
|
|
88
202
|
# @param path [String] API path
|
data/lib/braintrust/version.rb
CHANGED