@arizeai/phoenix-client 6.5.3 → 6.5.5
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 +45 -0
- package/dist/esm/__generated__/api/v1.d.ts +244 -0
- package/dist/esm/__generated__/api/v1.d.ts.map +1 -1
- package/dist/esm/experiments/resumeEvaluation.d.ts.map +1 -1
- package/dist/esm/experiments/resumeEvaluation.js +179 -170
- package/dist/esm/experiments/resumeEvaluation.js.map +1 -1
- package/dist/esm/experiments/resumeExperiment.d.ts.map +1 -1
- package/dist/esm/experiments/resumeExperiment.js +201 -185
- package/dist/esm/experiments/resumeExperiment.js.map +1 -1
- package/dist/esm/experiments/runExperiment.d.ts.map +1 -1
- package/dist/esm/experiments/runExperiment.js +238 -207
- package/dist/esm/experiments/runExperiment.js.map +1 -1
- package/dist/esm/experiments/tracing.d.ts +10 -0
- package/dist/esm/experiments/tracing.d.ts.map +1 -0
- package/dist/esm/experiments/tracing.js +21 -0
- package/dist/esm/experiments/tracing.js.map +1 -0
- package/dist/esm/prompts/sdks/toSDK.d.ts +2 -2
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/utils/formatPromptMessages.d.ts.map +1 -1
- package/dist/esm/utils/getPromptBySelector.d.ts.map +1 -1
- package/dist/src/__generated__/api/v1.d.ts +244 -0
- package/dist/src/__generated__/api/v1.d.ts.map +1 -1
- package/dist/src/experiments/resumeEvaluation.d.ts.map +1 -1
- package/dist/src/experiments/resumeEvaluation.js +192 -183
- package/dist/src/experiments/resumeEvaluation.js.map +1 -1
- package/dist/src/experiments/resumeExperiment.d.ts.map +1 -1
- package/dist/src/experiments/resumeExperiment.js +214 -198
- package/dist/src/experiments/resumeExperiment.js.map +1 -1
- package/dist/src/experiments/runExperiment.d.ts.map +1 -1
- package/dist/src/experiments/runExperiment.js +228 -197
- package/dist/src/experiments/runExperiment.js.map +1 -1
- package/dist/src/experiments/tracing.d.ts +10 -0
- package/dist/src/experiments/tracing.d.ts.map +1 -0
- package/dist/src/experiments/tracing.js +24 -0
- package/dist/src/experiments/tracing.js.map +1 -0
- package/dist/src/utils/formatPromptMessages.d.ts.map +1 -1
- package/dist/src/utils/getPromptBySelector.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/docs/annotations.mdx +83 -0
- package/docs/datasets.mdx +77 -0
- package/docs/document-annotations.mdx +208 -0
- package/docs/experiments.mdx +271 -0
- package/docs/overview.mdx +176 -0
- package/docs/prompts.mdx +73 -0
- package/docs/session-annotations.mdx +158 -0
- package/docs/sessions.mdx +87 -0
- package/docs/span-annotations.mdx +283 -0
- package/docs/spans.mdx +76 -0
- package/docs/traces.mdx +63 -0
- package/package.json +11 -5
- package/src/__generated__/api/v1.ts +244 -0
- package/src/experiments/resumeEvaluation.ts +224 -206
- package/src/experiments/resumeExperiment.ts +237 -213
- package/src/experiments/runExperiment.ts +281 -243
- package/src/experiments/tracing.ts +30 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Overview"
|
|
3
|
+
description: "Typed TypeScript client for Phoenix platform APIs"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
`@arizeai/phoenix-client` is the typed TypeScript client for Phoenix platform APIs. It ships a small root REST client plus focused module entrypoints for prompts, datasets, experiments, spans, sessions, and traces.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @arizeai/phoenix-client
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Minimal Example
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { createClient } from "@arizeai/phoenix-client";
|
|
18
|
+
import { listDatasets } from "@arizeai/phoenix-client/datasets";
|
|
19
|
+
|
|
20
|
+
const client = createClient();
|
|
21
|
+
const datasets = await listDatasets({ client });
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Docs And Source In `node_modules`
|
|
25
|
+
|
|
26
|
+
After install, a coding agent can inspect the installed package directly:
|
|
27
|
+
|
|
28
|
+
```text
|
|
29
|
+
node_modules/@arizeai/phoenix-client/docs/
|
|
30
|
+
node_modules/@arizeai/phoenix-client/src/
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
That gives the agent version-matched docs plus the exact implementation and generated API types that shipped with your project.
|
|
34
|
+
|
|
35
|
+
## Module Map
|
|
36
|
+
|
|
37
|
+
| Import | Purpose |
|
|
38
|
+
|--------|---------|
|
|
39
|
+
| `@arizeai/phoenix-client` | `createClient`, generated OpenAPI types, config helpers |
|
|
40
|
+
| `@arizeai/phoenix-client/prompts` | Prompt CRUD plus `toSDK` conversion |
|
|
41
|
+
| `@arizeai/phoenix-client/datasets` | Dataset creation and retrieval |
|
|
42
|
+
| `@arizeai/phoenix-client/experiments` | Experiment execution and lifecycle |
|
|
43
|
+
| `@arizeai/phoenix-client/spans` | Span search, notes, and span/document annotations |
|
|
44
|
+
| `@arizeai/phoenix-client/sessions` | Session listing, retrieval, and session annotations |
|
|
45
|
+
| `@arizeai/phoenix-client/traces` | Project trace retrieval |
|
|
46
|
+
|
|
47
|
+
## Configuration
|
|
48
|
+
|
|
49
|
+
`createClient()` resolves Phoenix client options in this order: library defaults, environment variables, then explicit options. In most applications, the normal setup is to set `PHOENIX_HOST` and `PHOENIX_API_KEY` in the environment and call `createClient()` with no overrides.
|
|
50
|
+
|
|
51
|
+
### Recommended Setup
|
|
52
|
+
|
|
53
|
+
Use the environment-driven path unless you have a specific reason to override client options in code.
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
export PHOENIX_HOST=http://localhost:6006
|
|
57
|
+
export PHOENIX_API_KEY=<your-api-key>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
If you're using Phoenix Cloud, `PHOENIX_HOST` may look like `https://app.phoenix.arize.com/s/my-space`.
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { createClient } from "@arizeai/phoenix-client";
|
|
64
|
+
|
|
65
|
+
const client = createClient();
|
|
66
|
+
|
|
67
|
+
const datasets = await client.GET("/v1/datasets");
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`PHOENIX_API_KEY` is converted into `Authorization: Bearer <key>` automatically. You do not need to build that header yourself unless you are explicitly overriding `headers`.
|
|
71
|
+
|
|
72
|
+
### Explicit Overrides
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { createClient } from "@arizeai/phoenix-client";
|
|
76
|
+
|
|
77
|
+
const client = createClient({
|
|
78
|
+
options: {
|
|
79
|
+
baseUrl: "https://phoenix.example.com",
|
|
80
|
+
headers: {
|
|
81
|
+
Authorization: `Bearer ${process.env.PHOENIX_API_KEY}`,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Use explicit options when you want configuration to live in code or when you need to override the environment for a specific client instance.
|
|
88
|
+
|
|
89
|
+
### createClient Parameters
|
|
90
|
+
|
|
91
|
+
| Field | Type | Description |
|
|
92
|
+
|--------|------|-------------|
|
|
93
|
+
| `options` | `Partial<ClientOptions>` | Explicit options passed to the underlying `openapi-fetch` client. |
|
|
94
|
+
| `getEnvironmentOptions` | `() => Partial<ClientOptions>` | Optional resolver for environment-derived options. The default implementation reads `process.env` when available. |
|
|
95
|
+
|
|
96
|
+
### Resolved Phoenix Options
|
|
97
|
+
|
|
98
|
+
These are the Phoenix-specific options this package resolves before creating the underlying OpenAPI client:
|
|
99
|
+
|
|
100
|
+
| Option | Type | Description |
|
|
101
|
+
|--------|------|-------------|
|
|
102
|
+
| `baseUrl` | `string` | Base Phoenix URL. Defaults to `http://localhost:6006`, or `PHOENIX_HOST` when that environment variable is set. |
|
|
103
|
+
| `headers` | `ClientOptions["headers"]` | Headers sent on every request. `PHOENIX_API_KEY` populates `Authorization` automatically. Explicit `headers` replace environment-derived headers. |
|
|
104
|
+
|
|
105
|
+
### Header Override Rule
|
|
106
|
+
|
|
107
|
+
If you pass `options.headers`, they replace the environment-derived header object rather than deep-merging with it. That means if you override `headers` and still want API key authentication, include `Authorization` yourself:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
const client = createClient({
|
|
111
|
+
options: {
|
|
112
|
+
headers: {
|
|
113
|
+
Authorization: `Bearer ${process.env.PHOENIX_API_KEY}`,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Environment Variables
|
|
120
|
+
|
|
121
|
+
| Variable | Maps to | Description |
|
|
122
|
+
|--------|---------|-------------|
|
|
123
|
+
| `PHOENIX_HOST` | `options.baseUrl` | Base Phoenix URL, for example `http://localhost:6006`. |
|
|
124
|
+
| `PHOENIX_API_KEY` | `options.headers.Authorization` | Bearer token for authenticated environments. |
|
|
125
|
+
| `PHOENIX_CLIENT_HEADERS` | `options.headers` | Optional JSON-encoded object of additional headers to send on every request. Most setups do not need this. |
|
|
126
|
+
|
|
127
|
+
## API Client
|
|
128
|
+
|
|
129
|
+
`createClient()` returns an `openapi-fetch` client that is typed against Phoenix's generated OpenAPI schema. Use this layer when you need an endpoint that does not yet have a high-level helper.
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import { createClient } from "@arizeai/phoenix-client";
|
|
133
|
+
|
|
134
|
+
const client = createClient();
|
|
135
|
+
|
|
136
|
+
const datasets = await client.GET("/v1/datasets");
|
|
137
|
+
|
|
138
|
+
const prompt = await client.GET("/v1/prompts/{prompt_identifier}/latest", {
|
|
139
|
+
params: {
|
|
140
|
+
path: {
|
|
141
|
+
prompt_identifier: "support-response",
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
The root export exposes generated API types: `pathsV1`, `componentsV1`, `operationsV1`, `Types`, and `PhoenixClient`.
|
|
148
|
+
|
|
149
|
+
Prefer this layer when:
|
|
150
|
+
|
|
151
|
+
- you need a newly added endpoint before a helper exists
|
|
152
|
+
- you want direct control over route, body, and query params
|
|
153
|
+
- you are building thin wrappers around Phoenix routes in your own codebase
|
|
154
|
+
|
|
155
|
+
## Where To Start
|
|
156
|
+
|
|
157
|
+
- [Prompts](./prompts), [Datasets](./datasets), [Experiments](./experiments) — higher-level workflows
|
|
158
|
+
- [Annotations](./annotations) — annotation concepts, then [Span](./span-annotations), [Document](./document-annotations), and [Session](./session-annotations) annotations for detailed usage
|
|
159
|
+
- [Spans](./spans), [Sessions](./sessions), [Traces](./traces) — retrieval and maintenance
|
|
160
|
+
|
|
161
|
+
<section className="hidden" data-agent-context="source-map" aria-label="Source map">
|
|
162
|
+
<h2>Source Map</h2>
|
|
163
|
+
<ul>
|
|
164
|
+
<li><code>src/client.ts</code></li>
|
|
165
|
+
<li><code>src/config.ts</code></li>
|
|
166
|
+
<li><code>src/__generated__/api/v1.ts</code></li>
|
|
167
|
+
<li><code>src/types/core.ts</code></li>
|
|
168
|
+
<li><code>src/prompts/</code></li>
|
|
169
|
+
<li><code>src/datasets/</code></li>
|
|
170
|
+
<li><code>src/experiments/</code></li>
|
|
171
|
+
<li><code>src/spans/</code></li>
|
|
172
|
+
<li><code>src/sessions/</code></li>
|
|
173
|
+
<li><code>src/traces/</code></li>
|
|
174
|
+
<li><code>src/types/</code></li>
|
|
175
|
+
</ul>
|
|
176
|
+
</section>
|
package/docs/prompts.mdx
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Prompts"
|
|
3
|
+
description: "Manage prompts with @arizeai/phoenix-client"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
The prompts module lets you create prompt versions in Phoenix, fetch them back by selector, list prompts, and adapt prompt versions to supported provider SDKs.
|
|
7
|
+
|
|
8
|
+
<section className="hidden" data-agent-context="relevant-source-files" aria-label="Relevant source files">
|
|
9
|
+
<h2>Relevant Source Files</h2>
|
|
10
|
+
<ul>
|
|
11
|
+
<li><code>src/prompts/getPrompt.ts</code> for the exact selector shape</li>
|
|
12
|
+
</ul>
|
|
13
|
+
</section>
|
|
14
|
+
|
|
15
|
+
## Create A Prompt
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import {
|
|
19
|
+
createPrompt,
|
|
20
|
+
promptVersion,
|
|
21
|
+
} from "@arizeai/phoenix-client/prompts";
|
|
22
|
+
|
|
23
|
+
await createPrompt({
|
|
24
|
+
name: "support-response",
|
|
25
|
+
description: "Customer support reply prompt",
|
|
26
|
+
version: promptVersion({
|
|
27
|
+
modelProvider: "OPENAI",
|
|
28
|
+
modelName: "gpt-4o-mini",
|
|
29
|
+
template: [{ role: "user", content: "Reply to {{question}}" }],
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Fetch By Selector
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { getPrompt } from "@arizeai/phoenix-client/prompts";
|
|
38
|
+
|
|
39
|
+
const prompt = await getPrompt({
|
|
40
|
+
prompt: { name: "support-response", tag: "production" },
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`prompt` can be selected by `{ name }`, `{ name, tag }`, or `{ versionId }`.
|
|
45
|
+
|
|
46
|
+
## Convert To Another SDK
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { toSDK } from "@arizeai/phoenix-client/prompts";
|
|
50
|
+
|
|
51
|
+
const promptAsAI = toSDK({
|
|
52
|
+
sdk: "ai",
|
|
53
|
+
prompt,
|
|
54
|
+
variables: { question: "Where is my order?" },
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Supported `sdk` targets:
|
|
59
|
+
|
|
60
|
+
- `ai`
|
|
61
|
+
- `openai`
|
|
62
|
+
- `anthropic`
|
|
63
|
+
|
|
64
|
+
<section className="hidden" data-agent-context="source-map" aria-label="Source map">
|
|
65
|
+
<h2>Source Map</h2>
|
|
66
|
+
<ul>
|
|
67
|
+
<li><code>src/prompts/createPrompt.ts</code></li>
|
|
68
|
+
<li><code>src/prompts/getPrompt.ts</code></li>
|
|
69
|
+
<li><code>src/prompts/listPrompts.ts</code></li>
|
|
70
|
+
<li><code>src/prompts/sdks/toSDK.ts</code></li>
|
|
71
|
+
<li><code>src/types/prompts.ts</code></li>
|
|
72
|
+
</ul>
|
|
73
|
+
</section>
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Session Annotations"
|
|
3
|
+
description: "Log session-level annotations for conversation evaluation with @arizeai/phoenix-client"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Session annotations attach feedback to multi-turn conversations or threads. Use them for conversation-level quality signals: whether the session achieved its goal, whether a human handoff was needed, overall satisfaction scores.
|
|
7
|
+
|
|
8
|
+
All functions are imported from `@arizeai/phoenix-client/sessions`. See [Annotations](./annotations) for the shared annotation model and concepts.
|
|
9
|
+
|
|
10
|
+
<Note>
|
|
11
|
+
Requires **Phoenix Server ≥ 12.0.0**. The client will throw an error with the minimum required version if the server is too old.
|
|
12
|
+
</Note>
|
|
13
|
+
|
|
14
|
+
<section className="hidden" data-agent-context="relevant-source-files" aria-label="Relevant source files">
|
|
15
|
+
<h2>Relevant Source Files</h2>
|
|
16
|
+
<ul>
|
|
17
|
+
<li><code>src/sessions/addSessionAnnotation.ts</code> for the single-annotation API</li>
|
|
18
|
+
<li><code>src/sessions/logSessionAnnotations.ts</code> for batch logging</li>
|
|
19
|
+
<li><code>src/sessions/types.ts</code> for the <code>SessionAnnotation</code> interface</li>
|
|
20
|
+
</ul>
|
|
21
|
+
</section>
|
|
22
|
+
|
|
23
|
+
## Add A Single Session Annotation
|
|
24
|
+
|
|
25
|
+
Mark a support session as resolved after human review:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { addSessionAnnotation } from "@arizeai/phoenix-client/sessions";
|
|
29
|
+
|
|
30
|
+
await addSessionAnnotation({
|
|
31
|
+
sessionAnnotation: {
|
|
32
|
+
sessionId: "cst_abc123",
|
|
33
|
+
name: "resolution",
|
|
34
|
+
annotatorKind: "HUMAN",
|
|
35
|
+
label: "resolved",
|
|
36
|
+
score: 1,
|
|
37
|
+
explanation: "User confirmed their issue was resolved.",
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Batch Log Session Annotations
|
|
43
|
+
|
|
44
|
+
Use `logSessionAnnotations` to annotate multiple sessions in a single request. This example scores a batch of support sessions for handoff detection:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { logSessionAnnotations } from "@arizeai/phoenix-client/sessions";
|
|
48
|
+
|
|
49
|
+
await logSessionAnnotations({
|
|
50
|
+
sessionAnnotations: [
|
|
51
|
+
{
|
|
52
|
+
sessionId: "cst_abc123",
|
|
53
|
+
name: "handoff-required",
|
|
54
|
+
annotatorKind: "CODE",
|
|
55
|
+
score: 0,
|
|
56
|
+
label: "no",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
sessionId: "cst_def456",
|
|
60
|
+
name: "handoff-required",
|
|
61
|
+
annotatorKind: "CODE",
|
|
62
|
+
score: 1,
|
|
63
|
+
label: "yes",
|
|
64
|
+
explanation: "Sentiment dropped below threshold at turn 4.",
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Conversation Quality Scoring
|
|
71
|
+
|
|
72
|
+
After a multi-turn conversation ends, use an LLM to evaluate overall coherence and goal completion:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { addSessionAnnotation } from "@arizeai/phoenix-client/sessions";
|
|
76
|
+
|
|
77
|
+
// evaluationResult comes from your LLM judge pipeline
|
|
78
|
+
await addSessionAnnotation({
|
|
79
|
+
sessionAnnotation: {
|
|
80
|
+
sessionId: sessionId,
|
|
81
|
+
name: "conversation-quality",
|
|
82
|
+
annotatorKind: "LLM",
|
|
83
|
+
score: evaluationResult.score,
|
|
84
|
+
label: evaluationResult.score > 0.7 ? "good" : "needs-improvement",
|
|
85
|
+
explanation: evaluationResult.reasoning,
|
|
86
|
+
metadata: { model: "gpt-4o", evaluatorVersion: "v2" },
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## End-User Satisfaction (CSAT)
|
|
92
|
+
|
|
93
|
+
Log customer satisfaction at the end of a chat session. Normalize the raw rating to a 0–1 scale for consistent scoring:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { addSessionAnnotation } from "@arizeai/phoenix-client/sessions";
|
|
97
|
+
|
|
98
|
+
// User submitted a 1-5 star rating at end of chat
|
|
99
|
+
await addSessionAnnotation({
|
|
100
|
+
sessionAnnotation: {
|
|
101
|
+
sessionId: sessionId,
|
|
102
|
+
name: "csat",
|
|
103
|
+
annotatorKind: "HUMAN",
|
|
104
|
+
score: userRating / 5,
|
|
105
|
+
label: userRating >= 4 ? "satisfied" : "unsatisfied",
|
|
106
|
+
metadata: { rawRating: userRating, channel: "mobile-app" },
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Idempotent Upserts With `identifier`
|
|
112
|
+
|
|
113
|
+
Session annotations are unique by `(name, sessionId, identifier)`. The `identifier` field controls whether a write creates a new annotation or updates an existing one.
|
|
114
|
+
|
|
115
|
+
Without `identifier`, a session can only have one annotation per name. Adding an `identifier` lets you store **multiple annotations with the same name** on the same session, each keyed by a different identifier. Re-sending the same tuple updates that specific annotation in place.
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import { addSessionAnnotation } from "@arizeai/phoenix-client/sessions";
|
|
119
|
+
|
|
120
|
+
await addSessionAnnotation({
|
|
121
|
+
sessionAnnotation: {
|
|
122
|
+
sessionId: sessionId,
|
|
123
|
+
name: "goal-completion",
|
|
124
|
+
annotatorKind: "LLM",
|
|
125
|
+
score: 0.85,
|
|
126
|
+
identifier: "goal-eval-v3",
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
// Running this again updates the existing annotation.
|
|
130
|
+
// Using identifier: "goal-eval-v4" would create a second annotation.
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Parameter Reference
|
|
134
|
+
|
|
135
|
+
### `SessionAnnotation`
|
|
136
|
+
|
|
137
|
+
| Field | Type | Required | Description |
|
|
138
|
+
|-------|------|----------|-------------|
|
|
139
|
+
| `sessionId` | `string` | Yes | Session / conversation / thread identifier |
|
|
140
|
+
| `name` | `string` | Yes | Annotation name (e.g. `"csat"`) |
|
|
141
|
+
| `annotatorKind` | `"HUMAN" \| "LLM" \| "CODE"` | No | Defaults to `"HUMAN"` |
|
|
142
|
+
| `label` | `string` | No* | Categorical label |
|
|
143
|
+
| `score` | `number` | No* | Numeric score |
|
|
144
|
+
| `explanation` | `string` | No* | Free-text explanation |
|
|
145
|
+
| `identifier` | `string` | No | For idempotent upserts |
|
|
146
|
+
| `metadata` | `Record<string, unknown>` | No | Arbitrary metadata |
|
|
147
|
+
|
|
148
|
+
\*At least one of `label`, `score`, or `explanation` is required.
|
|
149
|
+
|
|
150
|
+
<section className="hidden" data-agent-context="source-map" aria-label="Source map">
|
|
151
|
+
<h2>Source Map</h2>
|
|
152
|
+
<ul>
|
|
153
|
+
<li><code>src/sessions/addSessionAnnotation.ts</code></li>
|
|
154
|
+
<li><code>src/sessions/logSessionAnnotations.ts</code></li>
|
|
155
|
+
<li><code>src/sessions/types.ts</code></li>
|
|
156
|
+
<li><code>src/types/annotations.ts</code></li>
|
|
157
|
+
</ul>
|
|
158
|
+
</section>
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Sessions"
|
|
3
|
+
description: "Work with sessions in @arizeai/phoenix-client"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
The sessions module groups multi-turn activity under a project and supports retrieval, annotations, and cleanup.
|
|
7
|
+
|
|
8
|
+
<section className="hidden" data-agent-context="relevant-source-files" aria-label="Relevant source files">
|
|
9
|
+
<h2>Relevant Source Files</h2>
|
|
10
|
+
<ul>
|
|
11
|
+
<li>
|
|
12
|
+
<code>src/sessions/listSessions.ts</code> for the exact project selector
|
|
13
|
+
shape
|
|
14
|
+
</li>
|
|
15
|
+
<li>
|
|
16
|
+
<code>src/sessions/getSessionTurns.ts</code> for how turns are derived
|
|
17
|
+
from root spans
|
|
18
|
+
</li>
|
|
19
|
+
</ul>
|
|
20
|
+
</section>
|
|
21
|
+
|
|
22
|
+
## List Sessions
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { listSessions } from "@arizeai/phoenix-client/sessions";
|
|
26
|
+
|
|
27
|
+
const sessions = await listSessions({
|
|
28
|
+
projectName: "support-bot",
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
for (const session of sessions) {
|
|
32
|
+
console.log(session.sessionId);
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Retrieve A Session And Its Turns
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import {
|
|
40
|
+
getSession,
|
|
41
|
+
getSessionTurns,
|
|
42
|
+
} from "@arizeai/phoenix-client/sessions";
|
|
43
|
+
|
|
44
|
+
const session = await getSession({
|
|
45
|
+
sessionId: "cst_123",
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const turns = await getSessionTurns({
|
|
49
|
+
sessionId: "cst_123",
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`getSession()` and `getSessionTurns()` only need `sessionId`. They do not take a `project` selector.
|
|
54
|
+
|
|
55
|
+
## Annotate Sessions
|
|
56
|
+
|
|
57
|
+
Session annotations are covered in depth in [Session Annotations](./session-annotations). Quick example:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { addSessionAnnotation } from "@arizeai/phoenix-client/sessions";
|
|
61
|
+
|
|
62
|
+
await addSessionAnnotation({
|
|
63
|
+
sessionAnnotation: {
|
|
64
|
+
sessionId: "cst_123",
|
|
65
|
+
name: "handoff-required",
|
|
66
|
+
annotatorKind: "CODE",
|
|
67
|
+
score: 1,
|
|
68
|
+
label: "yes",
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Cleanup
|
|
74
|
+
|
|
75
|
+
Use `deleteSession` or `deleteSessions` when you need to remove session records by identifier.
|
|
76
|
+
|
|
77
|
+
<section className="hidden" data-agent-context="source-map" aria-label="Source map">
|
|
78
|
+
<h2>Source Map</h2>
|
|
79
|
+
<ul>
|
|
80
|
+
<li><code>src/sessions/listSessions.ts</code></li>
|
|
81
|
+
<li><code>src/sessions/getSession.ts</code></li>
|
|
82
|
+
<li><code>src/sessions/getSessionTurns.ts</code></li>
|
|
83
|
+
<li><code>src/sessions/addSessionAnnotation.ts</code></li>
|
|
84
|
+
<li><code>src/sessions/deleteSession.ts</code></li>
|
|
85
|
+
<li><code>src/sessions/deleteSessions.ts</code></li>
|
|
86
|
+
</ul>
|
|
87
|
+
</section>
|