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
4 changes: 4 additions & 0 deletions .github/workflows/.publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ on:
expectedVersion:
type: string
required: true
env:
type: string
default: npm

jobs:
publish:
runs-on: ubuntu-latest
environment: ${{ inputs.env }}

steps:
- uses: actions/checkout@v4
Expand Down
16 changes: 11 additions & 5 deletions .github/workflows/tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@ jobs:

splits:
runs-on: ubuntu-latest

steps:
- name: Set package and version
id: set_package_and_version
run: |
echo "PACKAGE=${TAG_NAME%%@*}" >> $GITHUB_ENV
echo "VERSION=${TAG_NAME#*@}" >> $GITHUB_ENV
echo "package=${TAG_NAME%%@*}" >> $GITHUB_OUTPUT
echo "version=${TAG_NAME#*@}" >> $GITHUB_OUTPUT
outputs:
package: ${{ steps.set_package_and_version.outputs.package }}
version: ${{ steps.set_package_and_version.outputs.version }}

publish:
needs: quality
needs: split
uses: ./.github/workflows/.publish.yml
secrets: inherit
with:
tag: latest
expectedVersion: ${{ env.VERSION }}
package: ${{ env.PACKAGE }}
expectedVersion: ${{ needs.split.outputs.version }}
package: ${{ needs.split.outputs.package }}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions packages/workflowai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Javascript / Typescript SDK for WorkflowAI

[![WorkflowAI](./examples/assets/readme-header.png)](https://workflowai.com)

[![npm version](https://img.shields.io/npm/v/@workflowai/workflowai.svg)](https://www.npmjs.com/package/@workflowai/workflowai)
[![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

## WorkflowAI

[WorkflowAI](https://workflowai.com) is a low-code tool for product managers and software engineers
that makes it easier to ship features powered by AI.

## Get Started

1. Go to [workflowai.com](https://workflowai.com).
2. Enter your company URL, and get suggestions of AI-powered features for your product.
3. Build your first AI features in a few minutes.
4. Then go to the **Code** section to copy the code generated for Typescript.

[![Code Section](./examples/assets/code-section.png)](https://workflowai.com/docs/agents/get-capital-info/1/code)

## Example Syntax

```ts
// Initialize WorkflowAI Client
import { WorkflowAI } from '@workflowai/workflowai';

const workflowAI = new WorkflowAI({
// optional, defaults to process.env.WORKFLOWAI_API_KEY
// key: // Add your API key here
});

// Initialize Your AI agent
export interface GetCapitalInfoInput {
city: string;
}

export interface GetCapitalInfoOutput {
country: string;
capital: string;
fun_fact: string;
}

const getCapitalInfo = workflowAI.agent<
GetCapitalInfoInput,
GetCapitalInfoOutput
>({
id: 'get-capital-info',
schemaId: 1,
version: '1.4',
// Cache options:
// - "auto" (default): if a previous run exists with the same version and input, and if
// the temperature is 0, the cached output is returned
// - "always": the cached output is returned when available, regardless
// of the temperature value
// - "never": the cache is never used
useCache: 'auto',
});

// Run Your AI agent
async function getCapitalInfoRun() {
const input: GetCapitalInfoInput = {
city: 'Wellington',
};

try {
const {
output,
data: { duration_seconds, cost_usd, version },
} = await getCapitalInfo(input);

console.log(output);
console.log('\nModel: ', version?.properties?.model);
console.log('Cost: $', cost_usd);
console.log('Latency: ', duration_seconds?.toFixed(2), 's');
} catch (error) {
console.error('Failed to run :', error);
}
}
```
2 changes: 1 addition & 1 deletion packages/workflowai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@workflowai/workflowai",
"version": "1.6.5",
"version": "1.6.6",
"type": "module",
"description": "WorkflowAI JS SDK",
"author": "WorkflowAI",
Expand Down
36 changes: 0 additions & 36 deletions packages/workflowai/src/api/README.md

This file was deleted.

6 changes: 5 additions & 1 deletion packages/workflowai/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ export type VersionProperties = Schema['TaskGroupProperties'];

export type VersionEnvironment = 'dev' | 'staging' | 'production';

export type VersionReference = VersionEnvironment | number | VersionProperties;
export type VersionReference =
| VersionEnvironment
| number
| string
| VersionProperties;

export type RunRequest = Schema['RunRequest'];

Expand Down
32 changes: 30 additions & 2 deletions tests/integration/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const run = workflowAI.agent<
>({
id: 'animal-classification',
schemaId: 4,
version: 43,
version: 'production',
});

describe('run', () => {
Expand Down Expand Up @@ -68,7 +68,35 @@ describe('run', () => {
expect(req.headers.get('Authorization')).toEqual('Bearer hello');
const body = await req.json();
expect(body).toEqual({
version: 43,
version: 'production',
stream: false,
task_input: {
animal: 'platypus',
},
use_cache: 'auto',
});
});
it('allows overriding the version by a semver semver', async () => {
const run1Fixture = await readFile(fixturePath('run1.json'), 'utf-8');
mockFetch.mockResponseOnce(run1Fixture);

const result = await run({ animal: 'platypus' }, { version: '1.4' });
expect(result.output).toEqual({
is_cute: true,
is_dangerous: true,
explanation_of_reasoning: 'Plat plat',
});

expect(mockFetch.mock.calls.length).toEqual(1);
const req = mockFetch.mock.calls[0][0] as Request;
expect(req.url).toEqual(
'https://run.workflowai.com/v1/_/agents/animal-classification/schemas/4/run'
);
expect(req.method).toEqual('POST');
expect(req.headers.get('Authorization')).toEqual('Bearer hello');
const body = await req.json();
expect(body).toEqual({
version: '1.4',
stream: false,
task_input: {
animal: 'platypus',
Expand Down