Skip to content

Commit 1521a27

Browse files
authored
feat(askfern): Add index and chat API definitons. (#3276)
1 parent be21f9b commit 1521a27

File tree

27 files changed

+742
-19
lines changed

27 files changed

+742
-19
lines changed

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.DS_Store
22

3-
3+
servers/fai
44
lib
55
build
66
**/dist/**

fern/apis/fai/definition/analytics.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
docs: APIs for the FAI (Acorn) Service
1+
docs: FAI Analytics API
22

33
imports:
44
commons: ./commons.yml

fern/apis/fai/definition/chat.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
docs: FAI Chat API
2+
3+
imports:
4+
commons: ./commons.yml
5+
6+
service:
7+
auth: false
8+
base-path: /chat
9+
endpoints:
10+
chatCompletion:
11+
docs: Create a docs chat completion for a given domain
12+
path: /{domain}
13+
method: POST
14+
path-parameters:
15+
domain: string
16+
request:
17+
name: ChatCompletionRequest
18+
body:
19+
properties:
20+
model: optional<string>
21+
system_prompt: optional<string>
22+
messages: list<ChatTurn>
23+
response: ChatCompletionResponse
24+
errors:
25+
- commons.BadRequestError
26+
- commons.InternalError
27+
28+
types:
29+
ChatCompletionResponse:
30+
properties:
31+
turn: ChatTurn
32+
33+
ChatTurn:
34+
properties:
35+
role: string
36+
text: string

fern/apis/fai/definition/index.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
docs: FAI Index API
2+
3+
imports:
4+
commons: ./commons.yml
5+
6+
service:
7+
auth: false
8+
base-path: /index
9+
endpoints:
10+
indexDocument:
11+
docs: Index a document for a given domain
12+
path: /{domain}
13+
method: POST
14+
path-parameters:
15+
domain: string
16+
request:
17+
name: IndexRequest
18+
body:
19+
properties:
20+
index_name:
21+
type: optional<string>
22+
default: custom
23+
docs: The name of the index to which the document will be added
24+
document_id:
25+
type: string
26+
docs: A unique identifier for the document
27+
context:
28+
type: string
29+
docs: The context of the document that will be indexed
30+
content:
31+
type: string
32+
docs: The content of the document that will be returned in the tool response
33+
errors:
34+
- commons.BadRequestError
35+
- commons.InternalError

packages/fai-sdk/README.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,19 @@ Instantiate and use the client with the following:
2323
import { FernFaiClient } from "@fern-api/fai-sdk";
2424

2525
const client = new FernFaiClient({ token: "YOUR_TOKEN" });
26-
await client.queries.createQuery({
27-
query_id: "query_id",
28-
conversation_id: "conversation_id",
29-
domain: "domain",
30-
text: "text",
31-
role: "role",
32-
source: "source",
33-
created_at: "2024-01-15T09:30:00Z",
34-
time_to_first_token: undefined,
26+
await client.chat.chatCompletion("domain", {
27+
model: undefined,
28+
system_prompt: undefined,
29+
messages: [
30+
{
31+
role: "role",
32+
text: "text",
33+
},
34+
{
35+
role: "role",
36+
text: "text",
37+
},
38+
],
3539
});
3640
```
3741

@@ -57,7 +61,7 @@ will be thrown.
5761
import { FernFaiError } from "@fern-api/fai-sdk";
5862

5963
try {
60-
await client.queries.createQuery(...);
64+
await client.chat.chatCompletion(...);
6165
} catch (err) {
6266
if (err instanceof FernFaiError) {
6367
console.log(err.statusCode);
@@ -75,7 +79,7 @@ try {
7579
If you would like to send additional headers as part of the request, use the `headers` request option.
7680

7781
```typescript
78-
const response = await client.queries.createQuery(..., {
82+
const response = await client.chat.chatCompletion(..., {
7983
headers: {
8084
'X-Custom-Header': 'custom value'
8185
}
@@ -97,7 +101,7 @@ A request is deemed retryable when any of the following HTTP status codes is ret
97101
Use the `maxRetries` request option to configure this behavior.
98102

99103
```typescript
100-
const response = await client.queries.createQuery(..., {
104+
const response = await client.chat.chatCompletion(..., {
101105
maxRetries: 0 // override maxRetries at the request level
102106
});
103107
```
@@ -107,7 +111,7 @@ const response = await client.queries.createQuery(..., {
107111
The SDK defaults to a 60 second timeout. Use the `timeoutInSeconds` option to configure this behavior.
108112

109113
```typescript
110-
const response = await client.queries.createQuery(..., {
114+
const response = await client.chat.chatCompletion(..., {
111115
timeoutInSeconds: 30 // override timeout to 30s
112116
});
113117
```
@@ -118,7 +122,7 @@ The SDK allows users to abort requests at any point by passing in an abort signa
118122

119123
```typescript
120124
const controller = new AbortController();
121-
const response = await client.queries.createQuery(..., {
125+
const response = await client.chat.chatCompletion(..., {
122126
abortSignal: controller.signal
123127
});
124128
controller.abort(); // aborts the request
@@ -130,7 +134,7 @@ The SDK provides access to raw response data, including headers, through the `.w
130134
The `.withRawResponse()` method returns a promise that results to an object with a `data` and a `rawResponse` property.
131135

132136
```typescript
133-
const { data, rawResponse } = await client.queries.createQuery(...).withRawResponse();
137+
const { data, rawResponse } = await client.chat.chatCompletion(...).withRawResponse();
134138

135139
console.log(data);
136140
console.log(rawResponse.headers['X-My-Header']);

packages/fai-sdk/reference.md

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,92 @@ await client.analytics.getInsights("domain");
146146
</dl>
147147
</details>
148148

149+
## Chat
150+
151+
<details><summary><code>client.chat.<a href="/src/api/resources/chat/client/Client.ts">chatCompletion</a>(domain, { ...params }) -> FernFai.ChatCompletionResponse</code></summary>
152+
<dl>
153+
<dd>
154+
155+
#### 📝 Description
156+
157+
<dl>
158+
<dd>
159+
160+
<dl>
161+
<dd>
162+
163+
Create a docs chat completion for a given domain
164+
165+
</dd>
166+
</dl>
167+
</dd>
168+
</dl>
169+
170+
#### 🔌 Usage
171+
172+
<dl>
173+
<dd>
174+
175+
<dl>
176+
<dd>
177+
178+
```typescript
179+
await client.chat.chatCompletion("domain", {
180+
model: undefined,
181+
system_prompt: undefined,
182+
messages: [
183+
{
184+
role: "role",
185+
text: "text",
186+
},
187+
{
188+
role: "role",
189+
text: "text",
190+
},
191+
],
192+
});
193+
```
194+
195+
</dd>
196+
</dl>
197+
</dd>
198+
</dl>
199+
200+
#### ⚙️ Parameters
201+
202+
<dl>
203+
<dd>
204+
205+
<dl>
206+
<dd>
207+
208+
**domain:** `string`
209+
210+
</dd>
211+
</dl>
212+
213+
<dl>
214+
<dd>
215+
216+
**request:** `FernFai.ChatCompletionRequest`
217+
218+
</dd>
219+
</dl>
220+
221+
<dl>
222+
<dd>
223+
224+
**requestOptions:** `Chat.RequestOptions`
225+
226+
</dd>
227+
</dl>
228+
</dd>
229+
</dl>
230+
231+
</dd>
232+
</dl>
233+
</details>
234+
149235
## Conversations
150236

151237
<details><summary><code>client.conversations.<a href="/src/api/resources/conversations/client/Client.ts">getConversation</a>(domain, conversationId) -> FernFai.Conversation</code></summary>
@@ -219,6 +305,84 @@ await client.conversations.getConversation("domain", "conversation_id");
219305
</dl>
220306
</details>
221307

308+
## Index
309+
310+
<details><summary><code>client.index.<a href="/src/api/resources/index/client/Client.ts">indexDocument</a>(domain, { ...params }) -> void</code></summary>
311+
<dl>
312+
<dd>
313+
314+
#### 📝 Description
315+
316+
<dl>
317+
<dd>
318+
319+
<dl>
320+
<dd>
321+
322+
Index a document for a given domain
323+
324+
</dd>
325+
</dl>
326+
</dd>
327+
</dl>
328+
329+
#### 🔌 Usage
330+
331+
<dl>
332+
<dd>
333+
334+
<dl>
335+
<dd>
336+
337+
```typescript
338+
await client.index.indexDocument("domain", {
339+
index_name: undefined,
340+
document_id: "document_id",
341+
context: "context",
342+
content: "content",
343+
});
344+
```
345+
346+
</dd>
347+
</dl>
348+
</dd>
349+
</dl>
350+
351+
#### ⚙️ Parameters
352+
353+
<dl>
354+
<dd>
355+
356+
<dl>
357+
<dd>
358+
359+
**domain:** `string`
360+
361+
</dd>
362+
</dl>
363+
364+
<dl>
365+
<dd>
366+
367+
**request:** `FernFai.IndexRequest`
368+
369+
</dd>
370+
</dl>
371+
372+
<dl>
373+
<dd>
374+
375+
**requestOptions:** `Index.RequestOptions`
376+
377+
</dd>
378+
</dl>
379+
</dd>
380+
</dl>
381+
382+
</dd>
383+
</dl>
384+
</details>
385+
222386
## Queries
223387

224388
<details><summary><code>client.queries.<a href="/src/api/resources/queries/client/Client.ts">createQuery</a>({ ...params }) -> void</code></summary>

packages/fai-sdk/src/Client.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import * as environments from "./environments.js";
66
import * as core from "./core/index.js";
77
import { mergeHeaders } from "./core/headers.js";
88
import { Analytics } from "./api/resources/analytics/client/Client.js";
9+
import { Chat } from "./api/resources/chat/client/Client.js";
910
import { Conversations } from "./api/resources/conversations/client/Client.js";
11+
import { Index } from "./api/resources/index/client/Client.js";
1012
import { Queries } from "./api/resources/queries/client/Client.js";
1113

1214
export declare namespace FernFaiClient {
@@ -34,7 +36,9 @@ export declare namespace FernFaiClient {
3436
export class FernFaiClient {
3537
protected readonly _options: FernFaiClient.Options;
3638
protected _analytics: Analytics | undefined;
39+
protected _chat: Chat | undefined;
3740
protected _conversations: Conversations | undefined;
41+
protected _index: Index | undefined;
3842
protected _queries: Queries | undefined;
3943

4044
constructor(_options: FernFaiClient.Options = {}) {
@@ -44,7 +48,7 @@ export class FernFaiClient {
4448
{
4549
"X-Fern-Language": "JavaScript",
4650
"X-Fern-SDK-Name": "@fern-api/fai-sdk",
47-
"X-Fern-SDK-Version": "0.0.38",
51+
"X-Fern-SDK-Version": "0.0.43",
4852
"X-Fern-Runtime": core.RUNTIME.type,
4953
"X-Fern-Runtime-Version": core.RUNTIME.version,
5054
},
@@ -57,10 +61,18 @@ export class FernFaiClient {
5761
return (this._analytics ??= new Analytics(this._options));
5862
}
5963

64+
public get chat(): Chat {
65+
return (this._chat ??= new Chat(this._options));
66+
}
67+
6068
public get conversations(): Conversations {
6169
return (this._conversations ??= new Conversations(this._options));
6270
}
6371

72+
public get index(): Index {
73+
return (this._index ??= new Index(this._options));
74+
}
75+
6476
public get queries(): Queries {
6577
return (this._queries ??= new Queries(this._options));
6678
}

0 commit comments

Comments
 (0)