|
| 1 | +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +import { APIResource } from '../resource'; |
| 4 | +import { isRequestOptions } from '../core'; |
| 5 | +import * as Core from '../core'; |
| 6 | +import * as CompletionAPI from './completion'; |
| 7 | + |
| 8 | +export class Completion extends APIResource { |
| 9 | + /** |
| 10 | + * Initiates a completion request to the configured LLM provider using specified |
| 11 | + * parameters and provided variables. This endpoint abstracts the integration with |
| 12 | + * different model providers, enabling seamless switching between models while |
| 13 | + * maintaining a consistent data model for your application. |
| 14 | + */ |
| 15 | + create( |
| 16 | + id: string, |
| 17 | + body?: CompletionCreateParams, |
| 18 | + options?: Core.RequestOptions, |
| 19 | + ): Core.APIPromise<CompletionCreateResponse>; |
| 20 | + create(id: string, options?: Core.RequestOptions): Core.APIPromise<CompletionCreateResponse>; |
| 21 | + create( |
| 22 | + id: string, |
| 23 | + body: CompletionCreateParams | Core.RequestOptions = {}, |
| 24 | + options?: Core.RequestOptions, |
| 25 | + ): Core.APIPromise<CompletionCreateResponse> { |
| 26 | + if (isRequestOptions(body)) { |
| 27 | + return this.create(id, {}, body); |
| 28 | + } |
| 29 | + return this._client.post(`/sdk/v1/prompts/${id}/completion`, { body, ...options }); |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +export interface CompletionCreateResponse { |
| 34 | + /** |
| 35 | + * The completion message generated by the model. |
| 36 | + */ |
| 37 | + message: CompletionCreateResponse.Message; |
| 38 | + |
| 39 | + stats: CompletionCreateResponse.Stats; |
| 40 | +} |
| 41 | + |
| 42 | +export namespace CompletionCreateResponse { |
| 43 | + /** |
| 44 | + * The completion message generated by the model. |
| 45 | + */ |
| 46 | + export interface Message { |
| 47 | + content: Array< |
| 48 | + | Message.TextContentBlockSchema |
| 49 | + | Message.ImageBase64ContentBlock |
| 50 | + | Message.ToolCallContentBlock |
| 51 | + | Message.ToolResultContentBlock |
| 52 | + >; |
| 53 | + |
| 54 | + role: 'assistant' | 'system' | 'tool' | 'user'; |
| 55 | + } |
| 56 | + |
| 57 | + export namespace Message { |
| 58 | + export interface TextContentBlockSchema { |
| 59 | + text: string; |
| 60 | + |
| 61 | + type: 'TEXT'; |
| 62 | + } |
| 63 | + |
| 64 | + export interface ImageBase64ContentBlock { |
| 65 | + imageBase64: string; |
| 66 | + |
| 67 | + mediaType: string; |
| 68 | + |
| 69 | + type: 'IMAGE_BASE64'; |
| 70 | + } |
| 71 | + |
| 72 | + export interface ToolCallContentBlock { |
| 73 | + toolCall: ToolCallContentBlock.ToolCall; |
| 74 | + |
| 75 | + type: 'TOOL_CALL'; |
| 76 | + } |
| 77 | + |
| 78 | + export namespace ToolCallContentBlock { |
| 79 | + export interface ToolCall { |
| 80 | + function: ToolCall.Function; |
| 81 | + |
| 82 | + /** |
| 83 | + * TOOL_CALL_1 |
| 84 | + */ |
| 85 | + toolCallId: string; |
| 86 | + |
| 87 | + /** |
| 88 | + * The type of the tool. Currently, only `function` is supported. |
| 89 | + */ |
| 90 | + type: 'function'; |
| 91 | + } |
| 92 | + |
| 93 | + export namespace ToolCall { |
| 94 | + export interface Function { |
| 95 | + /** |
| 96 | + * The arguments to call the function with, as generated by the model in JSON |
| 97 | + * format. Note that the model does not always generate valid JSON, and may |
| 98 | + * hallucinate parameters not defined by your function schema. Validate the |
| 99 | + * arguments in your code before calling your function. |
| 100 | + */ |
| 101 | + arguments: string; |
| 102 | + |
| 103 | + /** |
| 104 | + * The name of the function to call. |
| 105 | + */ |
| 106 | + name: string; |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + export interface ToolResultContentBlock { |
| 112 | + result: string; |
| 113 | + |
| 114 | + toolCallId: string; |
| 115 | + |
| 116 | + type: 'TOOL_RESULT'; |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + export interface Stats { |
| 121 | + /** |
| 122 | + * The cost of generating the completion. |
| 123 | + */ |
| 124 | + cost: number; |
| 125 | + |
| 126 | + /** |
| 127 | + * The number of tokens in the input prompt. |
| 128 | + */ |
| 129 | + inputTokenCount: number; |
| 130 | + |
| 131 | + /** |
| 132 | + * The time in milliseconds it took to generate the completion. |
| 133 | + */ |
| 134 | + latency: number; |
| 135 | + |
| 136 | + /** |
| 137 | + * The number of tokens in the output completion. |
| 138 | + */ |
| 139 | + outputTokenCount: number; |
| 140 | + } |
| 141 | +} |
| 142 | + |
| 143 | +export interface CompletionCreateParams { |
| 144 | + /** |
| 145 | + * Appended the the end of the configured prompt messages before running the |
| 146 | + * prompt. |
| 147 | + */ |
| 148 | + appendMessages?: Array<CompletionCreateParams.AppendMessage>; |
| 149 | + |
| 150 | + /** |
| 151 | + * Replaces the configured prompt messages when running the prompt. |
| 152 | + */ |
| 153 | + overrideMessages?: Array<CompletionCreateParams.OverrideMessage>; |
| 154 | + |
| 155 | + /** |
| 156 | + * A unique identifier representing your end-user, which can help monitor and |
| 157 | + * detect abuse. |
| 158 | + */ |
| 159 | + user?: string; |
| 160 | + |
| 161 | + /** |
| 162 | + * The template variables added to the prompt when executing the prompt. |
| 163 | + */ |
| 164 | + variables?: Record<string, string | null>; |
| 165 | +} |
| 166 | + |
| 167 | +export namespace CompletionCreateParams { |
| 168 | + export interface AppendMessage { |
| 169 | + content: Array< |
| 170 | + | AppendMessage.TextContentBlockSchema |
| 171 | + | AppendMessage.ImageBase64ContentBlock |
| 172 | + | AppendMessage.ToolCallContentBlock |
| 173 | + | AppendMessage.ToolResultContentBlock |
| 174 | + >; |
| 175 | + |
| 176 | + role: 'assistant' | 'system' | 'tool' | 'user'; |
| 177 | + } |
| 178 | + |
| 179 | + export namespace AppendMessage { |
| 180 | + export interface TextContentBlockSchema { |
| 181 | + text: string; |
| 182 | + |
| 183 | + type: 'TEXT'; |
| 184 | + } |
| 185 | + |
| 186 | + export interface ImageBase64ContentBlock { |
| 187 | + imageBase64: string; |
| 188 | + |
| 189 | + mediaType: string; |
| 190 | + |
| 191 | + type: 'IMAGE_BASE64'; |
| 192 | + } |
| 193 | + |
| 194 | + export interface ToolCallContentBlock { |
| 195 | + toolCall: ToolCallContentBlock.ToolCall; |
| 196 | + |
| 197 | + type: 'TOOL_CALL'; |
| 198 | + } |
| 199 | + |
| 200 | + export namespace ToolCallContentBlock { |
| 201 | + export interface ToolCall { |
| 202 | + function: ToolCall.Function; |
| 203 | + |
| 204 | + /** |
| 205 | + * TOOL_CALL_1 |
| 206 | + */ |
| 207 | + toolCallId: string; |
| 208 | + |
| 209 | + /** |
| 210 | + * The type of the tool. Currently, only `function` is supported. |
| 211 | + */ |
| 212 | + type: 'function'; |
| 213 | + } |
| 214 | + |
| 215 | + export namespace ToolCall { |
| 216 | + export interface Function { |
| 217 | + /** |
| 218 | + * The arguments to call the function with, as generated by the model in JSON |
| 219 | + * format. Note that the model does not always generate valid JSON, and may |
| 220 | + * hallucinate parameters not defined by your function schema. Validate the |
| 221 | + * arguments in your code before calling your function. |
| 222 | + */ |
| 223 | + arguments: string; |
| 224 | + |
| 225 | + /** |
| 226 | + * The name of the function to call. |
| 227 | + */ |
| 228 | + name: string; |
| 229 | + } |
| 230 | + } |
| 231 | + } |
| 232 | + |
| 233 | + export interface ToolResultContentBlock { |
| 234 | + result: string; |
| 235 | + |
| 236 | + toolCallId: string; |
| 237 | + |
| 238 | + type: 'TOOL_RESULT'; |
| 239 | + } |
| 240 | + } |
| 241 | + |
| 242 | + export interface OverrideMessage { |
| 243 | + content: Array< |
| 244 | + | OverrideMessage.TextContentBlockSchema |
| 245 | + | OverrideMessage.ImageBase64ContentBlock |
| 246 | + | OverrideMessage.ToolCallContentBlock |
| 247 | + | OverrideMessage.ToolResultContentBlock |
| 248 | + >; |
| 249 | + |
| 250 | + role: 'assistant' | 'system' | 'tool' | 'user'; |
| 251 | + } |
| 252 | + |
| 253 | + export namespace OverrideMessage { |
| 254 | + export interface TextContentBlockSchema { |
| 255 | + text: string; |
| 256 | + |
| 257 | + type: 'TEXT'; |
| 258 | + } |
| 259 | + |
| 260 | + export interface ImageBase64ContentBlock { |
| 261 | + imageBase64: string; |
| 262 | + |
| 263 | + mediaType: string; |
| 264 | + |
| 265 | + type: 'IMAGE_BASE64'; |
| 266 | + } |
| 267 | + |
| 268 | + export interface ToolCallContentBlock { |
| 269 | + toolCall: ToolCallContentBlock.ToolCall; |
| 270 | + |
| 271 | + type: 'TOOL_CALL'; |
| 272 | + } |
| 273 | + |
| 274 | + export namespace ToolCallContentBlock { |
| 275 | + export interface ToolCall { |
| 276 | + function: ToolCall.Function; |
| 277 | + |
| 278 | + /** |
| 279 | + * TOOL_CALL_1 |
| 280 | + */ |
| 281 | + toolCallId: string; |
| 282 | + |
| 283 | + /** |
| 284 | + * The type of the tool. Currently, only `function` is supported. |
| 285 | + */ |
| 286 | + type: 'function'; |
| 287 | + } |
| 288 | + |
| 289 | + export namespace ToolCall { |
| 290 | + export interface Function { |
| 291 | + /** |
| 292 | + * The arguments to call the function with, as generated by the model in JSON |
| 293 | + * format. Note that the model does not always generate valid JSON, and may |
| 294 | + * hallucinate parameters not defined by your function schema. Validate the |
| 295 | + * arguments in your code before calling your function. |
| 296 | + */ |
| 297 | + arguments: string; |
| 298 | + |
| 299 | + /** |
| 300 | + * The name of the function to call. |
| 301 | + */ |
| 302 | + name: string; |
| 303 | + } |
| 304 | + } |
| 305 | + } |
| 306 | + |
| 307 | + export interface ToolResultContentBlock { |
| 308 | + result: string; |
| 309 | + |
| 310 | + toolCallId: string; |
| 311 | + |
| 312 | + type: 'TOOL_RESULT'; |
| 313 | + } |
| 314 | + } |
| 315 | +} |
| 316 | + |
| 317 | +export namespace Completion { |
| 318 | + export import CompletionCreateResponse = CompletionAPI.CompletionCreateResponse; |
| 319 | + export import CompletionCreateParams = CompletionAPI.CompletionCreateParams; |
| 320 | +} |
0 commit comments