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
10 changes: 10 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'unused-imports', 'prettier'],
rules: {
'no-unused-vars': 'off',
'prettier/prettier': 'error',
'unused-imports/no-unused-imports': 'error',
},
root: true,
};
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.prism.log
node_modules
yarn-error.log
codegen.log
Brewfile.lock.json
dist
dist-deno
/*.tgz
.idea/
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CHANGELOG.md
/ecosystem-tests/*/**
/node_modules
/deno

# don't format tsc output, will break source maps
/dist
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"arrowParens": "always",
"experimentalTernaries": true,
"printWidth": 110,
"singleQuote": true,
"trailingComma": "all"
}
2 changes: 2 additions & 0 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
configured_endpoints: 74
openapi_spec_url: https://github.com/meta-llama/llama-stack/blob/main/docs/resources/llama-stack-spec.yaml
68 changes: 27 additions & 41 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
## Setting up the environment

This repository uses [`yarn@v1`](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable).
This repository uses [`yarn@v1`](https://classic.yarnpkg.com/lang/en/docs/install).
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,17 +22,17 @@ 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
```

```
chmod +x examples/<your-example>.ts
```sh
$ chmod +x examples/<your-example>.ts
# run the example against your api
yarn tsn -T examples/<your-example>.ts
$ yarn tsn -T examples/<your-example>.ts
```

## Using the repository from source
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://git@github.com:stainless-sdks/llama-stack-node.git
```sh
$ npm install git+ssh://git@github.com:stainless-sdks/llama-stack-node.git
```

Alternatively, to link a local copy of the repo:

```bash
```sh
# Clone
git clone https://www.github.com/stainless-sdks/llama-stack-node
cd llama-stack-node
$ git clone https://www.github.com/stainless-sdks/llama-stack-node
$ cd llama-stack-node

# With yarn
yarn link
cd ../my-package
yarn link llama-stack-client
$ yarn link
$ cd ../my-package
$ yarn link llama-stack-client

# With pnpm
pnpm link --global
cd ../my-package
pnpm link -—global llama-stack-client
$ pnpm link --global
$ cd ../my-package
$ pnpm link -—global llama-stack-client
```

## 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,26 +82,12 @@ 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

Changes made to this repository via the automated release PR pipeline should publish to npm automatically. If
the changes aren't made through the automated pipeline, you may want to make releases manually.

### Publish with a GitHub workflow

You can release to package managers by using [the `Publish NPM` GitHub action](https://www.github.com/stainless-sdks/llama-stack-node/actions/workflows/publish-npm.yml). This requires a setup organization or repository secret to be set up.

### Publish manually

If you need to manually release a package, you can run the `bin/publish-npm` script with an `NPM_TOKEN` set on
the environment.
33 changes: 17 additions & 16 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
MIT License

Copyright (c) 2024 Meta Platforms, Inc. and affiliates
Copyright (c) Meta Platforms, Inc. and affiliates

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
84 changes: 59 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Llama Stack Client Node API Library
# Llama Stack Client TypeScript and JavaScript API Library

[![NPM version](https://img.shields.io/npm/v/llama-stack-client.svg)](https://npmjs.org/package/llama-stack-client) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/llama-stack-client) [![Discord](https://img.shields.io/discord/1257833999603335178)](https://discord.gg/llama-stack)

This library provides convenient access to the Llama Stack Client REST API from server-side TypeScript or JavaScript.

The REST API documentation can be found on [llama-stack](https://github.com/meta-llama/llama-stack/blob/main/docs/resources/llama-stack-spec.html). The full API of this library can be found in [api.md](api.md).
The REST API documentation can be found on [https://llama-stack.readthedocs.io/en/latest/references/api_reference/index.html](https://llama-stack.readthedocs.io/en/latest/references/api_reference/index.html). The full API of this library can be found in [api.md](api.md).

It is generated with [Stainless](https://www.stainlessapi.com/).

Expand All @@ -14,7 +14,6 @@ It is generated with [Stainless](https://www.stainlessapi.com/).
npm install llama-stack-client
```


## Usage

The full API of this library can be found in [api.md](api.md).
Expand All @@ -24,18 +23,40 @@ The full API of this library can be found in [api.md](api.md).
import LlamaStackClient from 'llama-stack-client';

const client = new LlamaStackClient({
environment: 'sandbox', // defaults to 'production'
baseURL: 'http://localhost:8321'
});

async function main() {
const session = await client.agents.sessions.create({ agent_id: 'agent_id', session_name: 'session_name' });
const models = await client.models.list();

console.log(session.session_id);
console.log(models);
}

main();
```

## Streaming responses

We provide support for streaming responses using Server Sent Events (SSE).

```ts
import LlamaStackClient from 'llama-stack-client';

const client = new LlamaStackClient();

const stream = await client.inference.chatCompletion({
messages: [{ content: 'string', role: 'user' }],
model_id: 'meta-llama/Llama-3.2-3B-Instruct',
stream: true,
});
for await (const inferenceChatCompletionResponse of stream) {
process.stdout.write(inferenceChatCompletionResponse.event.delta.text || '');
}
```

If you need to cancel a stream, you can `break` from the loop
or call `stream.controller.abort()`.

### Request & Response types

This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:
Expand All @@ -44,16 +65,16 @@ This library includes TypeScript definitions for all request params and response
```ts
import LlamaStackClient from 'llama-stack-client';

const client = new LlamaStackClient({
environment: 'sandbox', // defaults to 'production'
});
const client = new LlamaStackClient();

async function main() {
const params: LlamaStackClient.Agents.SessionCreateParams = {
agent_id: 'agent_id',
session_name: 'session_name',
const params: LlamaStackClient.InferenceChatCompletionParams = {
messages: [{ content: 'string', role: 'user' }],
model_id: 'model_id',
};
const session: LlamaStackClient.Agents.SessionCreateResponse = await client.agents.sessions.create(params);
const response: LlamaStackClient.InferenceChatCompletionResponse = await client.inference.chatCompletion(
params,
);
}

main();
Expand All @@ -70,8 +91,8 @@ a subclass of `APIError` will be thrown:
<!-- prettier-ignore -->
```ts
async function main() {
const session = await client.agents.sessions
.create({ agent_id: 'agent_id', session_name: 'session_name' })
const response = await client.inference
.chatCompletion({ messages: [{ content: 'string', role: 'user' }], model_id: 'model_id' })
.catch(async (err) => {
if (err instanceof LlamaStackClient.APIError) {
console.log(err.status); // 400
Expand Down Expand Up @@ -115,7 +136,7 @@ const client = new LlamaStackClient({
});

// Or, configure per-request:
await client.agents.sessions.create({ agent_id: 'agent_id', session_name: 'session_name' }, {
await client.inference.chatCompletion({ messages: [{ content: 'string', role: 'user' }], model_id: 'model_id' }, {
maxRetries: 5,
});
```
Expand All @@ -132,7 +153,7 @@ const client = new LlamaStackClient({
});

// Override per-request:
await client.agents.sessions.create({ agent_id: 'agent_id', session_name: 'session_name' }, {
await client.inference.chatCompletion({ messages: [{ content: 'string', role: 'user' }], model_id: 'model_id' }, {
timeout: 5 * 1000,
});
```
Expand All @@ -153,17 +174,17 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi
```ts
const client = new LlamaStackClient();

const response = await client.agents.sessions
.create({ agent_id: 'agent_id', session_name: 'session_name' })
const response = await client.inference
.chatCompletion({ messages: [{ content: 'string', role: 'user' }], model_id: 'model_id' })
.asResponse();
console.log(response.headers.get('X-My-Header'));
console.log(response.statusText); // access the underlying Response object

const { data: session, response: raw } = await client.agents.sessions
.create({ agent_id: 'agent_id', session_name: 'session_name' })
const { data: response, response: raw } = await client.inference
.chatCompletion({ messages: [{ content: 'string', role: 'user' }], model_id: 'model_id' })
.withResponse();
console.log(raw.headers.get('X-My-Header'));
console.log(session.session_id);
console.log(response);
```

### Making custom/undocumented requests
Expand Down Expand Up @@ -267,8 +288,8 @@ const client = new LlamaStackClient({
});

// Override per-request:
await client.agents.sessions.create(
{ agent_id: 'agent_id', session_name: 'session_name' },
await client.inference.chatCompletion(
{ messages: [{ content: 'string', role: 'user' }], model_id: 'model_id' },
{
httpAgent: new http.Agent({ keepAlive: false }),
},
Expand All @@ -280,7 +301,7 @@ await client.agents.sessions.create(
This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:

1. Changes that only affect static types, without breaking runtime behavior.
2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals)_.
2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_
3. Changes that we do not expect to impact the vast majority of users in practice.

We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
Expand All @@ -293,6 +314,19 @@ TypeScript >= 4.5 is supported.

The following runtimes are supported:

- Web browsers (Up-to-date Chrome, Firefox, Safari, Edge, and more)
- Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
- Deno v1.28.0 or higher.
- Bun 1.0 or later.
- Cloudflare Workers.
- Vercel Edge Runtime.
- Jest 28 or greater with the `"node"` environment (`"jsdom"` is not supported at this time).
- Nitro v2.6 or greater.

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).
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ or products provided by Llama Stack Client please follow the respective company'

### Llama Stack Client Terms and Policies

Please contact dev-feedback@llama-stack-client.com for any questions or concerns regarding security of our services.
Please contact llamastack@meta.com for any questions or concerns regarding security of our services.

---

Expand Down
Loading