Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 21
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/writerai%2Fwriter-82683f2fd5f8778a27960ebabda40d6dc4640bdfb77ac4ec7f173b8bf8076d3c.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/writerai%2Fwriter-6b363dd34169cab18f5ec3bcf6586aecd4799f79a80c90bf54e5a12f91d9e7c2.yml
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const client = new Writer({
});

async function main() {
const chat = await client.chat.chat({ messages: [{ role: 'user' }], model: 'palmyra-x-004' });
const chatCompletion = await client.chat.chat({ messages: [{ role: 'user' }], model: 'palmyra-x-004' });

console.log(chat.id);
console.log(chatCompletion.id);
}

main();
Expand All @@ -49,8 +49,8 @@ const stream = await client.completions.create({
prompt: 'Hi, my name is',
stream: true,
});
for await (const streamingData of stream) {
console.log(streamingData.choices);
for await (const completionChunk of stream) {
console.log(completionChunk.choices);
}
```

Expand All @@ -71,7 +71,7 @@ const client = new Writer({

async function main() {
const params: Writer.ChatChatParams = { messages: [{ role: 'user' }], model: 'palmyra-x-004' };
const chat: Writer.Chat = await client.chat.chat(params);
const chatCompletion: Writer.ChatCompletion = await client.chat.chat(params);
}

main();
Expand All @@ -88,7 +88,7 @@ a subclass of `APIError` will be thrown:
<!-- prettier-ignore -->
```ts
async function main() {
const chat = await client.chat
const chatCompletion = await client.chat
.chat({ messages: [{ role: 'user' }], model: 'palmyra-x-004' })
.catch(async (err) => {
if (err instanceof Writer.APIError) {
Expand Down Expand Up @@ -208,11 +208,11 @@ const response = await client.chat
console.log(response.headers.get('X-My-Header'));
console.log(response.statusText); // access the underlying Response object

const { data: chat, response: raw } = await client.chat
const { data: chatCompletion, response: raw } = await client.chat
.chat({ messages: [{ role: 'user' }], model: 'palmyra-x-004' })
.withResponse();
console.log(raw.headers.get('X-My-Header'));
console.log(chat.id);
console.log(chatCompletion.id);
```

### Making custom/undocumented requests
Expand Down
29 changes: 26 additions & 3 deletions api.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# Shared

Types:

- <code><a href="./src/resources/shared.ts">ErrorMessage</a></code>
- <code><a href="./src/resources/shared.ts">ErrorObject</a></code>
- <code><a href="./src/resources/shared.ts">FunctionDefinition</a></code>
- <code><a href="./src/resources/shared.ts">FunctionParams</a></code>
- <code><a href="./src/resources/shared.ts">GraphData</a></code>
- <code><a href="./src/resources/shared.ts">Logprobs</a></code>
- <code><a href="./src/resources/shared.ts">LogprobsToken</a></code>
- <code><a href="./src/resources/shared.ts">Source</a></code>
- <code><a href="./src/resources/shared.ts">ToolCall</a></code>
- <code><a href="./src/resources/shared.ts">ToolCallStreaming</a></code>
- <code><a href="./src/resources/shared.ts">ToolChoiceJsonObject</a></code>
- <code><a href="./src/resources/shared.ts">ToolChoiceString</a></code>
- <code><a href="./src/resources/shared.ts">ToolParam</a></code>

# Applications

Types:
Expand All @@ -12,19 +30,24 @@ Methods:

Types:

- <code><a href="./src/resources/chat.ts">Chat</a></code>
- <code><a href="./src/resources/chat.ts">ChatCompletion</a></code>
- <code><a href="./src/resources/chat.ts">ChatCompletionChoice</a></code>
- <code><a href="./src/resources/chat.ts">ChatCompletionChunk</a></code>
- <code><a href="./src/resources/chat.ts">ChatCompletionMessage</a></code>
- <code><a href="./src/resources/chat.ts">ChatCompletionParams</a></code>
- <code><a href="./src/resources/chat.ts">ChatCompletionUsage</a></code>

Methods:

- <code title="post /v1/chat">client.chat.<a href="./src/resources/chat.ts">chat</a>({ ...params }) -> Chat</code>
- <code title="post /v1/chat">client.chat.<a href="./src/resources/chat.ts">chat</a>({ ...params }) -> ChatCompletion</code>

# Completions

Types:

- <code><a href="./src/resources/completions.ts">Completion</a></code>
- <code><a href="./src/resources/completions.ts">StreamingData</a></code>
- <code><a href="./src/resources/completions.ts">CompletionChunk</a></code>
- <code><a href="./src/resources/completions.ts">CompletionParams</a></code>

Methods:

Expand Down
38 changes: 31 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@ import {
ChatChatParams,
ChatChatParamsNonStreaming,
ChatChatParamsStreaming,
ChatCompletion,
ChatCompletionChoice,
ChatCompletionChunk,
ChatResource,
ChatCompletionMessage,
ChatCompletionParams,
ChatCompletionUsage,
} from './resources/chat';
import {
Completion,
CompletionChunk,
CompletionCreateParams,
CompletionCreateParamsNonStreaming,
CompletionCreateParamsStreaming,
CompletionParams,
Completions,
StreamingData,
} from './resources/completions';
import {
File,
Expand Down Expand Up @@ -179,7 +184,7 @@ export class Writer extends Core.APIClient {
}

applications: API.Applications = new API.Applications(this);
chat: API.ChatResource = new API.ChatResource(this);
chat: API.Chat = new API.Chat(this);
completions: API.Completions = new API.Completions(this);
models: API.Models = new API.Models(this);
graphs: API.Graphs = new API.Graphs(this);
Expand Down Expand Up @@ -223,7 +228,7 @@ export class Writer extends Core.APIClient {
}

Writer.Applications = Applications;
Writer.ChatResource = ChatResource;
Writer.Chat = Chat;
Writer.Completions = Completions;
Writer.Models = Models;
Writer.Graphs = Graphs;
Expand All @@ -244,9 +249,13 @@ export declare namespace Writer {
};

export {
ChatResource as ChatResource,
type Chat as Chat,
Chat as Chat,
type ChatCompletion as ChatCompletion,
type ChatCompletionChoice as ChatCompletionChoice,
type ChatCompletionChunk as ChatCompletionChunk,
type ChatCompletionMessage as ChatCompletionMessage,
type ChatCompletionParams as ChatCompletionParams,
type ChatCompletionUsage as ChatCompletionUsage,
type ChatChatParams as ChatChatParams,
type ChatChatParamsNonStreaming as ChatChatParamsNonStreaming,
type ChatChatParamsStreaming as ChatChatParamsStreaming,
Expand All @@ -255,7 +264,8 @@ export declare namespace Writer {
export {
Completions as Completions,
type Completion as Completion,
type StreamingData as StreamingData,
type CompletionChunk as CompletionChunk,
type CompletionParams as CompletionParams,
type CompletionCreateParams as CompletionCreateParams,
type CompletionCreateParamsNonStreaming as CompletionCreateParamsNonStreaming,
type CompletionCreateParamsStreaming as CompletionCreateParamsStreaming,
Expand Down Expand Up @@ -300,6 +310,20 @@ export declare namespace Writer {
type ToolContextAwareSplittingParams as ToolContextAwareSplittingParams,
type ToolParsePdfParams as ToolParsePdfParams,
};

export type ErrorMessage = API.ErrorMessage;
export type ErrorObject = API.ErrorObject;
export type FunctionDefinition = API.FunctionDefinition;
export type FunctionParams = API.FunctionParams;
export type GraphData = API.GraphData;
export type Logprobs = API.Logprobs;
export type LogprobsToken = API.LogprobsToken;
export type Source = API.Source;
export type ToolCall = API.ToolCall;
export type ToolCallStreaming = API.ToolCallStreaming;
export type ToolChoiceJsonObject = API.ToolChoiceJsonObject;
export type ToolChoiceString = API.ToolChoiceString;
export type ToolParam = API.ToolParam;
}

export { toFile, fileFromPath } from './uploads';
Expand Down
Loading