@sanity/client 7.2.1-agent-actions.1 → 7.2.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.
@@ -1,150 +0,0 @@
1
- import {type Observable} from 'rxjs'
2
-
3
- import {_request} from '../../data/dataMethods'
4
- import type {ObservableSanityClient, SanityClient} from '../../SanityClient'
5
- import type {AgentActionParams, Any, HttpRequest} from '../../types'
6
- import {hasDataset} from '../../validators'
7
-
8
- /** @beta */
9
- export interface PromptRequestBase {
10
- /**
11
- * Instruct the LLM how it should generate content. Be as specific and detailed as needed.
12
- *
13
- * The LLM only has access to information in the instruction, plus the target schema.
14
- *
15
- * string template using $variable
16
- * */
17
- instruction: string
18
- /**
19
- * param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable"
20
- *
21
- * ### Examples
22
- *
23
- * #### Constant
24
- *
25
- * ##### Shorthand
26
- * ```ts
27
- * client.agent.action.generate({
28
- * schemaId,
29
- * documentId,
30
- * instruction: 'Give the following topic:\n $topic \n ---\nReturns some facts about it',
31
- * instructionParams: {
32
- * topic: 'Grapefruit'
33
- * },
34
- * })
35
- * ```
36
- * ##### Object-form
37
- *
38
- * ```ts
39
- * client.agent.action.prompt({
40
- * instruction: 'Give the following topic:\n $topic \n ---\nReturns some facts about it.',
41
- * instructionParams: {
42
- * topic: {
43
- * type: 'constant',
44
- * value: 'Grapefruit'
45
- * },
46
- * },
47
- * })
48
- * ```
49
- * #### Field
50
- * ```ts
51
- * client.agent.action.prompt({
52
- * instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
53
- * instructionParams: {
54
- * pte: {
55
- * type: 'field',
56
- * path: ['pteField'],
57
- * documentId: 'someSanityDocId'
58
- * },
59
- * },
60
- * })
61
- * ```
62
- * #### Document
63
- * ```ts
64
- * client.agent.action.prompt({
65
- * json: true,
66
- * instruction: 'Given the following document:$document\nCreate a JSON string[] array with keywords describing it.',
67
- * instructionParams: {
68
- * document: {
69
- * type: 'document',
70
- * documentId: 'someSanityDocId'
71
- * },
72
- * },
73
- * })
74
- * ```
75
- *
76
- * #### GROQ
77
- * ```ts
78
- * client.agent.action.prompt({
79
- * instruction: 'Return the best title amongst these: $titles.',
80
- * instructionParams: {
81
- * titles: {
82
- * type: 'groq',
83
- * query: '* [_type==$type].title',
84
- * params: {type: 'article'}
85
- * },
86
- * },
87
- * })
88
- * ```
89
- * */
90
- instructionParams?: AgentActionParams<{docIdRequired: true}>
91
-
92
- /**
93
- * Controls how much variance the instructions will run with.
94
- *
95
- * Value must be in the range [0, 1] (inclusive).
96
- *
97
- * Defaults:
98
- * - generate: 0.3
99
- * - translate: 0
100
- * - transform: 0
101
- */
102
- temperature?: number
103
- }
104
-
105
- /**
106
- * @beta
107
- */
108
- // need the unused generic here to allow for optional callsite casting
109
- // eslint-disable-next-line unused-imports/no-unused-vars
110
- interface PromptJsonResponse<T extends Record<string, Any> = Record<string, Any>> {
111
- /**
112
- *
113
- * When true, the response body will be json according to the instruction.
114
- * When false, the response is the raw text response to the instruction.
115
- *
116
- * Note: In addition to setting this to true, `instruction` MUST include the word 'JSON', or 'json' for this to work.
117
- */
118
- format: 'json'
119
- }
120
-
121
- interface PromptTextResponse {
122
- /**
123
- *
124
- * When true, the response body will be json according to the instruction.
125
- * When false, the response is the raw text response to the instruction.
126
- *
127
- * Note: In addition to setting this to true, `instruction` MUST include the word 'JSON', or 'json' for this to work.
128
- */
129
- format?: 'text'
130
- }
131
-
132
- /** @beta */
133
- export type PromptRequest<T extends Record<string, Any> = Record<string, Any>> = (
134
- | PromptTextResponse
135
- | PromptJsonResponse<T>
136
- ) &
137
- PromptRequestBase
138
-
139
- export function _prompt<const DocumentShape extends Record<string, Any>>(
140
- client: SanityClient | ObservableSanityClient,
141
- httpRequest: HttpRequest,
142
- request: PromptRequest<DocumentShape>,
143
- ): Observable<(typeof request)['format'] extends 'json' ? DocumentShape : string> {
144
- const dataset = hasDataset(client.config())
145
- return _request(client, httpRequest, {
146
- method: 'POST',
147
- uri: `/agent/action/prompt/${dataset}`,
148
- body: request,
149
- })
150
- }