Skip to content

Commit

Permalink
Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangYiJiang committed Dec 11, 2024
1 parent 6ad9528 commit a7e8c39
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 95 deletions.
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
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);
}
}
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
4 changes: 2 additions & 2 deletions packages/core/src/model/nodes/GetEmbeddingNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class GetEmbeddingNodeImpl extends NodeImpl<GetEmbeddingNode> {
integration: 'openai',
useIntegrationInput: false,
model: undefined,
dimensions: undefined
dimensions: undefined,
},
};
}
Expand Down Expand Up @@ -141,7 +141,7 @@ export class GetEmbeddingNodeImpl extends NodeImpl<GetEmbeddingNode> {
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
Expand Down

0 comments on commit a7e8c39

Please sign in to comment.