Skip to content

Commit

Permalink
Merge pull request #68 from writer/release-please--branches--main--ch…
Browse files Browse the repository at this point in the history
…anges--next--components--writer-sdk

release: 1.0.0
  • Loading branch information
ramedina86 authored Oct 9, 2024
2 parents 394acb8 + 0b2fdc9 commit 2236af2
Show file tree
Hide file tree
Showing 22 changed files with 1,102 additions and 275 deletions.
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.5.0"
".": "1.0.0"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 18
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/writerai%2Fwriter-5d34056e0e749d39a81c92ed4fb221da6ac627cff4cb9edcb6b054fa00abb335.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/writerai%2Fwriter-2ad4cffb18a01119bca51bc468740407407dcf2aea29a0323e3c84662817b000.yml
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
# Changelog

## 1.0.0 (2024-10-09)

Full Changelog: [v0.5.0...v1.0.0](https://github.com/writer/writer-node/compare/v0.5.0...v1.0.0)

### Features

* **api:** add model graphs.Question ([#67](https://github.com/writer/writer-node/issues/67)) ([af195e9](https://github.com/writer/writer-node/commit/af195e9a6e4562dfb7a7e24cde19a20d45e8511f))
* **api:** rename to chat_completion_chunk ([#73](https://github.com/writer/writer-node/issues/73)) ([e4d5ac4](https://github.com/writer/writer-node/commit/e4d5ac4a9cf5eb8fa8a068024628b4ae689e5468))
* **api:** update models in readme ([#79](https://github.com/writer/writer-node/issues/79)) ([19b7851](https://github.com/writer/writer-node/commit/19b7851bc31035fb457063bd5ea92aa15f4bc4ee))


### Bug Fixes

* add content type to file uploads param ([cb5531a](https://github.com/writer/writer-node/commit/cb5531ab082f648e26b41b109e56b84bd41b4c50))
* change file content type to Core.Uploadable ([64c3ac9](https://github.com/writer/writer-node/commit/64c3ac9f330c55616511146bc4c2c228ebf05fc6))


### Chores

* **internal:** codegen related update ([#69](https://github.com/writer/writer-node/issues/69)) ([4fdbf70](https://github.com/writer/writer-node/commit/4fdbf70757530bd9dfd045e60da042877aac82a4))
* **internal:** codegen related update ([#72](https://github.com/writer/writer-node/issues/72)) ([611a33b](https://github.com/writer/writer-node/commit/611a33bda7ce33ec69fa3907a2b6ad7ae0fbe781))
* **internal:** move LineDecoder to a separate file ([#76](https://github.com/writer/writer-node/issues/76)) ([f8c8855](https://github.com/writer/writer-node/commit/f8c885507286f008fb26a501d692d25f912b4798))
* **internal:** pass props through internal parser ([#78](https://github.com/writer/writer-node/issues/78)) ([bb1aae5](https://github.com/writer/writer-node/commit/bb1aae50a38e375118b3ddaf35ceabb83b0ae44d))


### Documentation

* add pagination example ([#74](https://github.com/writer/writer-node/issues/74)) ([09b3ee2](https://github.com/writer/writer-node/commit/09b3ee23124d02bf223c1ec1e8458217af47b570))
* **api:** updates to API spec ([#70](https://github.com/writer/writer-node/issues/70)) ([7c0721d](https://github.com/writer/writer-node/commit/7c0721da2901bd6e4ee7aba97b32ec8b6d8bec52))
* **api:** updates to API spec ([#75](https://github.com/writer/writer-node/issues/75)) ([3fad6c7](https://github.com/writer/writer-node/commit/3fad6c7738c5abf3e795f3b7d8c35d9a76eaf98b))
* **api:** updates to API spec ([#77](https://github.com/writer/writer-node/issues/77)) ([8749431](https://github.com/writer/writer-node/commit/87494313a99d6c8be5f768ce7654bf7f52f7042a))

## 0.5.0 (2024-09-24)

Full Changelog: [v0.4.1...v0.5.0](https://github.com/writer/writer-node/compare/v0.4.1...v0.5.0)
Expand Down
46 changes: 23 additions & 23 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Other package managers may work but are not officially supported for development

To set up the repository, run:

```bash
yarn
yarn build
```sh
$ yarn
$ yarn build
```

This will install all the required dependencies and build output files to `dist/`.
Expand All @@ -22,7 +22,7 @@ modify the contents of the `src/lib/` and `examples/` directories.

All files in the `examples/` directory are not modified by the generator and can be freely edited or added to.

```bash
```ts
// add an example to examples/<your-example>.ts

#!/usr/bin/env -S npm run tsn -T
Expand All @@ -41,38 +41,38 @@ If you’d like to use the repository from source, you can either install from g

To install via git:

```bash
npm install git+ssh://[email protected]:writer/writer-node.git
```sh
$ npm install git+ssh://[email protected]:writer/writer-node.git
```

Alternatively, to link a local copy of the repo:

```bash
```sh
# Clone
git clone https://www.github.com/writer/writer-node
cd writer-node
$ git clone https://www.github.com/writer/writer-node
$ cd writer-node

# With yarn
yarn link
cd ../my-package
yarn link writer-sdk
$ yarn link
$ cd ../my-package
$ yarn link writer-sdk

# With pnpm
pnpm link --global
cd ../my-package
pnpm link -—global writer-sdk
$ pnpm link --global
$ cd ../my-package
$ pnpm link -—global writer-sdk
```

## Running tests

Most tests require you to [set up a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests.

```bash
npx prism mock path/to/your/openapi.yml
```sh
$ npx prism mock path/to/your/openapi.yml
```

```bash
yarn run test
```sh
$ yarn run test
```

## Linting and formatting
Expand All @@ -82,14 +82,14 @@ This repository uses [prettier](https://www.npmjs.com/package/prettier) and

To lint:

```bash
yarn lint
```sh
$ yarn lint
```

To format and fix all lint issues automatically:

```bash
yarn fix
```sh
$ yarn fix
```

## Publishing and releases
Expand Down
53 changes: 44 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const client = new Writer({
async function main() {
const chat = await client.chat.chat({
messages: [{ content: 'Write a memo summarizing this earnings report.', role: 'user' }],
model: 'palmyra-x-002-32k',
model: 'palmyra-x-004',
});

console.log(chat.id);
Expand All @@ -48,7 +48,7 @@ import Writer from 'writer-sdk';
const client = new Writer();

const stream = await client.completions.create({
model: 'palmyra-x-002-instruct',
model: 'palmyra-x-003-instruct',
prompt: 'Hi, my name is',
stream: true,
});
Expand All @@ -75,7 +75,7 @@ const client = new Writer({
async function main() {
const params: Writer.ChatChatParams = {
messages: [{ content: 'Write a memo summarizing this earnings report.', role: 'user' }],
model: 'palmyra-x-002-32k',
model: 'palmyra-x-004',
};
const chat: Writer.Chat = await client.chat.chat(params);
}
Expand All @@ -97,7 +97,7 @@ async function main() {
const chat = await client.chat
.chat({
messages: [{ content: 'Write a memo summarizing this earnings report.', role: 'user' }],
model: 'palmyra-x-002-32k',
model: 'palmyra-x-004',
})
.catch(async (err) => {
if (err instanceof Writer.APIError) {
Expand Down Expand Up @@ -142,7 +142,7 @@ const client = new Writer({
});

// Or, configure per-request:
await client.chat.chat({ messages: [{ content: 'Write a memo summarizing this earnings report.', role: 'user' }], model: 'palmyra-x-002-32k' }, {
await client.chat.chat({ messages: [{ content: 'Write a memo summarizing this earnings report.', role: 'user' }], model: 'palmyra-x-004' }, {
maxRetries: 5,
});
```
Expand All @@ -159,7 +159,7 @@ const client = new Writer({
});

// Override per-request:
await client.chat.chat({ messages: [{ content: 'Write a memo summarizing this earnings report.', role: 'user' }], model: 'palmyra-x-002-32k' }, {
await client.chat.chat({ messages: [{ content: 'Write a memo summarizing this earnings report.', role: 'user' }], model: 'palmyra-x-004' }, {
timeout: 5 * 1000,
});
```
Expand All @@ -168,6 +168,37 @@ On timeout, an `APIConnectionTimeoutError` is thrown.

Note that requests which time out will be [retried twice by default](#retries).

## Auto-pagination

List methods in the Writer API are paginated.
You can use `for await … of` syntax to iterate through items across all pages:

```ts
async function fetchAllGraphs(params) {
const allGraphs = [];
// Automatically fetches more pages as needed.
for await (const graph of client.graphs.list()) {
allGraphs.push(graph);
}
return allGraphs;
}
```

Alternatively, you can make request a single page at a time:

```ts
let page = await client.graphs.list();
for (const graph of page.data) {
console.log(graph);
}

// Convenience methods are provided for manually paginating:
while (page.hasNextPage()) {
page = page.getNextPage();
// ...
}
```

## Advanced Usage

### Accessing raw Response data (e.g., headers)
Expand All @@ -183,7 +214,7 @@ const client = new Writer();
const response = await client.chat
.chat({
messages: [{ content: 'Write a memo summarizing this earnings report.', role: 'user' }],
model: 'palmyra-x-002-32k',
model: 'palmyra-x-004',
})
.asResponse();
console.log(response.headers.get('X-My-Header'));
Expand All @@ -192,7 +223,7 @@ console.log(response.statusText); // access the underlying Response object
const { data: chat, response: raw } = await client.chat
.chat({
messages: [{ content: 'Write a memo summarizing this earnings report.', role: 'user' }],
model: 'palmyra-x-002-32k',
model: 'palmyra-x-004',
})
.withResponse();
console.log(raw.headers.get('X-My-Header'));
Expand Down Expand Up @@ -303,7 +334,7 @@ const client = new Writer({
await client.chat.chat(
{
messages: [{ content: 'Write a memo summarizing this earnings report.', role: 'user' }],
model: 'palmyra-x-002-32k',
model: 'palmyra-x-004',
},
{
httpAgent: new http.Agent({ keepAlive: false }),
Expand Down Expand Up @@ -332,3 +363,7 @@ The following runtimes are supported:
Note that React Native is not supported at this time.

If you are interested in other runtime environments, please open or upvote an issue on GitHub.

## Contributing

See [the contributing documentation](./CONTRIBUTING.md).
8 changes: 4 additions & 4 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Methods:
Types:

- <code><a href="./src/resources/chat.ts">Chat</a></code>
- <code><a href="./src/resources/chat.ts">ChatStreamingData</a></code>
- <code><a href="./src/resources/chat.ts">ChatCompletionChunk</a></code>

Methods:

Expand Down Expand Up @@ -45,10 +45,10 @@ Methods:
Types:

- <code><a href="./src/resources/graphs.ts">Graph</a></code>
- <code><a href="./src/resources/graphs.ts">Question</a></code>
- <code><a href="./src/resources/graphs.ts">GraphCreateResponse</a></code>
- <code><a href="./src/resources/graphs.ts">GraphUpdateResponse</a></code>
- <code><a href="./src/resources/graphs.ts">GraphDeleteResponse</a></code>
- <code><a href="./src/resources/graphs.ts">GraphQuestionResponse</a></code>
- <code><a href="./src/resources/graphs.ts">GraphRemoveFileFromGraphResponse</a></code>

Methods:
Expand All @@ -59,7 +59,7 @@ Methods:
- <code title="get /v1/graphs">client.graphs.<a href="./src/resources/graphs.ts">list</a>({ ...params }) -> GraphsCursorPage</code>
- <code title="delete /v1/graphs/{graph_id}">client.graphs.<a href="./src/resources/graphs.ts">delete</a>(graphId) -> GraphDeleteResponse</code>
- <code title="post /v1/graphs/{graph_id}/file">client.graphs.<a href="./src/resources/graphs.ts">addFileToGraph</a>(graphId, { ...params }) -> File</code>
- <code title="post /v1/graphs/question">client.graphs.<a href="./src/resources/graphs.ts">question</a>({ ...params }) -> GraphQuestionResponse</code>
- <code title="post /v1/graphs/question">client.graphs.<a href="./src/resources/graphs.ts">question</a>({ ...params }) -> Question</code>
- <code title="delete /v1/graphs/{graph_id}/file/{file_id}">client.graphs.<a href="./src/resources/graphs.ts">removeFileFromGraph</a>(graphId, fileId) -> GraphRemoveFileFromGraphResponse</code>

# Files
Expand All @@ -76,5 +76,5 @@ Methods:
- <code title="get /v1/files">client.files.<a href="./src/resources/files.ts">list</a>({ ...params }) -> FilesCursorPage</code>
- <code title="delete /v1/files/{file_id}">client.files.<a href="./src/resources/files.ts">delete</a>(fileId) -> FileDeleteResponse</code>
- <code title="get /v1/files/{file_id}/download">client.files.<a href="./src/resources/files.ts">download</a>(fileId) -> Response</code>
- <code title="post /v1/files/retry">client.files.<a href="./src/resources/files.ts">retry</a>({ ...params }) -> unknown</code>
- <code title="post /v1/files/retry">client.files.<a href="./src/resources/files.ts">retry</a>({ ...params }) -> FileRetryResponse</code>
- <code title="post /v1/files">client.files.<a href="./src/resources/files.ts">upload</a>({ ...params }) -> File</code>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "writer-sdk",
"version": "0.5.0",
"version": "1.0.0",
"description": "The official TypeScript library for the Writer API",
"author": "Writer <[email protected]>",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion scripts/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cd "$(dirname "$0")/.."
if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ]; then
brew bundle check >/dev/null 2>&1 || {
echo "==> Installing Homebrew dependencies…"
brew bundle
# brew bundle
}
fi

Expand Down
24 changes: 19 additions & 5 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ export class APIPromise<T> extends Promise<T> {
});
}

_thenUnwrap<U>(transform: (data: T) => U): APIPromise<U> {
return new APIPromise(this.responsePromise, async (props) => transform(await this.parseResponse(props)));
_thenUnwrap<U>(transform: (data: T, props: APIResponseProps) => U): APIPromise<U> {
return new APIPromise(this.responsePromise, async (props) =>
transform(await this.parseResponse(props), props),
);
}

/**
Expand Down Expand Up @@ -363,7 +365,11 @@ export abstract class APIClient {
delete reqHeaders['content-type'];
}

reqHeaders['x-stainless-retry-count'] = String(retryCount);
// Don't set the retry count header if it was already set or removed by the caller. We check `headers`,
// which can contain nulls, instead of `reqHeaders` to account for the removal case.
if (getHeader(headers, 'x-stainless-retry-count') === undefined) {
reqHeaders['x-stainless-retry-count'] = String(retryCount);
}

this.validateHeaders(reqHeaders, headers);

Expand Down Expand Up @@ -1144,7 +1150,15 @@ export const isHeadersProtocol = (headers: any): headers is HeadersProtocol => {
return typeof headers?.get === 'function';
};

export const getRequiredHeader = (headers: HeadersLike, header: string): string => {
export const getRequiredHeader = (headers: HeadersLike | Headers, header: string): string => {
const foundHeader = getHeader(headers, header);
if (foundHeader === undefined) {
throw new Error(`Could not find ${header} header`);
}
return foundHeader;
};

export const getHeader = (headers: HeadersLike | Headers, header: string): string | undefined => {
const lowerCasedHeader = header.toLowerCase();
if (isHeadersProtocol(headers)) {
// to deal with the case where the header looks like Stainless-Event-Id
Expand All @@ -1170,7 +1184,7 @@ export const getRequiredHeader = (headers: HeadersLike, header: string): string
}
}

throw new Error(`Could not find ${header} header`);
return undefined;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export namespace Writer {

export import ChatResource = API.ChatResource;
export import Chat = API.Chat;
export import ChatStreamingData = API.ChatStreamingData;
export import ChatCompletionChunk = API.ChatCompletionChunk;
export import ChatChatParams = API.ChatChatParams;
export import ChatChatParamsNonStreaming = API.ChatChatParamsNonStreaming;
export import ChatChatParamsStreaming = API.ChatChatParamsStreaming;
Expand All @@ -212,10 +212,10 @@ export namespace Writer {

export import Graphs = API.Graphs;
export import Graph = API.Graph;
export import Question = API.Question;
export import GraphCreateResponse = API.GraphCreateResponse;
export import GraphUpdateResponse = API.GraphUpdateResponse;
export import GraphDeleteResponse = API.GraphDeleteResponse;
export import GraphQuestionResponse = API.GraphQuestionResponse;
export import GraphRemoveFileFromGraphResponse = API.GraphRemoveFileFromGraphResponse;
export import GraphsCursorPage = API.GraphsCursorPage;
export import GraphCreateParams = API.GraphCreateParams;
Expand Down
Loading

0 comments on commit 2236af2

Please sign in to comment.