diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile old mode 100755 new mode 100644 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json old mode 100755 new mode 100644 diff --git a/.eslintrc.js b/.eslintrc.js old mode 100755 new mode 100644 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml old mode 100755 new mode 100644 index d791adb..e3530dc --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,11 +22,30 @@ jobs: with: node-version: '18' - - name: Install dependencies - run: yarn install + - name: Bootstrap + run: ./scripts/bootstrap - name: Check types run: ./scripts/lint + + build: + name: build + runs-on: ubuntu-latest + + + steps: + - uses: actions/checkout@v4 + + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Bootstrap + run: ./scripts/bootstrap + + - name: Check build + run: ./scripts/build test: name: test runs-on: ubuntu-latest diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml old mode 100755 new mode 100644 diff --git a/.github/workflows/release-doctor.yml b/.github/workflows/release-doctor.yml old mode 100755 new mode 100644 diff --git a/.gitignore b/.gitignore old mode 100755 new mode 100644 diff --git a/.prettierignore b/.prettierignore old mode 100755 new mode 100644 diff --git a/.prettierrc.json b/.prettierrc.json old mode 100755 new mode 100644 diff --git a/.release-please-manifest.json b/.release-please-manifest.json old mode 100755 new mode 100644 index 18e9f06..d0d087a --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.18.0" + ".": "1.19.0" } diff --git a/.stats.yml b/.stats.yml old mode 100755 new mode 100644 index 112acec..0222f21 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ configured_endpoints: 22 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/prompt-foundry%2Fprompt-foundry-sdk-84eb1e848fd165a965df78740df71651a8b413f023e5fdb6eb1acb9cce08e006.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/prompt-foundry%2Fprompt-foundry-sdk-d232bc0a3409f271bb778f567e5caeb18bea44e721c3d82a78f475f9ca3faa2b.yml diff --git a/Brewfile b/Brewfile old mode 100755 new mode 100644 diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e527a3..430e7f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,43 @@ # Changelog +## 1.19.0 (2024-09-14) + +Full Changelog: [v1.18.0...v1.19.0](https://github.com/prompt-foundry/typescript-sdk/compare/v1.18.0...v1.19.0) + +### Features + +* **api:** OpenAPI spec update via Stainless API ([#296](https://github.com/prompt-foundry/typescript-sdk/issues/296)) ([b109397](https://github.com/prompt-foundry/typescript-sdk/commit/b1093976c3be6e8389d65d127ebe856d2a34ff9b)) +* **api:** OpenAPI spec update via Stainless API ([#298](https://github.com/prompt-foundry/typescript-sdk/issues/298)) ([22df253](https://github.com/prompt-foundry/typescript-sdk/commit/22df253af20a541055c4343da65e7ef0774980b0)) +* **api:** OpenAPI spec update via Stainless API ([#299](https://github.com/prompt-foundry/typescript-sdk/issues/299)) ([aeb5bd3](https://github.com/prompt-foundry/typescript-sdk/commit/aeb5bd3613548139d4fbf332a2f48ef110ac87b1)) +* **api:** OpenAPI spec update via Stainless API ([#300](https://github.com/prompt-foundry/typescript-sdk/issues/300)) ([ab92cbf](https://github.com/prompt-foundry/typescript-sdk/commit/ab92cbf32a5e3373825d653b8b19ecdbd93c6fe7)) +* **api:** OpenAPI spec update via Stainless API ([#301](https://github.com/prompt-foundry/typescript-sdk/issues/301)) ([0cd49b4](https://github.com/prompt-foundry/typescript-sdk/commit/0cd49b4545499086879da70f5f620e90b189a6e6)) +* **api:** OpenAPI spec update via Stainless API ([#302](https://github.com/prompt-foundry/typescript-sdk/issues/302)) ([c78917f](https://github.com/prompt-foundry/typescript-sdk/commit/c78917fe2d358ba099969afb3a7982614c693c75)) +* **api:** OpenAPI spec update via Stainless API ([#303](https://github.com/prompt-foundry/typescript-sdk/issues/303)) ([dd0b8fb](https://github.com/prompt-foundry/typescript-sdk/commit/dd0b8fb614803dd001962871ad6964c0c48b8751)) +* **api:** OpenAPI spec update via Stainless API ([#304](https://github.com/prompt-foundry/typescript-sdk/issues/304)) ([cdd4c5f](https://github.com/prompt-foundry/typescript-sdk/commit/cdd4c5fa4a07b7e7e84e424bd6c56e92f0c16559)) +* **api:** OpenAPI spec update via Stainless API ([#305](https://github.com/prompt-foundry/typescript-sdk/issues/305)) ([9d85271](https://github.com/prompt-foundry/typescript-sdk/commit/9d85271e34f76fbf1dcb2b9f37e05d88f10bdb2e)) +* **api:** OpenAPI spec update via Stainless API ([#308](https://github.com/prompt-foundry/typescript-sdk/issues/308)) ([1c39d23](https://github.com/prompt-foundry/typescript-sdk/commit/1c39d23aaf9c86dd2eebd094ca2f768bd4ea2291)) +* **api:** OpenAPI spec update via Stainless API ([#311](https://github.com/prompt-foundry/typescript-sdk/issues/311)) ([80d0a53](https://github.com/prompt-foundry/typescript-sdk/commit/80d0a53aefee1441308ae23ef509a3672692a5c7)) + + +### Bug Fixes + +* **client:** correct File construction from node-fetch Responses ([#309](https://github.com/prompt-foundry/typescript-sdk/issues/309)) ([30fb68e](https://github.com/prompt-foundry/typescript-sdk/commit/30fb68e1fa8fcbecc0372d6357d7258fa04655b8)) +* **errors:** pass message through to APIConnectionError ([#313](https://github.com/prompt-foundry/typescript-sdk/issues/313)) ([694c64f](https://github.com/prompt-foundry/typescript-sdk/commit/694c64f2fa194e9bc5497facd1671efd7b300f5e)) + + +### Chores + +* better object fallback behaviour for casting errors ([#314](https://github.com/prompt-foundry/typescript-sdk/issues/314)) ([2aa9f07](https://github.com/prompt-foundry/typescript-sdk/commit/2aa9f07f487316818567b6963dce705d48d8233e)) +* **ci:** check for build errors ([#297](https://github.com/prompt-foundry/typescript-sdk/issues/297)) ([2b8b0d7](https://github.com/prompt-foundry/typescript-sdk/commit/2b8b0d7841454afe4a164217a1cccd7e3d58e2a5)) +* **ci:** install deps via ./script/bootstrap ([#307](https://github.com/prompt-foundry/typescript-sdk/issues/307)) ([8b757ee](https://github.com/prompt-foundry/typescript-sdk/commit/8b757ee63f894eb9498d575f2155732703d10995)) +* **internal:** codegen related update ([#312](https://github.com/prompt-foundry/typescript-sdk/issues/312)) ([14613c4](https://github.com/prompt-foundry/typescript-sdk/commit/14613c4fc73afd6fadaae1fb9e1de40af7edc889)) +* run tsc as part of lint script ([#306](https://github.com/prompt-foundry/typescript-sdk/issues/306)) ([e19c47f](https://github.com/prompt-foundry/typescript-sdk/commit/e19c47f427c47c2a645f03e1b1e2934acd5bc27e)) + + +### Documentation + +* update CONTRIBUTING.md ([#315](https://github.com/prompt-foundry/typescript-sdk/issues/315)) ([d24e88f](https://github.com/prompt-foundry/typescript-sdk/commit/d24e88f6ed1cfc692972c6200d89e6b2d5f2cc07)) + ## 1.18.0 (2024-08-26) Full Changelog: [v1.17.0...v1.18.0](https://github.com/prompt-foundry/typescript-sdk/compare/v1.17.0...v1.18.0) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md old mode 100755 new mode 100644 index a23c828..42d1f88 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,13 +14,13 @@ This will install all the required dependencies and build output files to `dist/ ## Modifying/Adding code -Most of the SDK is generated code, and any modified code will be overridden on the next generation. The -`src/lib/` and `examples/` directories are exceptions and will never be overridden. +Most of the SDK is generated code. Modifications to code will be persisted between generations, but may +result in merge conflicts between manual patches and changes from the generator. The generator will never +modify the contents of the `src/lib/` and `examples/` directories. ## Adding and running examples -All files in the `examples/` directory are not modified by the Stainless generator and can be freely edited or -added to. +All files in the `examples/` directory are not modified by the generator and can be freely edited or added to. ```bash // add an example to examples/.ts diff --git a/LICENSE b/LICENSE old mode 100755 new mode 100644 diff --git a/README.md b/README.md old mode 100755 new mode 100644 diff --git a/SECURITY.md b/SECURITY.md old mode 100755 new mode 100644 diff --git a/api.md b/api.md old mode 100755 new mode 100644 index 23342fa..05b561b --- a/api.md +++ b/api.md @@ -12,10 +12,10 @@ Methods: Types: -- Parameters - PromptConfiguration - PromptListResponse - PromptDeleteResponse +- PromptGetParametersResponse Methods: @@ -24,7 +24,7 @@ Methods: - client.prompts.list() -> PromptListResponse - client.prompts.delete(id) -> PromptDeleteResponse - client.prompts.get(id) -> PromptConfiguration -- client.prompts.getParameters(id, { ...params }) -> Parameters +- client.prompts.getParameters(id, { ...params }) -> PromptGetParametersResponse # Tools diff --git a/bin/check-release-environment b/bin/check-release-environment old mode 100755 new mode 100644 diff --git a/bin/publish-npm b/bin/publish-npm old mode 100755 new mode 100644 diff --git a/examples/.keep b/examples/.keep old mode 100755 new mode 100644 diff --git a/jest.config.ts b/jest.config.ts old mode 100755 new mode 100644 diff --git a/package.json b/package.json old mode 100755 new mode 100644 index 6348e0d..9ab7ba8 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@prompt-foundry/typescript-sdk", - "version": "1.18.0", + "version": "1.19.0", "description": "The official TypeScript library for the Prompt Foundry API", "author": "Prompt Foundry ", "types": "dist/index.d.ts", diff --git a/release-please-config.json b/release-please-config.json old mode 100755 new mode 100644 diff --git a/scripts/lint b/scripts/lint index 4af1de0..6ba75df 100755 --- a/scripts/lint +++ b/scripts/lint @@ -6,3 +6,6 @@ cd "$(dirname "$0")/.." echo "==> Running eslint" ESLINT_USE_FLAT_CONFIG="false" ./node_modules/.bin/eslint --ext ts,js . + +echo "==> Running tsc" +./node_modules/.bin/tsc --noEmit diff --git a/scripts/utils/check-version.cjs b/scripts/utils/check-version.cjs old mode 100755 new mode 100644 diff --git a/scripts/utils/fix-index-exports.cjs b/scripts/utils/fix-index-exports.cjs old mode 100755 new mode 100644 diff --git a/scripts/utils/make-dist-package-json.cjs b/scripts/utils/make-dist-package-json.cjs old mode 100755 new mode 100644 diff --git a/scripts/utils/postprocess-files.cjs b/scripts/utils/postprocess-files.cjs old mode 100755 new mode 100644 diff --git a/src/_shims/MultipartBody.ts b/src/_shims/MultipartBody.ts old mode 100755 new mode 100644 diff --git a/src/_shims/README.md b/src/_shims/README.md old mode 100755 new mode 100644 diff --git a/src/_shims/auto/runtime-bun.ts b/src/_shims/auto/runtime-bun.ts old mode 100755 new mode 100644 diff --git a/src/_shims/auto/runtime-deno.ts b/src/_shims/auto/runtime-deno.ts old mode 100755 new mode 100644 diff --git a/src/_shims/auto/runtime-node.ts b/src/_shims/auto/runtime-node.ts old mode 100755 new mode 100644 diff --git a/src/_shims/auto/runtime.ts b/src/_shims/auto/runtime.ts old mode 100755 new mode 100644 diff --git a/src/_shims/auto/types-deno.ts b/src/_shims/auto/types-deno.ts old mode 100755 new mode 100644 diff --git a/src/_shims/auto/types-node.ts b/src/_shims/auto/types-node.ts old mode 100755 new mode 100644 diff --git a/src/_shims/auto/types.d.ts b/src/_shims/auto/types.d.ts old mode 100755 new mode 100644 diff --git a/src/_shims/auto/types.js b/src/_shims/auto/types.js old mode 100755 new mode 100644 diff --git a/src/_shims/auto/types.mjs b/src/_shims/auto/types.mjs old mode 100755 new mode 100644 diff --git a/src/_shims/bun-runtime.ts b/src/_shims/bun-runtime.ts old mode 100755 new mode 100644 diff --git a/src/_shims/index-deno.ts b/src/_shims/index-deno.ts old mode 100755 new mode 100644 diff --git a/src/_shims/index.d.ts b/src/_shims/index.d.ts old mode 100755 new mode 100644 diff --git a/src/_shims/index.js b/src/_shims/index.js old mode 100755 new mode 100644 diff --git a/src/_shims/index.mjs b/src/_shims/index.mjs old mode 100755 new mode 100644 diff --git a/src/_shims/manual-types.d.ts b/src/_shims/manual-types.d.ts old mode 100755 new mode 100644 diff --git a/src/_shims/manual-types.js b/src/_shims/manual-types.js old mode 100755 new mode 100644 diff --git a/src/_shims/manual-types.mjs b/src/_shims/manual-types.mjs old mode 100755 new mode 100644 diff --git a/src/_shims/node-runtime.ts b/src/_shims/node-runtime.ts old mode 100755 new mode 100644 diff --git a/src/_shims/node-types.d.ts b/src/_shims/node-types.d.ts old mode 100755 new mode 100644 diff --git a/src/_shims/node-types.js b/src/_shims/node-types.js old mode 100755 new mode 100644 diff --git a/src/_shims/node-types.mjs b/src/_shims/node-types.mjs old mode 100755 new mode 100644 diff --git a/src/_shims/registry.ts b/src/_shims/registry.ts old mode 100755 new mode 100644 diff --git a/src/_shims/web-runtime.ts b/src/_shims/web-runtime.ts old mode 100755 new mode 100644 diff --git a/src/_shims/web-types.d.ts b/src/_shims/web-types.d.ts old mode 100755 new mode 100644 diff --git a/src/_shims/web-types.js b/src/_shims/web-types.js old mode 100755 new mode 100644 diff --git a/src/_shims/web-types.mjs b/src/_shims/web-types.mjs old mode 100755 new mode 100644 diff --git a/src/core.ts b/src/core.ts old mode 100755 new mode 100644 index 266498c..99e8d9c --- a/src/core.ts +++ b/src/core.ts @@ -978,6 +978,11 @@ const validatePositiveInteger = (name: string, n: unknown): number => { export const castToError = (err: any): Error => { if (err instanceof Error) return err; + if (typeof err === 'object' && err !== null) { + try { + return new Error(JSON.stringify(err)); + } catch {} + } return new Error(err); }; diff --git a/src/error.ts b/src/error.ts old mode 100755 new mode 100644 index 1ab40d7..fc81972 --- a/src/error.ts +++ b/src/error.ts @@ -49,7 +49,7 @@ export class APIError extends PromptFoundryError { headers: Headers | undefined, ) { if (!status) { - return new APIConnectionError({ cause: castToError(errorResponse) }); + return new APIConnectionError({ message, cause: castToError(errorResponse) }); } const error = errorResponse as Record; @@ -101,7 +101,7 @@ export class APIUserAbortError extends APIError { export class APIConnectionError extends APIError { override readonly status: undefined = undefined; - constructor({ message, cause }: { message?: string; cause?: Error | undefined }) { + constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) { super(undefined, undefined, message || 'Connection error.', undefined); // in some environments the 'cause' property is already declared // @ts-ignore diff --git a/src/index.ts b/src/index.ts old mode 100755 new mode 100644 index 450e5c3..f15b7d2 --- a/src/index.ts +++ b/src/index.ts @@ -194,10 +194,10 @@ export namespace PromptFoundry { export import CompletionCreateParams = API.CompletionCreateParams; export import Prompts = API.Prompts; - export import Parameters = API.Parameters; export import PromptConfiguration = API.PromptConfiguration; export import PromptListResponse = API.PromptListResponse; export import PromptDeleteResponse = API.PromptDeleteResponse; + export import PromptGetParametersResponse = API.PromptGetParametersResponse; export import PromptCreateParams = API.PromptCreateParams; export import PromptUpdateParams = API.PromptUpdateParams; export import PromptGetParametersParams = API.PromptGetParametersParams; diff --git a/src/lib/.keep b/src/lib/.keep old mode 100755 new mode 100644 diff --git a/src/resource.ts b/src/resource.ts old mode 100755 new mode 100644 diff --git a/src/resources/completion.ts b/src/resources/completion.ts old mode 100755 new mode 100644 diff --git a/src/resources/evaluation-assertions.ts b/src/resources/evaluation-assertions.ts old mode 100755 new mode 100644 diff --git a/src/resources/evaluations.ts b/src/resources/evaluations.ts old mode 100755 new mode 100644 diff --git a/src/resources/index.ts b/src/resources/index.ts old mode 100755 new mode 100644 index e2f5def..1d67965 --- a/src/resources/index.ts +++ b/src/resources/index.ts @@ -19,10 +19,10 @@ export { EvaluationAssertions, } from './evaluation-assertions'; export { - Parameters, PromptConfiguration, PromptListResponse, PromptDeleteResponse, + PromptGetParametersResponse, PromptCreateParams, PromptUpdateParams, PromptGetParametersParams, diff --git a/src/resources/prompts.ts b/src/resources/prompts.ts old mode 100755 new mode 100644 index 14f1ce1..b93a556 --- a/src/resources/prompts.ts +++ b/src/resources/prompts.ts @@ -56,13 +56,13 @@ export class Prompts extends APIResource { id: string, body?: PromptGetParametersParams, options?: Core.RequestOptions, - ): Core.APIPromise; - getParameters(id: string, options?: Core.RequestOptions): Core.APIPromise; + ): Core.APIPromise; + getParameters(id: string, options?: Core.RequestOptions): Core.APIPromise; getParameters( id: string, body: PromptGetParametersParams | Core.RequestOptions = {}, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.APIPromise { if (isRequestOptions(body)) { return this.getParameters(id, {}, body); } @@ -70,18 +70,207 @@ export class Prompts extends APIResource { } } -export type Parameters = Parameters.AnthropicModelParameters | Parameters.OpenAIModelParameters; +export interface PromptConfiguration { + /** + * Example: "PROMPT_1" + */ + id: string; + + /** + * The configured messages WITHOUT variables replaced. + */ + messages: Array; + + /** + * Example: "Check the weather" + */ + name: string; + + parameters: PromptConfiguration.Parameters; + + tools: Array; +} + +export namespace PromptConfiguration { + export interface Message { + content: Array< + | Message.TextContentBlock + | Message.ImageBase64ContentBlock + | Message.ToolCallContentBlock + | Message.ToolResultContentBlock + >; + + role: 'assistant' | 'system' | 'tool' | 'user'; + } + + export namespace Message { + export interface TextContentBlock { + text: string; + + type: 'TEXT'; + } + + export interface ImageBase64ContentBlock { + imageBase64: string; + + mediaType: string; + + type: 'IMAGE_BASE64'; + } + + export interface ToolCallContentBlock { + toolCall: ToolCallContentBlock.ToolCall; + + type: 'TOOL_CALL'; + } + + export namespace ToolCallContentBlock { + export interface ToolCall { + function: ToolCall.Function; + + /** + * TOOL_CALL_1 + */ + toolCallId: string; + + /** + * The type of the tool. Currently, only `function` is supported. + */ + type: 'function'; + } + + export namespace ToolCall { + export interface Function { + /** + * The arguments to call the function with, as generated by the model in JSON + * format. Note that the model does not always generate valid JSON, and may + * hallucinate parameters not defined by your function schema. Validate the + * arguments in your code before calling your function. + */ + arguments: string; + + /** + * The name of the function to call. + */ + name: string; + } + } + } + + export interface ToolResultContentBlock { + result: string; + + toolCallId: string; + + type: 'TOOL_RESULT'; + } + } + + export interface Parameters { + /** + * Example: 0 + */ + frequencyPenalty: number; + + /** + * Example: 100 + */ + maxTokens: number | null; + + /** + * The name of the model for the provider. + */ + name: string; + + parallelToolCalls: boolean; + + /** + * Example: 0 + */ + presencePenalty: number; + + /** + * The LLM model provider. + */ + provider: 'ANTHROPIC' | 'OPENAI'; + + /** + * Example: PromptResponseFormat.TEXT + */ + responseFormat: 'JSON' | 'TEXT'; + + /** + * Example: 97946543 + */ + seed: number | null; + + stream: boolean; + + /** + * Example: 1 + */ + temperature: number; + + toolChoice: string | null; + + /** + * Example: 50 + */ + topK: number | null; -export namespace Parameters { - export interface AnthropicModelParameters { + /** + * Example: 1 + */ + topP: number; + } + + export interface Tool { + /** + * The initial messages to be included with your call to the LLM API. + */ + id: string; + + /** + * A description of what the tool does, used by the model to choose when and how to + * call the tool. + */ + description: string; + + /** + * The name of the tool to be called. Must be a-z, A-Z, 0-9, or contain underscores + * and dashes, with a maximum length of 64. + */ name: string; - parameters: AnthropicModelParameters.Parameters; + /** + * The parameters the functions accepts, described as a JSON Schema object. This + * schema is designed to match the TypeScript Record, allowing for + * any properties with values of any type. + */ + parameters: Record; + } +} + +export type PromptListResponse = Array; + +export interface PromptDeleteResponse { + success?: boolean; +} + +export type PromptGetParametersResponse = + | PromptGetParametersResponse.AnthropicModelNonStreamingParameters + | PromptGetParametersResponse.OpenAIModelNonStreamingParameters; + +export namespace PromptGetParametersResponse { + export interface AnthropicModelNonStreamingParameters { + name: string; + + parameters: AnthropicModelNonStreamingParameters.Parameters; provider: 'anthropic'; } - export namespace AnthropicModelParameters { + export namespace AnthropicModelNonStreamingParameters { export interface Parameters { max_tokens: number; @@ -94,12 +283,12 @@ export namespace Parameters { | 'claude-3-sonnet-20240229' | 'claude-3-haiku-20240307'; + stream: false; + metadata?: Parameters.Metadata; stop_sequences?: Array; - stream?: boolean; - system?: string; temperature?: number; @@ -237,15 +426,15 @@ export namespace Parameters { } } - export interface OpenAIModelParameters { + export interface OpenAIModelNonStreamingParameters { name: string; - parameters: OpenAIModelParameters.Parameters; + parameters: OpenAIModelNonStreamingParameters.Parameters; provider: 'openai'; } - export namespace OpenAIModelParameters { + export namespace OpenAIModelNonStreamingParameters { export interface Parameters { messages: Array< | Parameters.OpenAIChatCompletionRequestSystemMessage @@ -257,6 +446,13 @@ export namespace Parameters { model: string; + response_format: + | Parameters.OpenAIResponseFormatText + | Parameters.OpenAIResponseFormatJsonObject + | Parameters.OpenAIResponseFormatJsonSchema; + + stream: false; + frequency_penalty?: number | null; logit_bias?: Record | null; @@ -271,16 +467,10 @@ export namespace Parameters { presence_penalty?: number | null; - response_format?: Parameters.ResponseFormat; - seed?: number | null; stop?: string | Array; - stream?: boolean | null; - - stream_options?: Parameters.StreamOptions | null; - temperature?: number | null; tool_choice?: 'none' | 'auto' | 'required' | Parameters.OpenAIChatCompletionNamedToolChoice; @@ -390,12 +580,30 @@ export namespace Parameters { role: 'function'; } - export interface ResponseFormat { - type?: 'text' | 'json_object'; + export interface OpenAIResponseFormatText { + type: 'text'; + } + + export interface OpenAIResponseFormatJsonObject { + type: 'json_object'; } - export interface StreamOptions { - include_usage: boolean; + export interface OpenAIResponseFormatJsonSchema { + json_schema: OpenAIResponseFormatJsonSchema.JsonSchema; + + type: 'json_schema'; + } + + export namespace OpenAIResponseFormatJsonSchema { + export interface JsonSchema { + name: string; + + strict: boolean | null; + + description?: string; + + schema?: Record; + } } export interface OpenAIChatCompletionNamedToolChoice { @@ -429,193 +637,6 @@ export namespace Parameters { } } -export interface PromptConfiguration { - /** - * Example: "PROMPT_1" - */ - id: string; - - /** - * The configured messages WITHOUT variables replaced. - */ - messages: Array; - - /** - * Example: "Check the weather" - */ - name: string; - - parameters: PromptConfiguration.Parameters; - - tools: Array; -} - -export namespace PromptConfiguration { - export interface Message { - content: Array< - | Message.TextContentBlock - | Message.ImageBase64ContentBlock - | Message.ToolCallContentBlock - | Message.ToolResultContentBlock - >; - - role: 'assistant' | 'system' | 'tool' | 'user'; - } - - export namespace Message { - export interface TextContentBlock { - text: string; - - type: 'TEXT'; - } - - export interface ImageBase64ContentBlock { - imageBase64: string; - - mediaType: string; - - type: 'IMAGE_BASE64'; - } - - export interface ToolCallContentBlock { - toolCall: ToolCallContentBlock.ToolCall; - - type: 'TOOL_CALL'; - } - - export namespace ToolCallContentBlock { - export interface ToolCall { - function: ToolCall.Function; - - /** - * TOOL_CALL_1 - */ - toolCallId: string; - - /** - * The type of the tool. Currently, only `function` is supported. - */ - type: 'function'; - } - - export namespace ToolCall { - export interface Function { - /** - * The arguments to call the function with, as generated by the model in JSON - * format. Note that the model does not always generate valid JSON, and may - * hallucinate parameters not defined by your function schema. Validate the - * arguments in your code before calling your function. - */ - arguments: string; - - /** - * The name of the function to call. - */ - name: string; - } - } - } - - export interface ToolResultContentBlock { - result: string; - - toolCallId: string; - - type: 'TOOL_RESULT'; - } - } - - export interface Parameters { - /** - * Example: 0 - */ - frequencyPenalty: number; - - /** - * Example: 100 - */ - maxTokens: number | null; - - /** - * The name of the model for the provider. - */ - name: string; - - parallelToolCalls: boolean; - - /** - * Example: 0 - */ - presencePenalty: number; - - /** - * The LLM model provider. - */ - provider: 'ANTHROPIC' | 'OPENAI'; - - /** - * Example: PromptResponseFormat.TEXT - */ - responseFormat: 'JSON' | 'TEXT'; - - /** - * Example: 97946543 - */ - seed: number | null; - - stream: boolean; - - /** - * Example: 1 - */ - temperature: number; - - toolChoice: string | null; - - /** - * Example: 50 - */ - topK: number | null; - - /** - * Example: 1 - */ - topP: number; - } - - export interface Tool { - /** - * The initial messages to be included with your call to the LLM API. - */ - id: string; - - /** - * A description of what the tool does, used by the model to choose when and how to - * call the tool. - */ - description: string; - - /** - * The name of the tool to be called. Must be a-z, A-Z, 0-9, or contain underscores - * and dashes, with a maximum length of 64. - */ - name: string; - - /** - * The parameters the functions accepts, described as a JSON Schema object. This - * schema is designed to match the TypeScript Record, allowing for - * any properties with values of any type. - */ - parameters: Record; - } -} - -export type PromptListResponse = Array; - -export interface PromptDeleteResponse { - success?: boolean; -} - export interface PromptCreateParams { messages: Array; @@ -1091,10 +1112,10 @@ export namespace PromptGetParametersParams { } export namespace Prompts { - export import Parameters = PromptsAPI.Parameters; export import PromptConfiguration = PromptsAPI.PromptConfiguration; export import PromptListResponse = PromptsAPI.PromptListResponse; export import PromptDeleteResponse = PromptsAPI.PromptDeleteResponse; + export import PromptGetParametersResponse = PromptsAPI.PromptGetParametersResponse; export import PromptCreateParams = PromptsAPI.PromptCreateParams; export import PromptUpdateParams = PromptsAPI.PromptUpdateParams; export import PromptGetParametersParams = PromptsAPI.PromptGetParametersParams; diff --git a/src/resources/tools.ts b/src/resources/tools.ts old mode 100755 new mode 100644 diff --git a/src/shims/node.ts b/src/shims/node.ts old mode 100755 new mode 100644 diff --git a/src/shims/web.ts b/src/shims/web.ts old mode 100755 new mode 100644 diff --git a/src/uploads.ts b/src/uploads.ts old mode 100755 new mode 100644 index 081827c..8fd2154 --- a/src/uploads.ts +++ b/src/uploads.ts @@ -107,21 +107,28 @@ export async function toFile( // If it's a promise, resolve it. value = await value; - // Use the file's options if there isn't one provided - options ??= isFileLike(value) ? { lastModified: value.lastModified, type: value.type } : {}; + // If we've been given a `File` we don't need to do anything + if (isFileLike(value)) { + return value; + } if (isResponseLike(value)) { const blob = await value.blob(); name ||= new URL(value.url).pathname.split(/[\\/]/).pop() ?? 'unknown_file'; - return new File([blob as any], name, options); + // we need to convert the `Blob` into an array buffer because the `Blob` class + // that `node-fetch` defines is incompatible with the web standard which results + // in `new File` interpreting it as a string instead of binary data. + const data = isBlobLike(blob) ? [(await blob.arrayBuffer()) as any] : [blob]; + + return new File(data, name, options); } const bits = await getBytes(value); name ||= getName(value) ?? 'unknown_file'; - if (!options.type) { + if (!options?.type) { const type = (bits[0] as any)?.type; if (typeof type === 'string') { options = { ...options, type }; diff --git a/src/version.ts b/src/version.ts old mode 100755 new mode 100644 index 2f0d0ca..0158408 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = '1.18.0'; // x-release-please-version +export const VERSION = '1.19.0'; // x-release-please-version diff --git a/tests/api-resources/completion.test.ts b/tests/api-resources/completion.test.ts old mode 100755 new mode 100644 diff --git a/tests/api-resources/evaluation-assertions.test.ts b/tests/api-resources/evaluation-assertions.test.ts old mode 100755 new mode 100644 diff --git a/tests/api-resources/evaluations.test.ts b/tests/api-resources/evaluations.test.ts old mode 100755 new mode 100644 diff --git a/tests/api-resources/prompts.test.ts b/tests/api-resources/prompts.test.ts old mode 100755 new mode 100644 diff --git a/tests/api-resources/tools.test.ts b/tests/api-resources/tools.test.ts old mode 100755 new mode 100644 diff --git a/tests/form.test.ts b/tests/form.test.ts old mode 100755 new mode 100644 diff --git a/tests/index.test.ts b/tests/index.test.ts old mode 100755 new mode 100644 diff --git a/tests/responses.test.ts b/tests/responses.test.ts old mode 100755 new mode 100644 diff --git a/tests/stringifyQuery.test.ts b/tests/stringifyQuery.test.ts old mode 100755 new mode 100644 diff --git a/tests/uploads.test.ts b/tests/uploads.test.ts old mode 100755 new mode 100644 index a3d1e4e..bc09a5c --- a/tests/uploads.test.ts +++ b/tests/uploads.test.ts @@ -54,4 +54,12 @@ describe('toFile', () => { const file = await toFile(input); expect(file.name).toEqual('uploads.test.ts'); }); + + it('does not copy File objects', async () => { + const input = new File(['foo'], 'input.jsonl', { type: 'jsonl' }); + const file = await toFile(input); + expect(file).toBe(input); + expect(file.name).toEqual('input.jsonl'); + expect(file.type).toBe('jsonl'); + }); }); diff --git a/tsc-multi.json b/tsc-multi.json old mode 100755 new mode 100644 diff --git a/tsconfig.build.json b/tsconfig.build.json old mode 100755 new mode 100644 diff --git a/tsconfig.deno.json b/tsconfig.deno.json old mode 100755 new mode 100644 diff --git a/tsconfig.dist-src.json b/tsconfig.dist-src.json old mode 100755 new mode 100644 diff --git a/tsconfig.json b/tsconfig.json old mode 100755 new mode 100644