diff --git a/packages/app/src/components/Port.tsx b/packages/app/src/components/Port.tsx index 3ac6255d5..6c3e2cd81 100644 --- a/packages/app/src/components/Port.tsx +++ b/packages/app/src/components/Port.tsx @@ -116,7 +116,11 @@ export const Port: FC<{ > {canDragTo &&
}
-
+
{title}
diff --git a/packages/cli/bin/cli.js b/packages/cli/bin/cli.js index e207f1811..1b6ff6dd1 100644 --- a/packages/cli/bin/cli.js +++ b/packages/cli/bin/cli.js @@ -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 [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 [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); + } } diff --git a/packages/core/src/integrations/openai/OpenAIEmbeddingGenerator.ts b/packages/core/src/integrations/openai/OpenAIEmbeddingGenerator.ts index 1e5c1e319..6989ec521 100644 --- a/packages/core/src/integrations/openai/OpenAIEmbeddingGenerator.ts +++ b/packages/core/src/integrations/openai/OpenAIEmbeddingGenerator.ts @@ -2,7 +2,7 @@ import { type Settings } from '../../index.js'; import { type EmbeddingGenerator } from '../EmbeddingGenerator.js'; import { OpenAI } from 'openai'; -type OpenAIOptions = Pick +type OpenAIOptions = Pick; export class OpenAIEmbeddingGenerator implements EmbeddingGenerator { readonly #settings; @@ -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; diff --git a/packages/core/src/model/nodes/GetEmbeddingNode.ts b/packages/core/src/model/nodes/GetEmbeddingNode.ts index ac4e1ec1d..308bf05f5 100644 --- a/packages/core/src/model/nodes/GetEmbeddingNode.ts +++ b/packages/core/src/model/nodes/GetEmbeddingNode.ts @@ -37,7 +37,7 @@ export class GetEmbeddingNodeImpl extends NodeImpl { integration: 'openai', useIntegrationInput: false, model: undefined, - dimensions: undefined + dimensions: undefined, }, }; } @@ -141,7 +141,7 @@ export class GetEmbeddingNodeImpl extends NodeImpl { const integrationName = this.data.useIntegrationInput ? coerceType(inputs['integration' as PortId], 'string') : this.data.integration; - + const model = this.data.useModelInput ? coerceType(inputs['model' as PortId], 'string') : this.data.model; const dimensions = this.data.useDimensionsInput