@arizeai/phoenix-client 1.0.1 → 1.0.2
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.
- package/README.md +2 -0
- package/dist/esm/__generated__/api/v1.d.ts +90 -0
- package/dist/esm/__generated__/api/v1.d.ts.map +1 -1
- package/dist/esm/client.d.ts +24 -6
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +21 -3
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/experiments/runExperiment.d.ts +6 -0
- package/dist/esm/experiments/runExperiment.d.ts.map +1 -1
- package/dist/esm/experiments/runExperiment.js +3 -3
- package/dist/esm/experiments/runExperiment.js.map +1 -1
- package/dist/esm/prompts/constants.d.ts +1 -1
- package/dist/esm/prompts/constants.js +1 -1
- package/dist/esm/prompts/createPrompt.d.ts +20 -5
- package/dist/esm/prompts/createPrompt.d.ts.map +1 -1
- package/dist/esm/prompts/createPrompt.js +12 -3
- package/dist/esm/prompts/createPrompt.js.map +1 -1
- package/dist/esm/prompts/getPrompt.d.ts +4 -1
- package/dist/esm/prompts/getPrompt.d.ts.map +1 -1
- package/dist/esm/prompts/getPrompt.js +4 -1
- package/dist/esm/prompts/getPrompt.js.map +1 -1
- package/dist/esm/prompts/sdks/toAI.d.ts.map +1 -1
- package/dist/esm/prompts/sdks/toAnthropic.d.ts.map +1 -1
- package/dist/esm/prompts/sdks/toOpenAI.d.ts.map +1 -1
- package/dist/esm/prompts/sdks/toSDK.d.ts +13 -2
- package/dist/esm/prompts/sdks/toSDK.d.ts.map +1 -1
- package/dist/esm/prompts/sdks/toSDK.js +12 -1
- package/dist/esm/prompts/sdks/toSDK.js.map +1 -1
- package/dist/esm/schemas/llm/converters.d.ts.map +1 -1
- package/dist/esm/schemas/llm/phoenixPrompt/messagePartSchemas.d.ts.map +1 -1
- package/dist/esm/schemas/llm/utils.d.ts.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/utils/formatPromptMessages.d.ts.map +1 -1
- package/dist/esm/utils/{getDatasetLike.d.ts → getDatasetBySelector.d.ts} +6 -3
- package/dist/esm/utils/getDatasetBySelector.d.ts.map +1 -0
- package/dist/esm/utils/{getDatasetLike.js → getDatasetBySelector.js} +3 -3
- package/dist/esm/utils/getDatasetBySelector.js.map +1 -0
- package/dist/esm/utils/{getPromptVersionLike.d.ts → getPromptBySelector.d.ts} +7 -1
- package/dist/esm/utils/getPromptBySelector.d.ts.map +1 -0
- package/dist/esm/utils/{getPromptVersionLike.js → getPromptBySelector.js} +4 -1
- package/dist/esm/utils/getPromptBySelector.js.map +1 -0
- package/dist/esm/utils/schemaMatches.d.ts.map +1 -1
- package/dist/src/__generated__/api/v1.d.ts +90 -0
- package/dist/src/__generated__/api/v1.d.ts.map +1 -1
- package/dist/src/client.d.ts +24 -6
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +21 -3
- package/dist/src/client.js.map +1 -1
- package/dist/src/experiments/runExperiment.d.ts +6 -0
- package/dist/src/experiments/runExperiment.d.ts.map +1 -1
- package/dist/src/experiments/runExperiment.js +3 -3
- package/dist/src/experiments/runExperiment.js.map +1 -1
- package/dist/src/prompts/constants.d.ts +1 -1
- package/dist/src/prompts/constants.js +1 -1
- package/dist/src/prompts/createPrompt.d.ts +20 -5
- package/dist/src/prompts/createPrompt.d.ts.map +1 -1
- package/dist/src/prompts/createPrompt.js +12 -3
- package/dist/src/prompts/createPrompt.js.map +1 -1
- package/dist/src/prompts/getPrompt.d.ts +4 -1
- package/dist/src/prompts/getPrompt.d.ts.map +1 -1
- package/dist/src/prompts/getPrompt.js +5 -2
- package/dist/src/prompts/getPrompt.js.map +1 -1
- package/dist/src/prompts/sdks/toAI.d.ts.map +1 -1
- package/dist/src/prompts/sdks/toAnthropic.d.ts.map +1 -1
- package/dist/src/prompts/sdks/toOpenAI.d.ts.map +1 -1
- package/dist/src/prompts/sdks/toSDK.d.ts +13 -2
- package/dist/src/prompts/sdks/toSDK.d.ts.map +1 -1
- package/dist/src/prompts/sdks/toSDK.js +12 -1
- package/dist/src/prompts/sdks/toSDK.js.map +1 -1
- package/dist/src/schemas/llm/converters.d.ts.map +1 -1
- package/dist/src/schemas/llm/phoenixPrompt/messagePartSchemas.d.ts.map +1 -1
- package/dist/src/schemas/llm/utils.d.ts.map +1 -1
- package/dist/src/utils/formatPromptMessages.d.ts.map +1 -1
- package/dist/src/utils/{getDatasetLike.d.ts → getDatasetBySelector.d.ts} +6 -3
- package/dist/src/utils/getDatasetBySelector.d.ts.map +1 -0
- package/dist/src/utils/{getDatasetLike.js → getDatasetBySelector.js} +4 -4
- package/dist/src/utils/getDatasetBySelector.js.map +1 -0
- package/dist/src/utils/{getPromptVersionLike.d.ts → getPromptBySelector.d.ts} +7 -1
- package/dist/src/utils/getPromptBySelector.d.ts.map +1 -0
- package/dist/src/utils/{getPromptVersionLike.js → getPromptBySelector.js} +4 -1
- package/dist/src/utils/getPromptBySelector.js.map +1 -0
- package/dist/src/utils/schemaMatches.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -12
- package/src/__generated__/api/v1.ts +90 -0
- package/src/client.ts +24 -6
- package/src/experiments/runExperiment.ts +9 -3
- package/src/prompts/constants.ts +1 -1
- package/src/prompts/createPrompt.ts +20 -5
- package/src/prompts/getPrompt.ts +5 -2
- package/src/prompts/sdks/toSDK.ts +12 -1
- package/src/utils/{getDatasetLike.ts → getDatasetBySelector.ts} +5 -2
- package/src/utils/{getPromptVersionLike.ts → getPromptBySelector.ts} +6 -0
- package/dist/esm/utils/getDatasetLike.d.ts.map +0 -1
- package/dist/esm/utils/getDatasetLike.js.map +0 -1
- package/dist/esm/utils/getPromptVersionLike.d.ts.map +0 -1
- package/dist/esm/utils/getPromptVersionLike.js.map +0 -1
- package/dist/src/utils/getDatasetLike.d.ts.map +0 -1
- package/dist/src/utils/getDatasetLike.js.map +0 -1
- package/dist/src/utils/getPromptVersionLike.d.ts.map +0 -1
- package/dist/src/utils/getPromptVersionLike.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arizeai/phoenix-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "A client for the Phoenix API",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -36,28 +36,29 @@
|
|
|
36
36
|
"author": "",
|
|
37
37
|
"license": "ELv2",
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@ai-sdk/openai": "^1.1.
|
|
39
|
+
"@ai-sdk/openai": "^1.1.15",
|
|
40
40
|
"@anthropic-ai/sdk": "^0.35.0",
|
|
41
|
-
"@types/node": "^20.
|
|
41
|
+
"@types/node": "^20.17.22",
|
|
42
42
|
"ai": "^4.1.24",
|
|
43
43
|
"openai": "^4.77.0",
|
|
44
|
-
"openapi-typescript": "^7.
|
|
45
|
-
"tsx": "^4.19.
|
|
46
|
-
"
|
|
44
|
+
"openapi-typescript": "^7.6.1",
|
|
45
|
+
"tsx": "^4.19.3",
|
|
46
|
+
"typedoc": "^0.27.9",
|
|
47
|
+
"vitest": "^2.1.9"
|
|
47
48
|
},
|
|
48
49
|
"dependencies": {
|
|
49
|
-
"openapi-fetch": "^0.12.
|
|
50
|
+
"openapi-fetch": "^0.12.5",
|
|
50
51
|
"tiny-invariant": "^1.3.3",
|
|
51
|
-
"zod": "^3.24.
|
|
52
|
-
"zod-to-json-schema": "^3.24.
|
|
52
|
+
"zod": "^3.24.2",
|
|
53
|
+
"zod-to-json-schema": "^3.24.3"
|
|
53
54
|
},
|
|
54
55
|
"engines": {
|
|
55
56
|
"node": ">=18"
|
|
56
57
|
},
|
|
57
58
|
"optionalDependencies": {
|
|
58
59
|
"@anthropic-ai/sdk": "^0.35.0",
|
|
59
|
-
"ai": "^4.1.
|
|
60
|
-
"openai": "^4.
|
|
60
|
+
"ai": "^4.1.47",
|
|
61
|
+
"openai": "^4.86.1"
|
|
61
62
|
},
|
|
62
63
|
"scripts": {
|
|
63
64
|
"clean": "rimraf dist",
|
|
@@ -66,6 +67,8 @@
|
|
|
66
67
|
"build": "tsc --build tsconfig.json tsconfig.esm.json && tsc-alias -p tsconfig.esm.json",
|
|
67
68
|
"postbuild": "echo '{\"type\": \"module\"}' > ./dist/esm/package.json && rimraf dist/test dist/examples",
|
|
68
69
|
"type:check": "tsc --noEmit",
|
|
69
|
-
"test": "vitest --typecheck"
|
|
70
|
+
"test": "vitest --typecheck",
|
|
71
|
+
"docs": "typedoc",
|
|
72
|
+
"docs:preview": "pnpx http-server ./docs -p 8080 -o"
|
|
70
73
|
}
|
|
71
74
|
}
|
|
@@ -176,6 +176,23 @@ export interface paths {
|
|
|
176
176
|
patch?: never;
|
|
177
177
|
trace?: never;
|
|
178
178
|
};
|
|
179
|
+
"/v1/experiments/{experiment_id}/json": {
|
|
180
|
+
parameters: {
|
|
181
|
+
query?: never;
|
|
182
|
+
header?: never;
|
|
183
|
+
path?: never;
|
|
184
|
+
cookie?: never;
|
|
185
|
+
};
|
|
186
|
+
/** Download experiment runs as a JSON file */
|
|
187
|
+
get: operations["getExperimentJSON"];
|
|
188
|
+
put?: never;
|
|
189
|
+
post?: never;
|
|
190
|
+
delete?: never;
|
|
191
|
+
options?: never;
|
|
192
|
+
head?: never;
|
|
193
|
+
patch?: never;
|
|
194
|
+
trace?: never;
|
|
195
|
+
};
|
|
179
196
|
"/v1/span_annotations": {
|
|
180
197
|
parameters: {
|
|
181
198
|
query?: never;
|
|
@@ -578,6 +595,26 @@ export interface components {
|
|
|
578
595
|
top_p?: number;
|
|
579
596
|
/** Stop Sequences */
|
|
580
597
|
stop_sequences?: string[];
|
|
598
|
+
/** Thinking */
|
|
599
|
+
thinking?: components["schemas"]["PromptAnthropicThinkingConfigDisabled"] | components["schemas"]["PromptAnthropicThinkingConfigEnabled"];
|
|
600
|
+
};
|
|
601
|
+
/** PromptAnthropicThinkingConfigDisabled */
|
|
602
|
+
PromptAnthropicThinkingConfigDisabled: {
|
|
603
|
+
/**
|
|
604
|
+
* @description discriminator enum property added by openapi-typescript
|
|
605
|
+
* @enum {string}
|
|
606
|
+
*/
|
|
607
|
+
type: "disabled";
|
|
608
|
+
};
|
|
609
|
+
/** PromptAnthropicThinkingConfigEnabled */
|
|
610
|
+
PromptAnthropicThinkingConfigEnabled: {
|
|
611
|
+
/**
|
|
612
|
+
* @description discriminator enum property added by openapi-typescript
|
|
613
|
+
* @enum {string}
|
|
614
|
+
*/
|
|
615
|
+
type: "enabled";
|
|
616
|
+
/** Budget Tokens */
|
|
617
|
+
budget_tokens: number;
|
|
581
618
|
};
|
|
582
619
|
/** PromptAzureOpenAIInvocationParameters */
|
|
583
620
|
PromptAzureOpenAIInvocationParameters: {
|
|
@@ -594,6 +631,8 @@ export interface components {
|
|
|
594
631
|
temperature?: number;
|
|
595
632
|
/** Max Tokens */
|
|
596
633
|
max_tokens?: number;
|
|
634
|
+
/** Max Completion Tokens */
|
|
635
|
+
max_completion_tokens?: number;
|
|
597
636
|
/** Frequency Penalty */
|
|
598
637
|
frequency_penalty?: number;
|
|
599
638
|
/** Presence Penalty */
|
|
@@ -677,6 +716,8 @@ export interface components {
|
|
|
677
716
|
temperature?: number;
|
|
678
717
|
/** Max Tokens */
|
|
679
718
|
max_tokens?: number;
|
|
719
|
+
/** Max Completion Tokens */
|
|
720
|
+
max_completion_tokens?: number;
|
|
680
721
|
/** Frequency Penalty */
|
|
681
722
|
frequency_penalty?: number;
|
|
682
723
|
/** Presence Penalty */
|
|
@@ -1541,6 +1582,55 @@ export interface operations {
|
|
|
1541
1582
|
};
|
|
1542
1583
|
};
|
|
1543
1584
|
};
|
|
1585
|
+
getExperimentJSON: {
|
|
1586
|
+
parameters: {
|
|
1587
|
+
query?: never;
|
|
1588
|
+
header?: never;
|
|
1589
|
+
path: {
|
|
1590
|
+
experiment_id: string;
|
|
1591
|
+
};
|
|
1592
|
+
cookie?: never;
|
|
1593
|
+
};
|
|
1594
|
+
requestBody?: never;
|
|
1595
|
+
responses: {
|
|
1596
|
+
/** @description Successful Response */
|
|
1597
|
+
200: {
|
|
1598
|
+
headers: {
|
|
1599
|
+
[name: string]: unknown;
|
|
1600
|
+
};
|
|
1601
|
+
content: {
|
|
1602
|
+
"text/plain": string;
|
|
1603
|
+
};
|
|
1604
|
+
};
|
|
1605
|
+
/** @description Forbidden */
|
|
1606
|
+
403: {
|
|
1607
|
+
headers: {
|
|
1608
|
+
[name: string]: unknown;
|
|
1609
|
+
};
|
|
1610
|
+
content: {
|
|
1611
|
+
"text/plain": string;
|
|
1612
|
+
};
|
|
1613
|
+
};
|
|
1614
|
+
/** @description Experiment not found */
|
|
1615
|
+
404: {
|
|
1616
|
+
headers: {
|
|
1617
|
+
[name: string]: unknown;
|
|
1618
|
+
};
|
|
1619
|
+
content: {
|
|
1620
|
+
"text/plain": string;
|
|
1621
|
+
};
|
|
1622
|
+
};
|
|
1623
|
+
/** @description Validation Error */
|
|
1624
|
+
422: {
|
|
1625
|
+
headers: {
|
|
1626
|
+
[name: string]: unknown;
|
|
1627
|
+
};
|
|
1628
|
+
content: {
|
|
1629
|
+
"application/json": components["schemas"]["HTTPValidationError"];
|
|
1630
|
+
};
|
|
1631
|
+
};
|
|
1632
|
+
};
|
|
1633
|
+
};
|
|
1544
1634
|
annotateSpans: {
|
|
1545
1635
|
parameters: {
|
|
1546
1636
|
query?: {
|
package/src/client.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import createOpenApiClient, { ClientOptions } from "openapi-fetch";
|
|
1
|
+
import createOpenApiClient, { type ClientOptions } from "openapi-fetch";
|
|
2
2
|
import type {
|
|
3
3
|
paths as oapiPathsV1,
|
|
4
4
|
components as oapiComponentsV1,
|
|
@@ -14,7 +14,7 @@ type componentsV1 = oapiComponentsV1;
|
|
|
14
14
|
type operationsV1 = oapiOperationsV1;
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* Generated openapi types for the Phoenix client
|
|
17
|
+
* Generated openapi types for the Phoenix client, by API version.
|
|
18
18
|
*/
|
|
19
19
|
export type Types = {
|
|
20
20
|
V1: {
|
|
@@ -29,6 +29,9 @@ export type Types = {
|
|
|
29
29
|
* defaults < environment < explicit options
|
|
30
30
|
*
|
|
31
31
|
* Headers are simply replaced, not merged.
|
|
32
|
+
*
|
|
33
|
+
* You can call this function before instantiating the client if you need to retain access
|
|
34
|
+
* to the options that were passed in to the client.
|
|
32
35
|
*/
|
|
33
36
|
export const getMergedOptions = ({
|
|
34
37
|
options = {},
|
|
@@ -49,10 +52,25 @@ export const getMergedOptions = ({
|
|
|
49
52
|
/**
|
|
50
53
|
* Create a Phoenix client.
|
|
51
54
|
*
|
|
55
|
+
* The client is strongly typed and uses generated openapi types.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { createClient } from "@arize/phoenix-client";
|
|
60
|
+
*
|
|
61
|
+
* const client = createClient();
|
|
62
|
+
*
|
|
63
|
+
* const response = await client.GET("/v1/traces");
|
|
64
|
+
* // ^ path string is strongly typed, and completion works with autocomplete
|
|
65
|
+
* // path parameters, query parameters, and request body are also strongly typed based on the openapi spec,
|
|
66
|
+
* // the path, and the method.
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
52
69
|
* @param config - The configuration to use for the client.
|
|
53
|
-
* @param config.options - The options to use for
|
|
54
|
-
* @param config.getEnvironmentOptions - The function to use to get the environment options.
|
|
55
|
-
*
|
|
70
|
+
* @param config.options - The options to use for [openapi-fetch.createOpenApiClient](https://github.com/openapi-ts/openapi-typescript/tree/main/packages/openapi-fetch).
|
|
71
|
+
* @param config.getEnvironmentOptions - The function to use to get the environment options. By default, a function that
|
|
72
|
+
* returns `process.env` is used.
|
|
73
|
+
* @returns The Phoenix client as a strongly typed [openapi-fetch](https://github.com/openapi-ts/openapi-typescript/tree/main/packages/openapi-fetch) client.
|
|
56
74
|
*/
|
|
57
75
|
export const createClient = (
|
|
58
76
|
config: {
|
|
@@ -65,6 +83,6 @@ export const createClient = (
|
|
|
65
83
|
};
|
|
66
84
|
|
|
67
85
|
/**
|
|
68
|
-
*
|
|
86
|
+
* Resolved type of the Phoenix client
|
|
69
87
|
*/
|
|
70
88
|
export type PhoenixClient = ReturnType<typeof createClient>;
|
|
@@ -13,9 +13,15 @@ import { promisifyResult } from "../utils/promisifyResult";
|
|
|
13
13
|
import invariant from "tiny-invariant";
|
|
14
14
|
import { pluralize } from "../utils/pluralize";
|
|
15
15
|
import { ClientFn } from "../types/core";
|
|
16
|
-
import {
|
|
16
|
+
import { getDatasetBySelector } from "../utils/getDatasetBySelector";
|
|
17
17
|
import { type Logger } from "../types/logger";
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Parameters for running an experiment.
|
|
21
|
+
*
|
|
22
|
+
* @experimental This feature is not complete, and will change in the future.
|
|
23
|
+
* @deprecated This function will be un-marked as deprecated once the experimental feature flag is removed.
|
|
24
|
+
*/
|
|
19
25
|
export type RunExperimentParams = ClientFn & {
|
|
20
26
|
/**
|
|
21
27
|
* An optional name for the experiment.
|
|
@@ -70,7 +76,7 @@ export async function runExperiment({
|
|
|
70
76
|
record = true,
|
|
71
77
|
}: RunExperimentParams): Promise<RanExperiment> {
|
|
72
78
|
const client = _client ?? createClient();
|
|
73
|
-
const dataset = await
|
|
79
|
+
const dataset = await getDatasetBySelector({ dataset: _dataset, client });
|
|
74
80
|
invariant(dataset, `Dataset not found`);
|
|
75
81
|
invariant(dataset.examples.length > 0, `Dataset has no examples`);
|
|
76
82
|
const experimentName =
|
|
@@ -223,7 +229,7 @@ export async function evaluateExperiment({
|
|
|
223
229
|
logger: Logger;
|
|
224
230
|
}): Promise<RanExperiment> {
|
|
225
231
|
const client = _client ?? createClient();
|
|
226
|
-
const dataset = await
|
|
232
|
+
const dataset = await getDatasetBySelector({
|
|
227
233
|
dataset: experiment.datasetId,
|
|
228
234
|
client,
|
|
229
235
|
});
|
package/src/prompts/constants.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PromptModelProvider } from "../types/prompts";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* A mapping of
|
|
4
|
+
* A mapping of PromptModelProvider to a human-readable string
|
|
5
5
|
*/
|
|
6
6
|
export const PromptModelProviders: Record<PromptModelProvider, string> = {
|
|
7
7
|
OPENAI: "OpenAI",
|
|
@@ -13,11 +13,11 @@ import {
|
|
|
13
13
|
import { assertUnreachable } from "../utils/assertUnreachable";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* Parameters to
|
|
16
|
+
* Parameters to create a prompt
|
|
17
17
|
*/
|
|
18
18
|
export interface CreatePromptParams extends ClientFn, PromptData {
|
|
19
19
|
/**
|
|
20
|
-
* The name of the
|
|
20
|
+
* The name of the prompt
|
|
21
21
|
*/
|
|
22
22
|
name: string;
|
|
23
23
|
/**
|
|
@@ -31,8 +31,12 @@ export interface CreatePromptParams extends ClientFn, PromptData {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* Create a prompt and store it in Phoenix
|
|
35
|
-
*
|
|
34
|
+
* Create a prompt and store it in Phoenix.
|
|
35
|
+
*
|
|
36
|
+
* If a prompt with the same name exists, a new version of the prompt will be appended to the history.
|
|
37
|
+
*
|
|
38
|
+
* @param params - The parameters to create a prompt.
|
|
39
|
+
* @returns The created prompt version.
|
|
36
40
|
*/
|
|
37
41
|
export async function createPrompt({
|
|
38
42
|
client: _client,
|
|
@@ -54,7 +58,13 @@ export async function createPrompt({
|
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
interface PromptVersionInputBase {
|
|
61
|
+
/**
|
|
62
|
+
* The description of the prompt version.
|
|
63
|
+
*/
|
|
57
64
|
description?: string;
|
|
65
|
+
/**
|
|
66
|
+
* The name of the model to use for the prompt version.
|
|
67
|
+
*/
|
|
58
68
|
modelName: PromptVersionData["model_name"];
|
|
59
69
|
/**
|
|
60
70
|
* The template for the prompt version.
|
|
@@ -99,7 +109,12 @@ type PromptVersionInput =
|
|
|
99
109
|
| GooglePromptVersionInput;
|
|
100
110
|
|
|
101
111
|
/**
|
|
102
|
-
* A helper function to construct a prompt version declaratively
|
|
112
|
+
* A helper function to construct a prompt version declaratively.
|
|
113
|
+
*
|
|
114
|
+
* The output of this function can be used to create a prompt version in Phoenix.
|
|
115
|
+
*
|
|
116
|
+
* @param params - The parameters to create a prompt version.
|
|
117
|
+
* @returns Structured prompt version data, not yet persisted to Phoenix.
|
|
103
118
|
*/
|
|
104
119
|
export function promptVersion(params: PromptVersionInput): PromptVersionData {
|
|
105
120
|
const {
|
package/src/prompts/getPrompt.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createClient } from "../client";
|
|
2
2
|
import { ClientFn } from "../types/core";
|
|
3
3
|
import { PromptSelector, PromptVersion } from "../types/prompts";
|
|
4
|
-
import { getPromptBySelector } from "../utils/
|
|
4
|
+
import { getPromptBySelector } from "../utils/getPromptBySelector";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Parameters for
|
|
7
|
+
* Parameters for getting a prompt from Phoenix.
|
|
8
8
|
*/
|
|
9
9
|
export interface GetPromptParams extends ClientFn {
|
|
10
10
|
/**
|
|
@@ -15,6 +15,9 @@ export interface GetPromptParams extends ClientFn {
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Get a prompt from the Phoenix API.
|
|
18
|
+
*
|
|
19
|
+
* @param params - The parameters to get a prompt.
|
|
20
|
+
* @returns The prompt version, or null if it does not exist.
|
|
18
21
|
*/
|
|
19
22
|
export async function getPrompt({
|
|
20
23
|
client: _client,
|
|
@@ -64,12 +64,23 @@ type ToSDKParams<T extends SupportedSDK, V extends Variables = Variables> = {
|
|
|
64
64
|
/**
|
|
65
65
|
* Convert a Phoenix prompt to a specific SDK's parameters
|
|
66
66
|
*
|
|
67
|
-
* @example
|
|
67
|
+
* @example quickstart
|
|
68
68
|
* ```ts
|
|
69
|
+
* // Get a prompt from Phoenix, use it via openai sdk
|
|
69
70
|
* const prompt = await getPrompt({ prompt: { name: "my-prompt" } });
|
|
70
71
|
* const openaiParams = toSDK({ sdk: "openai", prompt });
|
|
71
72
|
* const response = await openai.chat.completions.create(openaiParams);
|
|
72
73
|
* ```
|
|
74
|
+
*
|
|
75
|
+
* @example type safety
|
|
76
|
+
* ```ts
|
|
77
|
+
* // Enforce variable types via Generic argument
|
|
78
|
+
* const prompt = await getPrompt({ prompt: { name: "my-prompt" } });
|
|
79
|
+
* const openaiParams = toSDK<"openai", { name: string }>({ sdk: "openai", prompt, variables: { name: "John" } });
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @param params - The parameters to convert a prompt to an SDK's parameters
|
|
83
|
+
* @returns The SDK's parameters
|
|
73
84
|
*/
|
|
74
85
|
export const toSDK = <T extends SupportedSDK, V extends Variables = Variables>({
|
|
75
86
|
sdk: _sdk,
|
|
@@ -8,6 +8,9 @@ import { Dataset } from "../types/datasets";
|
|
|
8
8
|
* Parameters for the getDatasetLike function
|
|
9
9
|
*/
|
|
10
10
|
export type GetDatasetLikeParams = {
|
|
11
|
+
/**
|
|
12
|
+
* The dataset to get. Can be in the form of a dataset id, an array of examples, or a dataset object.
|
|
13
|
+
*/
|
|
11
14
|
dataset: Dataset | string | Example[];
|
|
12
15
|
client: PhoenixClient;
|
|
13
16
|
};
|
|
@@ -19,10 +22,10 @@ export type GetDatasetLikeParams = {
|
|
|
19
22
|
* If the input is an array of examples, create a new dataset from the examples then return it.
|
|
20
23
|
* If the input is a dataset, return it as is.
|
|
21
24
|
*
|
|
22
|
-
* @param
|
|
25
|
+
* @param params - The parameters to get a dataset.
|
|
23
26
|
* @returns The dataset.
|
|
24
27
|
*/
|
|
25
|
-
export async function
|
|
28
|
+
export async function getDatasetBySelector({
|
|
26
29
|
dataset,
|
|
27
30
|
client,
|
|
28
31
|
}: GetDatasetLikeParams): Promise<Dataset | null> {
|
|
@@ -7,6 +7,9 @@ import { createClient } from "../client";
|
|
|
7
7
|
* Parameters for the getPromptBySelector function
|
|
8
8
|
*/
|
|
9
9
|
export type GetPromptBySelectorParams = ClientFn & {
|
|
10
|
+
/**
|
|
11
|
+
* The prompt to get. Can be in the form of a prompt id, a prompt version id, a prompt name, or a prompt name + tag.
|
|
12
|
+
*/
|
|
10
13
|
prompt: PromptSelector;
|
|
11
14
|
};
|
|
12
15
|
|
|
@@ -17,6 +20,9 @@ export type GetPromptBySelectorParams = ClientFn & {
|
|
|
17
20
|
* if the input is a prompt version id, fetch that prompt version.
|
|
18
21
|
* if the input is a prompt tag and name, fetch the prompt version that has that tag and name.
|
|
19
22
|
* if the input is a prompt name, fetch the latest prompt version from the client.
|
|
23
|
+
*
|
|
24
|
+
* @param params - The parameters to get a prompt.
|
|
25
|
+
* @returns The nearest prompt version that matches the selector, or null if it does not exist.
|
|
20
26
|
*/
|
|
21
27
|
export async function getPromptBySelector({
|
|
22
28
|
client: _client,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getDatasetLike.d.ts","sourceRoot":"","sources":["../../../src/utils/getDatasetLike.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,EAAE,CAAC;IACtC,MAAM,EAAE,aAAa,CAAC;CACvB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,cAAc,CAAC,EACnC,OAAO,EACP,MAAM,GACP,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAwBhD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get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AAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getPromptVersionLike.d.ts","sourceRoot":"","sources":["../../../src/utils/getPromptVersionLike.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,QAAQ,GAAG;IACjD,MAAM,EAAE,cAAc,CAAC;CACxB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CAAC,EACxC,MAAM,EAAE,OAAO,EACf,MAAM,GACP,EAAE,yBAAyB;;oBAkDmxsB,uDAAsB;;cAAkI,uDAAsB,yBAAwB,uDAAsB;mBAAoD,uDAAsB;qBAAoD,uDAAsB;2BAAqG,uDAAsB,uCAAsC,uDAAsB,4CAA2C,uDAAsB,0CAAyC,uDAAsB;YAAyD,uDAAsB;sBAAwF,uDAAsB;;UADlpuB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getPromptVersionLike.js","sourceRoot":"","sources":["../../../src/utils/getPromptVersionLike.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAGvC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AASzC;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,EACxC,MAAM,EAAE,OAAO,EACf,MAAM,GACoB;IAC1B,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,OAAO,IAAI,YAAY,EAAE,CAAC;QACzC,IAAI,UAAU,IAAI,MAAM,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAClD,CAAC;QACD,IAAI,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,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,sCAAsC;QACtC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getDatasetLike.d.ts","sourceRoot":"","sources":["../../../src/utils/getDatasetLike.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,EAAE,CAAC;IACtC,MAAM,EAAE,aAAa,CAAC;CACvB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,cAAc,CAAC,EACnC,OAAO,EACP,MAAM,GACP,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAwBhD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getDatasetLike.js","sourceRoot":"","sources":["../../../src/utils/getDatasetLike.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAwBA,wCA2BC;AAnDD,oEAAuC;AAcvC;;;;;;;;;GASG;AACH,SAAsB,cAAc;yDAAC,EACnC,OAAO,EACP,MAAM,GACe;QACrB,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,MAAM,eAAe,GAAG,MAAM,MAAM;iBACjC,GAAG,CAAC,mBAAmB,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;iBAC/D,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,WAAC,OAAA,MAAA,CAAC,CAAC,IAAI,0CAAE,IAA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