Skip to content

Commit

Permalink
Merge branch 'main' into aryamanagrawal/optional-traces
Browse files Browse the repository at this point in the history
  • Loading branch information
AryamanAgrawalIronclad committed Jan 7, 2025
2 parents 5f2c099 + c507a75 commit b862725
Show file tree
Hide file tree
Showing 25 changed files with 149 additions and 164 deletions.
5 changes: 3 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
es2021: true,
},
root: true,
extends: ['standard-with-typescript', 'plugin:react/recommended'],
extends: ['standard-with-typescript'],
plugins: ['import', '@typescript-eslint'],
overrides: [
{
Expand Down Expand Up @@ -52,7 +52,8 @@ module.exports = {
'prefer-const': 'error',
'eol-last': 'off',
'import/no-duplicates': 'error',
'import/no-cycle': 'error',
// TODO: Enable after fixing cycle in CallGraphNode -> globalRivetNodeRegistry
'import/no-cycle': 'warn',
'no-extra-boolean-cast': 'off',
'no-prototype-builtins': 'off',
'no-undef-init': 'off',
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ jobs:
NODE_OPTIONS: --max_old_space_size=6000
- name: Test
run: yarn test
- name: Lint
run: yarn lint
- name: Prettier
run: yarn prettier --check
38 changes: 2 additions & 36 deletions .pnp.cjs

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

6 changes: 5 additions & 1 deletion packages/app/src/components/Port.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ export const Port: FC<{
>
{canDragTo && <div className={clsx('port-hover-area')} />}
</div>
<div className={clsx("port-label", preservePortCase ? "" : "port-label-uppercase")} onMouseOver={handleMouseOver} onMouseOut={handleMouseOut}>
<div
className={clsx('port-label', preservePortCase ? '' : 'port-label-uppercase')}
onMouseOver={handleMouseOver}
onMouseOut={handleMouseOut}
>
{title}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
{
files: ['*.ts', '*.tsx'],
parserOptions: {
project: './packages/cli/tsconfig.json',
project: './tsconfig.json',
ecmaVersion: 'latest',
sourceType: 'module',
},
Expand Down
189 changes: 99 additions & 90 deletions packages/cli/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,99 +3,108 @@ import { resolve } from 'node:path';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
await yargs(hideBin(process.argv))
.command('run <projectFile> [graphName]', 'Run a graph in a project file, or the main graph if graphName is not specified.', (y) => y
.positional('projectFile', {
describe: 'The project file to run',
type: 'string',
demandOption: true,
})
.positional('graphName', {
describe: 'The name of the graph to run',
type: 'string',
})
.option('inputs-stdin', {
describe: 'Read inputs from stdin as JSON',
type: 'boolean',
default: false,
})
.option('include-cost', {
describe: 'Include the total cost in the output',
type: 'boolean',
default: false,
})
.option('context', {
describe: 'Adds a context value to the graph run',
type: 'string',
array: true,
default: [],
})
.option('input', {
describe: 'Adds an input to the graph run',
type: 'string',
array: true,
default: [],
}), (args) => run(args))
.demandCommand()
.parseAsync();
.command(
'run <projectFile> [graphName]',
'Run a graph in a project file, or the main graph if graphName is not specified.',
(y) =>
y
.positional('projectFile', {
describe: 'The project file to run',
type: 'string',
demandOption: true,
})
.positional('graphName', {
describe: 'The name of the graph to run',
type: 'string',
})
.option('inputs-stdin', {
describe: 'Read inputs from stdin as JSON',
type: 'boolean',
default: false,
})
.option('include-cost', {
describe: 'Include the total cost in the output',
type: 'boolean',
default: false,
})
.option('context', {
describe: 'Adds a context value to the graph run',
type: 'string',
array: true,
default: [],
})
.option('input', {
describe: 'Adds an input to the graph run',
type: 'string',
array: true,
default: [],
}),
(args) => run(args),
)
.demandCommand()
.parseAsync();
async function run(args) {
try {
const projectPath = resolve(process.cwd(), args.projectFile);
const project = await loadProjectFromFile(projectPath);
if (!args.graphName && !project.metadata.mainGraphId) {
const validGraphs = Object.values(project.graphs).map((graph) => [graph.metadata.id, graph.metadata.name]);
const validGraphNames = validGraphs.map(([id, name]) => `• "${name}" (${id})`);
console.error(`No graph name provided, and project does not specify a main graph. Valid graphs are: \n${validGraphNames.join('\n')}\n\n Use either the graph's name or its ID. For example, \`rivet run my-project.rivet-project my-graph\` or \`rivet run my-project.rivet-project 1234abcd\``);
process.exit(1);
}
let inputs = {};
if (args.inputsStdin) {
// Read json from stdin
const stdin = process.stdin;
stdin.setEncoding('utf8');
let input = '';
for await (const chunk of stdin) {
input += chunk;
}
try {
inputs = JSON.parse(input);
}
catch (err) {
console.error('Failed to parse input JSON');
console.error(err);
process.exit(1);
}
}
else {
inputs = Object.fromEntries(args.input.map((input) => {
const [key, value] = input.split('=');
if (!key || !value) {
console.error(`Invalid input value: ${input}`);
process.exit(1);
}
return [key, value];
}));
}
const contextValues = Object.fromEntries(args.context.map((context) => {
const [key, value] = context.split('=');
if (!key || !value) {
console.error(`Invalid context value: ${context}`);
process.exit(1);
}
return [key, value];
}));
const { run } = createProcessor(project, {
graph: args.graphName,
inputs,
context: contextValues,
});
const outputs = await run();
if (!args.includeCost) {
delete outputs.cost;
}
console.log(outputs);
try {
const projectPath = resolve(process.cwd(), args.projectFile);
const project = await loadProjectFromFile(projectPath);
if (!args.graphName && !project.metadata.mainGraphId) {
const validGraphs = Object.values(project.graphs).map((graph) => [graph.metadata.id, graph.metadata.name]);
const validGraphNames = validGraphs.map(([id, name]) => `• "${name}" (${id})`);
console.error(
`No graph name provided, and project does not specify a main graph. Valid graphs are: \n${validGraphNames.join('\n')}\n\n Use either the graph's name or its ID. For example, \`rivet run my-project.rivet-project my-graph\` or \`rivet run my-project.rivet-project 1234abcd\``,
);
process.exit(1);
}
catch (err) {
let inputs = {};
if (args.inputsStdin) {
// Read json from stdin
const stdin = process.stdin;
stdin.setEncoding('utf8');
let input = '';
for await (const chunk of stdin) {
input += chunk;
}
try {
inputs = JSON.parse(input);
} catch (err) {
console.error('Failed to parse input JSON');
console.error(err);
process.exit(1);
}
} else {
inputs = Object.fromEntries(
args.input.map((input) => {
const [key, value] = input.split('=');
if (!key || !value) {
console.error(`Invalid input value: ${input}`);
process.exit(1);
}
return [key, value];
}),
);
}
const contextValues = Object.fromEntries(
args.context.map((context) => {
const [key, value] = context.split('=');
if (!key || !value) {
console.error(`Invalid context value: ${context}`);
process.exit(1);
}
return [key, value];
}),
);
const { run } = createProcessor(project, {
graph: args.graphName,
inputs,
context: contextValues,
});
const outputs = await run();
if (!args.includeCost) {
delete outputs.cost;
}
console.log(outputs);
} catch (err) {
console.error(err);
process.exit(1);
}
}
3 changes: 2 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@ironclad/rivet-cli",
"license": "MIT",
"repository": "https://github.com/ironclad/rivet",
"version": "1.20.0",
"version": "1.20.1",
"src": "bin/cli.ts",
"bin": {
"rivet": "bin/cli.js"
Expand All @@ -26,6 +26,7 @@
},
"devDependencies": {
"@types/yargs": "^17.0.29",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"eslint": "^8.52.0",
"eslint-config-standard-with-typescript": "^39.1.1",
"eslint-plugin-import": "^2.29.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@ironclad/rivet-core",
"license": "MIT",
"repository": "https://github.com/ironclad/rivet",
"version": "1.20.0",
"version": "1.20.1",
"packageManager": "[email protected]",
"main": "dist/cjs/bundle.cjs",
"module": "dist/esm/index.js",
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/api/createProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { getProcessorEvents, getProcessorSSEStream, getSingleNodeStream } from '
import { GraphProcessor } from '../model/GraphProcessor.js';

Check warning on line 19 in packages/core/src/api/createProcessor.ts

View workflow job for this annotation

GitHub Actions / build

Dependency cycle via ./Nodes.js:36=>./nodes/CallGraphNode.js:210

Check warning on line 19 in packages/core/src/api/createProcessor.ts

View workflow job for this annotation

GitHub Actions / build

Dependency cycle via ./Nodes.js:36=>./nodes/CallGraphNode.js:210
import { deserializeProject } from '../utils/serialization/serialization.js';
import { DEFAULT_CHAT_NODE_TIMEOUT } from '../utils/defaults.js';
import type { Tokenizer } from '../integrations/Tokenizer.js';

export type LooseDataValue = DataValue | string | number | boolean;

Expand All @@ -39,6 +40,7 @@ export type RunGraphOptions = {
registry?: NodeRegistration;
includeTrace?: boolean;
getChatNodeEndpoint?: ProcessContext['getChatNodeEndpoint'];
tokenizer?: Tokenizer;
} & {
[P in keyof ProcessEvents as `on${PascalCase<P>}`]?: (params: ProcessEvents[P]) => void;
} & Settings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type Settings } from '../../index.js';
import { type EmbeddingGenerator } from '../EmbeddingGenerator.js';
import { OpenAI } from 'openai';

type OpenAIOptions = Pick<OpenAI.EmbeddingCreateParams, 'model' | 'dimensions' >
type OpenAIOptions = Pick<OpenAI.EmbeddingCreateParams, 'model' | 'dimensions'>;

export class OpenAIEmbeddingGenerator implements EmbeddingGenerator {
readonly #settings;
Expand All @@ -21,7 +21,7 @@ export class OpenAIEmbeddingGenerator implements EmbeddingGenerator {
const response = await api.embeddings.create({
input: text,
model: options?.model ?? 'text-embedding-ada-002',
dimensions: options?.dimensions
dimensions: options?.dimensions,
});

const embeddings = response.data;
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/model/GraphProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ export class GraphProcessor {
if (this.runToNodeIds) {
const dependencyNodes = this.getDependencyNodesDeep(node.id);

if (this.runToNodeIds.some((runTo) => runTo != node.id && dependencyNodes.includes(runTo))) {
if (this.runToNodeIds.some((runTo) => runTo !== node.id && dependencyNodes.includes(runTo))) {
if(this.#includeTrace){

Check failure on line 934 in packages/core/src/model/GraphProcessor.ts

View workflow job for this annotation

GitHub Actions / build

Expected space(s) after "if"

Check failure on line 934 in packages/core/src/model/GraphProcessor.ts

View workflow job for this annotation

GitHub Actions / build

Expected space(s) after "if"
this.#emitter.emit('trace', `Node ${node.title} is excluded due to runToNodeIds`);
}
Expand Down Expand Up @@ -1553,6 +1553,7 @@ export class GraphProcessor {
processor.on('graphStart', (e) => this.#emitter.emit('graphStart', e));
processor.on('graphFinish', (e) => this.#emitter.emit('graphFinish', e));
processor.on('globalSet', (e) => this.#emitter.emit('globalSet', e));
processor.on('newAbortController', (e) => this.#emitter.emit('newAbortController', e));
processor.on('pause', () => {
if (!this.#isPaused) {
this.pause();
Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/model/Nodes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type { ChartNode } from './NodeBase.js';
import { NodeRegistration } from './NodeRegistration.js';
import type { NodeImpl } from './NodeImpl.js';

import { userInputNode } from './nodes/UserInputNode.js';
export * from './nodes/UserInputNode.js';
Expand Down Expand Up @@ -218,8 +216,6 @@ export * from './nodes/DelegateFunctionCallNode.js';
import { playAudioNode } from './nodes/PlayAudioNode.js';
export * from './nodes/PlayAudioNode.js';

export * from './nodes/CallGraphNode.js';

export const registerBuiltInNodes = (registry: NodeRegistration) => {
return registry
.register(toYamlNode)
Expand Down
Loading

0 comments on commit b862725

Please sign in to comment.