Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(weave_ts): Add initial JS SDK #2704

Merged
merged 247 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
247 commits
Select commit Hold shift + click to select a range
c01dcfb
Working auth/init/op and call trace/parent tracking
shawnlewis Aug 30, 2024
62793cb
openai integration
shawnlewis Aug 30, 2024
8e5d3f7
Correctly name openai.chat.completions.create op name
shawnlewis Aug 30, 2024
8bef86d
Use batch call logging endpoint
shawnlewis Aug 30, 2024
f72a508
AI generated README
shawnlewis Aug 30, 2024
c03a2a4
Fix package build
shawnlewis Aug 30, 2024
dd3b361
Update README, build, console.logs
shawnlewis Aug 30, 2024
c0e5bea
Initialize entity name from wandb SDK
shawnlewis Aug 30, 2024
c16308b
Include version in UserAgent headers
shawnlewis Aug 30, 2024
d193d95
Bump to 0.6.3
shawnlewis Aug 30, 2024
2aee76a
Small README updates
shawnlewis Aug 30, 2024
f79be82
Include version info in call attributes
shawnlewis Aug 31, 2024
5d8b2f6
Package 0.6.4
shawnlewis Aug 31, 2024
7670a03
Push README update
shawnlewis Aug 31, 2024
9804f48
Rename server APis
shawnlewis Aug 31, 2024
a97c2ff
Remove unused stuff
shawnlewis Aug 31, 2024
f71ded0
add jest test
shawnlewis Aug 31, 2024
db48d96
Fix concurrency issues
shawnlewis Aug 31, 2024
8dec781
0.6.5
shawnlewis Aug 31, 2024
0126350
Token usage tracking for openai op
shawnlewis Aug 31, 2024
dff73f4
Summary rollup
shawnlewis Aug 31, 2024
7994563
make openai mock and use it in test
shawnlewis Aug 31, 2024
7fa7715
Respect include usage and add mock test
shawnlewis Aug 31, 2024
cd07cb5
Change function calls in mock a little
shawnlewis Aug 31, 2024
41d56c1
Factor out openai op wrapper
shawnlewis Aug 31, 2024
9e76dbb
Fix flake
shawnlewis Aug 31, 2024
5134010
Handle streaming in OpenAI API. Almost
shawnlewis Aug 31, 2024
c996fe6
Fix openai streaming case
shawnlewis Aug 31, 2024
0f0f672
Update readme and tweak line order
shawnlewis Aug 31, 2024
f3138d2
Refactor to have global Client object
shawnlewis Aug 31, 2024
cb26500
Lets call it WeaveClient instead
shawnlewis Aug 31, 2024
7926a19
Working on adding image support
shawnlewis Aug 31, 2024
a6ba91e
Image handling, work with openai.images.generate
shawnlewis Aug 31, 2024
4d8725e
Rename to wrapOpenAI
shawnlewis Aug 31, 2024
ea9f37a
Async saving for images / files
shawnlewis Sep 1, 2024
d2a5a50
projectName -> projectId
shawnlewis Sep 1, 2024
8c67d2b
Update README
shawnlewis Sep 1, 2024
e4e2113
JS v0.6.6
shawnlewis Sep 1, 2024
0169d12
Typo / clean
shawnlewis Sep 1, 2024
0b7b438
Basic op saving working.
shawnlewis Sep 1, 2024
3cbc061
Update README
shawnlewis Sep 1, 2024
d72c4f9
Start to add Evaluation, build ts examples
shawnlewis Sep 1, 2024
6da994f
Refactor Op into file, fix tests
shawnlewis Sep 1, 2024
2e5a39c
recursive object saving
shawnlewis Sep 1, 2024
9223155
Refactoring op/clientApi interface
shawnlewis Sep 2, 2024
73b38dc
Clean up test logging. Add some comments. Move some things.
shawnlewis Sep 2, 2024
1eda389
Remove unnecessary object wrapper from callstack
shawnlewis Sep 2, 2024
67d73da
Define type for CallStackEntry
shawnlewis Sep 2, 2024
a890922
Factor out CallStack class and simplify
shawnlewis Sep 2, 2024
74b1853
Make asyncStorage private
shawnlewis Sep 2, 2024
e358563
Move more stuff into client
shawnlewis Sep 2, 2024
475d369
Move more processing into WeaveClient
shawnlewis Sep 2, 2024
9832ed8
remove unused line
shawnlewis Sep 2, 2024
eece090
Move netrc stuff to settings.ts
shawnlewis Sep 2, 2024
cfa3d12
Reorganize weaveClient, weaveInit, media
shawnlewis Sep 2, 2024
834e305
Print call log
shawnlewis Sep 2, 2024
443d871
Privatize
shawnlewis Sep 2, 2024
6db8a7b
Remove unnecessary function
shawnlewis Sep 2, 2024
b5e70d4
Move ObjectRef
shawnlewis Sep 2, 2024
fa73e33
Fully async logging
shawnlewis Sep 2, 2024
f5a718c
Match python evaluation
shawnlewis Sep 2, 2024
a4198d2
Eval summary and log parameter names
shawnlewis Sep 2, 2024
e5b761d
Split out dataset and evaluation, fix tests
shawnlewis Sep 2, 2024
7046434
Handle eval model errors
shawnlewis Sep 2, 2024
271ba51
Parallel evaluation
shawnlewis Sep 2, 2024
6215d0d
Eval example in README
shawnlewis Sep 2, 2024
01795a0
Save Dataset.rows as Table
shawnlewis Sep 3, 2024
89c22d3
Pass frontend's Dataset check
shawnlewis Sep 3, 2024
9566463
Eval progress bar
shawnlewis Sep 3, 2024
a851c3b
Images in datasets works
shawnlewis Sep 3, 2024
5769c50
Don't need saveMedia, simplify
shawnlewis Sep 3, 2024
247f26e
Remove unnecessary processFileQueue
shawnlewis Sep 3, 2024
616ac33
Full working dataset row ref tracking
shawnlewis Sep 3, 2024
97f5cba
Don't try to summarize images
shawnlewis Sep 3, 2024
3de6064
Concurrency limit, fix parallel table saving bug
shawnlewis Sep 3, 2024
5129771
Fix tests
shawnlewis Sep 3, 2024
123d218
Parameter naming control
shawnlewis Sep 3, 2024
71e1628
Disable pLimit, can't build module in yet
shawnlewis Sep 3, 2024
9a9364d
JS v0.6.7
shawnlewis Sep 3, 2024
a43e5fc
Use our own concurrency limiter
shawnlewis Sep 3, 2024
cb1c74b
Lift params for eval
shawnlewis Sep 3, 2024
1a63e0f
Lift params for eval
shawnlewis Sep 3, 2024
a52d6f6
Read WANDB_API_KEY env var. Better error message
shawnlewis Sep 4, 2024
45758a8
JS v0.6.8
shawnlewis Sep 4, 2024
a55b4f3
Fixes: export boundOp. Don't rely on obj.className(), use javascript …
shawnlewis Sep 16, 2024
4a3f355
Eval fixes (print errors and more), obj id/description fixes
shawnlewis Sep 19, 2024
7b5636a
Automatically pick up model attributes
shawnlewis Sep 19, 2024
9d17dd0
Typesafe Dataset, Eval, Op!
shawnlewis Sep 19, 2024
4c07a82
Fix eval bugs, better types, op callDisplayName option
shawnlewis Sep 21, 2024
a2b0f54
invoke instead of run
shawnlewis Sep 21, 2024
1394a48
Fix summary rollup missing bug, and issue with wrapOpenAI type
shawnlewis Sep 22, 2024
b1d7372
update package lock
shawnlewis Sep 23, 2024
931d7c2
Fix openai integration for beta API
shawnlewis Sep 24, 2024
b917895
Fix openai op names
shawnlewis Sep 24, 2024
a1b7990
Retries, client patching fixes
shawnlewis Sep 26, 2024
154eb2a
Fix tests, change scorer to receive obj
shawnlewis Sep 27, 2024
31e813e
Fix exmaples for latest changes
shawnlewis Sep 27, 2024
01b3dc0
Fix dataset row ref issues.
shawnlewis Sep 28, 2024
cec1c95
Rollup summary on exception and API for getting child summary
shawnlewis Oct 4, 2024
7224568
add prettier
andrewtruong Oct 7, 2024
94c5605
apply fmt
andrewtruong Oct 7, 2024
74cb4ec
add constants
andrewtruong Oct 7, 2024
187dedf
add fn
andrewtruong Oct 7, 2024
e4899d2
simplify opWrapper func
andrewtruong Oct 7, 2024
43fdeb0
cleanup CallStack
andrewtruong Oct 7, 2024
64f5227
add tsx
andrewtruong Oct 7, 2024
bcb1c4a
add source map
andrewtruong Oct 7, 2024
62935f6
tidy tsconfig
andrewtruong Oct 10, 2024
b6a9562
move under sdks/node/
andrewtruong Oct 11, 2024
581edd9
wip
andrewtruong Oct 11, 2024
7a1782a
fix dataset example
andrewtruong Oct 11, 2024
006a571
also format examples
andrewtruong Oct 11, 2024
26a3345
format examples
andrewtruong Oct 11, 2024
94245c5
ts-ify examples
andrewtruong Oct 11, 2024
6ac736b
packaging
andrewtruong Oct 11, 2024
bbca36d
add dev notes
andrewtruong Oct 11, 2024
096018e
add swagger typescript api
andrewtruong Oct 11, 2024
3caf073
add new generated api
andrewtruong Oct 11, 2024
f0aa838
fmt
andrewtruong Oct 11, 2024
5f6a782
cleanup
andrewtruong Oct 11, 2024
1d2abd7
tidy
andrewtruong Oct 11, 2024
ab171fa
fmt
andrewtruong Oct 11, 2024
f0a00af
simplify openai
andrewtruong Oct 11, 2024
1be5a3d
temp: add testing tools
andrewtruong Oct 11, 2024
c5d1e64
move user agent
andrewtruong Oct 11, 2024
04bbc6d
move server api to generated
andrewtruong Oct 11, 2024
1cb89e1
concurrentLimit -> utils
andrewtruong Oct 11, 2024
0d7e7f9
wandbServerApi -> wandbInterface
andrewtruong Oct 11, 2024
565b871
testApi -> examples
andrewtruong Oct 11, 2024
5ed2952
retry -> utils
andrewtruong Oct 11, 2024
e660f8c
add note on inMemoryTraceServer
andrewtruong Oct 11, 2024
87a8cab
simplify asynciterator
andrewtruong Oct 11, 2024
a8ae16a
add note
andrewtruong Oct 11, 2024
5bfb4c8
wandbInterface -> wandb
andrewtruong Oct 11, 2024
af7cb47
tidy
andrewtruong Oct 11, 2024
2e9a486
note about tsi
andrewtruong Oct 11, 2024
c477175
add bootstrap
andrewtruong Oct 12, 2024
fcf34c2
tidy fn
andrewtruong Oct 14, 2024
72a96f6
add node tests in ci
andrewtruong Oct 14, 2024
c0a4eb3
add note on missing extras field
andrewtruong Oct 14, 2024
54e567d
add note on refs
andrewtruong Oct 14, 2024
983ee77
row -> getRow
andrewtruong Oct 14, 2024
f2f3f72
Runnable -> Callable
andrewtruong Oct 14, 2024
3452fd9
update media type
andrewtruong Oct 15, 2024
7475bdf
moving code closer to where it's used
andrewtruong Oct 15, 2024
39a5212
settings -> wandb/settings
andrewtruong Oct 15, 2024
1c5da0f
simplify op name
andrewtruong Oct 15, 2024
d142ee7
add watch
andrewtruong Oct 15, 2024
9c74c6e
tidy digest
andrewtruong Oct 15, 2024
988f902
itemPromiseMap -> inProgressTasks
andrewtruong Oct 15, 2024
23491f8
simplify op check
andrewtruong Oct 15, 2024
9b8cea2
update pkg config
andrewtruong Oct 15, 2024
b26eb85
tidy
andrewtruong Oct 16, 2024
d6245b9
predict_and_score -> predictAndScore
andrewtruong Oct 16, 2024
2e1810c
tests
andrewtruong Oct 16, 2024
3b1d144
add coverage
andrewtruong Oct 20, 2024
7e220e3
add util tests
andrewtruong Oct 20, 2024
0c3270c
add wandb tests
andrewtruong Oct 20, 2024
412a54c
add table test
andrewtruong Oct 20, 2024
bb4ef33
add digest tests
andrewtruong Oct 20, 2024
91110b4
add weaveObject tests
andrewtruong Oct 20, 2024
f97c081
update clientApi
andrewtruong Oct 20, 2024
9af62af
add dataset tests
andrewtruong Oct 20, 2024
219ff9d
simplify wandbServerApi
andrewtruong Oct 20, 2024
ffd09df
fix clientApi tests
andrewtruong Oct 20, 2024
bd5c6b6
fix digest
andrewtruong Oct 20, 2024
a93c45e
tidy
andrewtruong Oct 20, 2024
b3f056d
client tidying
andrewtruong Oct 20, 2024
0bae642
settings
andrewtruong Oct 21, 2024
455a65a
cleanup
andrewtruong Oct 21, 2024
d08093f
add basic eval mapping
andrewtruong Oct 21, 2024
1623080
update evals
andrewtruong Oct 21, 2024
db06b3d
add functionParsing tests
andrewtruong Oct 21, 2024
fe13989
add more init options
andrewtruong Oct 21, 2024
6ed5813
tighten init
andrewtruong Oct 21, 2024
b7f1629
fn parsing
andrewtruong Oct 22, 2024
c7bf2b5
update fn
andrewtruong Oct 22, 2024
e69856c
cleanup examples
andrewtruong Oct 22, 2024
45feef8
update fn
andrewtruong Oct 22, 2024
23c16e5
add audio
andrewtruong Oct 22, 2024
4a87afb
startCall -> createCall
andrewtruong Oct 22, 2024
d4570ca
options for other urls
andrewtruong Oct 23, 2024
466c14d
add loadtesting
andrewtruong Oct 23, 2024
b75583a
make exceptions work
andrewtruong Oct 23, 2024
dfd2a28
loadtest
andrewtruong Oct 23, 2024
bf14018
op docs
andrewtruong Oct 24, 2024
f1328ec
add optional code formatting with prettier
andrewtruong Oct 24, 2024
74cfefd
add login
andrewtruong Oct 24, 2024
414b47f
add no-init warning
andrewtruong Oct 24, 2024
110f016
simplify urls
andrewtruong Oct 24, 2024
e759917
simplify init
andrewtruong Oct 24, 2024
dcee877
add init and login docs
andrewtruong Oct 24, 2024
ad8aa2f
no format code
andrewtruong Oct 24, 2024
594aa97
tidy media
andrewtruong Oct 24, 2024
f54c249
tidy eval
andrewtruong Oct 24, 2024
3567dc8
doc wrapOpenAI
andrewtruong Oct 24, 2024
ade5bb6
doc media
andrewtruong Oct 24, 2024
4ecb5b0
add automatic boundop
andrewtruong Oct 24, 2024
9ed8896
tidy
andrewtruong Oct 24, 2024
311eba9
fix test
andrewtruong Oct 24, 2024
be51ec7
update dev docs
andrewtruong Oct 24, 2024
d4d2c1d
init fix
andrewtruong Oct 24, 2024
c0b2fb3
fix eval
andrewtruong Oct 24, 2024
0ca9e8c
fix header
andrewtruong Oct 24, 2024
ff946be
hmm
andrewtruong Oct 24, 2024
22024af
update package
andrewtruong Oct 24, 2024
739916f
fix examples
andrewtruong Oct 24, 2024
936a28a
better netrc
andrewtruong Oct 24, 2024
fbb1402
cleanup fn
andrewtruong Oct 24, 2024
d378856
add media test
andrewtruong Oct 24, 2024
53499db
add login test
andrewtruong Oct 24, 2024
38bcdad
update examples
andrewtruong Oct 24, 2024
bef2a4d
fix urls
andrewtruong Oct 24, 2024
b2c490e
tidy examples
andrewtruong Oct 24, 2024
18c92c3
more tidying
andrewtruong Oct 24, 2024
587d1e2
add example with classes
andrewtruong Oct 24, 2024
c412ce7
add example with various datatypes
andrewtruong Oct 24, 2024
cd0f754
fixup evals
andrewtruong Oct 25, 2024
0794fd2
tidy settings
andrewtruong Oct 25, 2024
c6c3e76
tests
andrewtruong Oct 25, 2024
acf95a7
add saveArbitrary
andrewtruong Oct 25, 2024
1d41876
add publish
andrewtruong Oct 25, 2024
15cdef6
add basic get api
andrewtruong Oct 25, 2024
f86fe08
add func support
andrewtruong Oct 25, 2024
5abcbc5
more saving
andrewtruong Oct 25, 2024
4396aee
wip custom object get
andrewtruong Oct 25, 2024
ed15a72
fix tests
andrewtruong Oct 25, 2024
26a6e8d
rename Callable->Runnable and call->invoke
andrewtruong Oct 25, 2024
d1ad74e
update pkg
andrewtruong Oct 25, 2024
1d3003a
fix urls
andrewtruong Oct 25, 2024
841508a
update pkg
andrewtruong Oct 25, 2024
cbcbda0
fix netrc and urls
andrewtruong Oct 25, 2024
957e715
better error msg
andrewtruong Oct 25, 2024
426c52c
add getWandbConfigs
andrewtruong Oct 25, 2024
058a2eb
fix
andrewtruong Oct 25, 2024
52797d8
add imports
andrewtruong Oct 25, 2024
1056542
add getCalls
andrewtruong Oct 25, 2024
c70de50
bump
andrewtruong Oct 26, 2024
36945f3
fmt
andrewtruong Oct 28, 2024
a29d0f3
fix test
andrewtruong Oct 28, 2024
ac31a69
fix test
andrewtruong Oct 28, 2024
64208a2
tests
andrewtruong Oct 28, 2024
dca9aa2
test
andrewtruong Oct 28, 2024
079aa97
test
andrewtruong Oct 28, 2024
bd354ac
test
andrewtruong Oct 28, 2024
b377cd9
test
andrewtruong Oct 29, 2024
0e41b18
more tests
andrewtruong Oct 29, 2024
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
32 changes: 32 additions & 0 deletions .github/workflows/weave-node-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Node.js Tests

on:
push:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20]
steps:
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
run_install: false
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
cache-dependency-path: sdks/node/pnpm-lock.yaml
- name: Install dependencies
run: pnpm install
working-directory: sdks/node
- name: Run tests
run: pnpm test
working-directory: sdks/node
env:
WANDB_API_KEY: ${{ secrets.WANDB_API_KEY }}
2 changes: 2 additions & 0 deletions sdks/node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
coverage
16 changes: 16 additions & 0 deletions sdks/node/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"trailingComma": "es5",
"singleQuote": true,
"bracketSpacing": false,
"bracketSameLine": true,
"tabWidth": 2,
"arrowParens": "avoid",
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"options": {
"parser": "typescript"
}
}
]
}
Binary file added sdks/node/CantinaBand3.wav
Binary file not shown.
7 changes: 7 additions & 0 deletions sdks/node/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
install-pnpm:
curl -fsSL https://get.pnpm.io/install.sh | sh -

bootstrap: install-pnpm
pnpm env use --global 20
pnpm install
pnpm run generate-api
23 changes: 23 additions & 0 deletions sdks/node/README-DEV.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Working notes

1. Setup your env

```sh
make boostrap

pnpm install
pnpm link --global
pnpm link --global weave
```

2. Run tests

```sh
pnpm test
```

3. Format

```sh
pnpm format
```
202 changes: 202 additions & 0 deletions sdks/node/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
# Weave (Alpha)

Weave is a library for tracing and monitoring AI applications.

This is an Alpha release, APIs are extremely subject to change.

## Installation

You can install Weave via npm:

```bash
npm install weave
```

Ensure you have a wandb API key in ~/.netrc.

Like

```
machine api.wandb.ai
login user
password <wandb-api-key>
```

Get your wandb API key from [here](https://wandb.ai/authorize).

## Quickstart

Put this in a file called `predict.mjs`:

```javascript
import { OpenAI } from "openai";
import { init, op, wrapOpenAI } from "weave";

const openai = wrapOpenAI(new OpenAI());

async function extractDinos(input) {
const response = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
{
role: "user",
content: `In JSON format extract a list of 'dinosaurs', with their 'name', their 'common_name', and whether its 'diet' is a herbivore or carnivore: ${input}`,
},
],
});
return response.choices[0].message.content;
}
const extractDinosOp = op(extractDinos);

async function main() {
await init("weave-quickstart");
const result = await extractDinosOp(
"I watched as a Tyrannosaurus rex (T. rex) chased after a Triceratops (Trike), both carnivore and herbivore locked in an ancient dance. Meanwhile, a gentle giant Brachiosaurus (Brachi) calmly munched on treetops, blissfully unaware of the chaos below."
);
console.log(result);
}

main();
```

and then run

```
node predict.mjs
```

## Usage

### Initializing a Project

Before you can start tracing operations, you need to initialize a project. This sets up the necessary environment for trace collection.

```javascript
import { init } from "weave";

// Initialize your project with a unique project name
init("my-awesome-ai-project");
```

### Tracing Operations

You can trace specific operations using the `op` function. This function wraps your existing functions and tracks their execution.

```javascript
import { op } from "weave";

// Define a function you want to trace
async function myFunction(arg1, arg2) {
// Your function logic
return arg1 + arg2;
}

// Wrap the function with op to enable tracing
const tracedFunction = op(myFunction, "myFunction");

// Call the traced function
tracedFunction(5, 10);
```

### OpenAI Integration

Weave provides an integration with OpenAI, allowing you to trace API calls made to OpenAI's services seamlessly.

```javascript
import { wrapOpenAI } from "weave/integrations/openai";

// Create a patched instance of OpenAI
const openai = wrapOpenAI();

// Use the OpenAI instance as usual
openai.chat.completions.create({
model: "text-davinci-003",
prompt: 'Translate the following English text to French: "Hello, world!"',
max_tokens: 60,
});

// Weave tracks images too!
openai.images.generate({
prompt: "A cute baby sea otter",
n: 3,
size: "256x256",
response_format: "b64_json",
});
```

### Evaluations

```typescript
import { init, op, Dataset, Evaluation } from "weave";

async function main() {
await init("weavejsdev-eval6");
const ds = new Dataset({
id: "My Dataset",
description: "This is a dataset",
rows: [
{ name: "Alice", age: 25 },
{ name: "Bob", age: 30 },
{ name: "Charlie", age: 34 },
],
});
const evaluation = new Evaluation({
dataset: ds,
scorers: [
op(
(modelOutput: any, datasetItem: any) => modelOutput == datasetItem.age,
{ name: "isEqual" }
),
],
});

const model = op(async function myModel(input) {
return input.age;
});

const results = await evaluation.evaluate({ model });
console.log(JSON.stringify(results, null, 2));
}

main();
```

## Configuration

Weave reads API keys from the `.netrc` file located in your home directory. Ensure you have the required API keys configured for seamless integration and tracking.

```
machine api.wandb.ai
login user
password <wandb-api-key>
```

Get your wandb API key from [here](https://wandb.ai/authorize).

## License

This project is licensed under the Apaache2 License - see the [LICENSE](../LICENSE) file for details.

### Roadmap / TODO

- [x] Return token counts
- [x] Summary merging
- [x] Image support
- [x] Decide how to handle args in js, since they're not named
- [x] Make sure LLM streaming is handled
- [x] Op versioning / code capture
- [ ] Retry logic
- [ ] Handle other wandb backends (managed / self-hosted)
- [ ] Include system information in call attributes including package version.
- [x] Objects / Datasets / Models / Evaluations
- [ ] Ref tracking
- [ ] More integrations

## Known Issues

- [ ] openai choices > 1 and "tools" not handled (function works though)
- [ ] we always inject params.stream_options.include_usage in openai request, need to not send back usage chunk if user didn't ask for it.
- [ ] handle all openai.images.generate formats, and images in inputs.
- [ ] openai.images.generate token counts.
- [ ] if a streaming op with streamReducer returns its iterator instead of iterating within the op, summary rollups won't work.
- [ ] Decide what's in public interface (WeaveClient)
28 changes: 28 additions & 0 deletions sdks/node/examples/classesWithOps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import OpenAI from 'openai';
import * as weave from 'weave';

class ExampleModel {
private oaiClient: OpenAI;

constructor() {
this.oaiClient = weave.wrapOpenAI(new OpenAI());
this.invoke = weave.op(this, this.invoke);
}

async invoke(input: string) {
const response = await this.oaiClient.chat.completions.create({
model: 'gpt-4o',
messages: [{role: 'user', content: input}],
});
return response.choices[0].message.content;
}
}

async function main() {
await weave.init('examples');

const model = new ExampleModel();
await model.invoke('Tell me a joke');
}

main();
53 changes: 53 additions & 0 deletions sdks/node/examples/createDataset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import fs from 'fs';
import 'source-map-support/register';
import * as weave from 'weave';

const sentences = [
'There are many fruits that were found on the recently discovered planet Goocrux. There are neoskizzles that grow there, which are purple and taste like candy.',
'Pounits are a bright green color and are more savory than sweet.',
'Finally, there are fruits called glowls, which have a very sour and bitter taste which is acidic and caustic, and a pale orange tinge to them.',
];
const labels = [
{fruit: 'neoskizzles', color: 'purple', flavor: 'candy'},
{fruit: 'pounits', color: 'bright green', flavor: 'savory'},
{fruit: 'glowls', color: 'pale orange', flavor: 'sour and bitter'},
];
const logsPng = fs.readFileSync('logs.png');
const audioClip = fs.readFileSync('CantinaBand3.wav');
const examples = [
{
id: '0',
sentence: sentences[0],
target: labels[0],
image: weave.weaveImage({data: logsPng, imageType: 'png'}),
audio: weave.weaveAudio({data: audioClip, audioType: 'wav'}),
},
{
id: '1',
sentence: sentences[1],
target: labels[1],
image: weave.weaveImage({data: logsPng, imageType: 'png'}),
audio: weave.weaveAudio({data: audioClip, audioType: 'wav'}),
},
{
id: '2',
sentence: sentences[2],
target: labels[2],
image: weave.weaveImage({data: logsPng, imageType: 'png'}),
audio: weave.weaveAudio({data: audioClip, audioType: 'wav'}),
},
];

async function main() {
await weave.init('examples');
const ds = new weave.Dataset({
id: 'Fruit Dataset',
rows: examples,
});

ds.save();
const ref = await ds.__savedRef;
console.log(ref);
}

main();
Loading
Loading