Skip to content

Commit

Permalink
Merge branch 'main' into gogwilt/improve-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
abrenneke committed Dec 19, 2023
2 parents bf811a8 + 4dfb0aa commit e0be905
Show file tree
Hide file tree
Showing 41 changed files with 1,066 additions and 93 deletions.
3 changes: 2 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@
"avatar_url": "https://avatars.githubusercontent.com/u/50146659?v=4",
"profile": "https://reactgular.com",
"contributions": [
"code"
"code",
"doc"
]
}
],
Expand Down
239 changes: 177 additions & 62 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ If you have any bug reports, questions, ideas, or unexpected behavior feel free
- [volta](https://volta.sh/) or Node.js >=20
- [rust](https://rustup.rs/)
- [yarn](https://yarnpkg.com/getting-started/install)
- [macOS](https://www.apple.com/ca/macos/sonoma/) (Mac only) macOS 12.3 or higher

### Building and Running

Expand Down Expand Up @@ -68,3 +69,14 @@ Testing will also run linting at the same time.
Rivet uses [ESLint](https://eslint.org/) for linting and [Prettier](https://prettier.io/) for formatting. To run linting, run `yarn lint` in the root folder. This will run linting for all packages.

In VS Code, ESLint is configured to run automatically on save. We also recommend enabling the `Format on Save` option in VS Code to automatically format files with Prettier on save.

## Node Executor

Certain nodes need to run in the "Node Executor." This starts a "sidecar" process, which can be difficult to develop with. If you are developing a feature or plugin that requires the Node Executor, consider running the node executor directly:

```
cd packages/app-executor
yarn start --port 21889
```

This will reduce the build time. However, you will still need to restart the sidecar whenever you make a code change.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="https://github.com/bardia-pourvakil"><img src="https://avatars.githubusercontent.com/u/132475166?v=4?s=100" width="100px;" alt="bardia-pourvakil"/><br /><sub><b>bardia-pourvakil</b></sub></a><br /><a href="https://github.com/Ironclad/rivet/commits?author=bardia-pourvakil" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Cinerar"><img src="https://avatars.githubusercontent.com/u/120550?v=4?s=100" width="100px;" alt="Cinerar"/><br /><sub><b>Cinerar</b></sub></a><br /><a href="https://github.com/Ironclad/rivet/commits?author=Cinerar" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/vpckso"><img src="https://avatars.githubusercontent.com/u/40294053?v=4?s=100" width="100px;" alt="Kit"/><br /><sub><b>Kit</b></sub></a><br /><a href="https://github.com/Ironclad/rivet/commits?author=vpckso" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://reactgular.com"><img src="https://avatars.githubusercontent.com/u/50146659?v=4?s=100" width="100px;" alt="Nick Foscarini"/><br /><sub><b>Nick Foscarini</b></sub></a><br /><a href="https://github.com/Ironclad/rivet/commits?author=codemile" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://reactgular.com"><img src="https://avatars.githubusercontent.com/u/50146659?v=4?s=100" width="100px;" alt="Nick Foscarini"/><br /><sub><b>Nick Foscarini</b></sub></a><br /><a href="https://github.com/Ironclad/rivet/commits?author=codemile" title="Code">💻</a> <a href="https://github.com/Ironclad/rivet/commits?author=codemile" title="Documentation">📖</a></td>
</tr>
</tbody>
</table>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"eslint-plugin-react-hooks": "^4.6.0",
"rollup": "^4.1.4",
"ts-node": "^10.9.1",
"tsx": "^3.14.0",
"tsx": "^4.6.2",
"typescript": "^5.2.2",
"yargs": "^17.7.2",
"zx": "^7.2.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/app-executor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"eslint-plugin-promise": "^6.1.1",
"execa": "^8.0.1",
"pkg": "^5.8.1",
"tsx": "^3.14.0",
"tsx": "^4.6.2",
"type-fest": "^4.5.0",
"typescript": "^5.2.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,6 @@
"execa": "^8.0.1",
"rollup-plugin-visualizer": "^5.9.2",
"semver": "^7.5.4",
"tsx": "^3.14.0"
"tsx": "^4.6.2"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 20 additions & 2 deletions packages/app/src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import PineconeLogo from './assets/vendor_logos/pinecone-logo.png';
import OpenAILogo from './assets/vendor_logos/openai-white-logomark.svg';
import ChromaLogo from './assets/vendor_logos/chroma.svg';
import OllamaLogo from './assets/vendor_logos/ollama-logo.png';
import BraintrustLogo from './assets/vendor_logos/braintrust_data_logo.jpeg';
import PythonLogo from './assets/vendor_logos/Python-logo.svg.png';
import FolderLogo from './assets/vendor_logos/folder-icon.png';
import GoogleLogo from './assets/vendor_logos/google-logo.png';

type SharedPluginInfo = {
id: string;
Expand Down Expand Up @@ -48,7 +52,7 @@ export const pluginInfos: PluginInfo[] = [
author: 'Rivet Team',
package: 'rivet-plugin-example-python-exec',
tag: 'latest',
logoImage: RivetLogo,
logoImage: PythonLogo,
github: 'https://github.com/abrenneke/rivet-plugin-example-python-exec',
},
{
Expand All @@ -74,6 +78,7 @@ export const pluginInfos: PluginInfo[] = [
Adds an Autoevals node with many variants of evaluations.
`,
author: 'Braintrust',
logoImage: BraintrustLogo,
documentation: 'https://rivet.ironcladapp.com/docs/user-guide/plugins/built-in/autoevals',
},
{
Expand Down Expand Up @@ -181,7 +186,7 @@ export const pluginInfos: PluginInfo[] = [
author: 'Rivet Team',
package: 'rivet-plugin-fs',
tag: 'latest',
logoImage: RivetLogo,
logoImage: FolderLogo,
},
{
type: 'built-in',
Expand Down Expand Up @@ -221,4 +226,17 @@ export const pluginInfos: PluginInfo[] = [
tag: 'latest',
logoImage: OllamaLogo,
},
{
type: 'built-in',
id: 'google',
name: 'Google',
description: dedent`
Allows you to chat with Google LLM models such as Gemini.
Adds a Chat (Google) node.
`,
author: 'Rivet Team',
logoImage: GoogleLogo,
documentation: 'https://rivet.ironcladapp.com/docs/user-guide/plugins/built-in/google',
},
];
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-n": "^16.2.0",
"eslint-plugin-promise": "^6.1.1",
"tsx": "^3.14.0",
"tsx": "^4.6.2",
"typescript": "^5.2.2"
},
"volta": {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
},
"dependencies": {
"@gentrace/core": "^2.2.5",
"@google-cloud/vertexai": "^0.1.3",
"@huggingface/inference": "^2.6.4",
"assemblyai": "^4.0.0",
"autoevals": "^0.0.26",
Expand Down Expand Up @@ -85,7 +86,7 @@
"lodash": "^4.17.21",
"rimraf": "^5.0.5",
"ts-node": "^10.9.1",
"tsx": "^3.14.0",
"tsx": "^4.6.2",
"typescript": "^5.2.2"
},
"volta": {
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/model/nodes/CodeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { nodeDefinition } from '../NodeDefinition.js';

export type CodeNode = ChartNode<'code', CodeNodeData>;

const maskInput = (name: string) => name.trim().replace(/[^a-zA-Z0-9_]/g, '_');
const asValidNames = (names: string[]): string[] => Array(...new Set(names.map(maskInput))).filter(Boolean);

export type CodeNodeData = {
code: string;
inputNames: string | string[];
Expand Down Expand Up @@ -59,7 +62,7 @@ export class CodeNodeImpl extends NodeImpl<CodeNode> {
: [this.data.inputNames]
: [];

return inputNames.map((inputName) => {
return asValidNames(inputNames).map((inputName) => {
return {
type: 'any',
id: inputName.trim() as PortId,
Expand All @@ -77,7 +80,7 @@ export class CodeNodeImpl extends NodeImpl<CodeNode> {
: [this.data.outputNames]
: [];

return outputNames.map((outputName) => {
return asValidNames(outputNames).map((outputName) => {
return {
id: outputName.trim() as PortId,
title: outputName.trim(),
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { huggingFacePlugin } from './plugins/huggingface/plugin.js';
import pineconePlugin from './plugins/pinecone/index.js';
import gentracePlugin from './plugins/gentrace/index.js';
import { openAIPlugin } from './plugins/openai/plugin.js';
import { googlePlugin } from './plugins/google/plugin.js';

export { anthropicPlugin, autoevalsPlugin, assemblyAiPlugin, pineconePlugin, huggingFacePlugin, gentracePlugin };
export { anthropicPlugin, autoevalsPlugin, assemblyAiPlugin, pineconePlugin, huggingFacePlugin, gentracePlugin, googlePlugin };

export const plugins = {
anthropic: anthropicPlugin,
Expand All @@ -16,4 +17,5 @@ export const plugins = {
huggingFace: huggingFacePlugin,
gentrace: gentracePlugin,
openai: openAIPlugin,
google: googlePlugin
};
120 changes: 120 additions & 0 deletions packages/core/src/plugins/google/google.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
export type GoogleModel = {
maxTokens: number;
cost: {
prompt: number;
completion: number;
};
displayName: string;
};

export const googleModels = {
'gemini-pro': {
maxTokens: 32760,
cost: {
prompt: NaN,
completion: NaN,
},
displayName: 'Gemini Pro',
},
'gemini-pro-vision': {
maxTokens: 16384,
cost: {
prompt: NaN,
completion: NaN,
},
displayName: 'Gemini Pro Vision',
},
} satisfies Record<string, GoogleModel>;

export type GoogleModels = keyof typeof googleModels;

export const googleModelOptions = Object.entries(googleModels).map(([id, { displayName }]) => ({
value: id,
label: displayName,
}));

export interface GoogleChatMessage {
role: 'user' | 'assistant';
parts: ({
text: string;
} | {
inline_data: {
mime_type: string;
data: string;
};
})[]
}

export type ChatCompletionOptions = {
project: string;
location: string;
applicationCredentials: string;
model: GoogleModels;
prompt: GoogleChatMessage[];
max_output_tokens: number;
temperature?: number;
top_p?: number;
top_k?: number;
signal?: AbortSignal;
};

export type ChatCompletionChunk = {
completion: string;
finish_reason: 'FINISH_REASON_UNSPECIFIED' | 'FINISH_REASON_STOP' | 'FINISH_REASON_MAX_TOKENS' | 'FINISH_REASON_SAFETY' | 'FINISH_REASON_RECITATION' | 'FINISH_REASON_OTHER' | undefined;
model: string;
};

export async function* streamChatCompletions({
project,
location,
applicationCredentials,
model,
signal,
max_output_tokens,
temperature,
top_p,
top_k,
prompt,
}: ChatCompletionOptions): AsyncGenerator<ChatCompletionChunk> {
const defaultSignal = new AbortController().signal;

// If you import normally, the Google auth library throws a fit.
const { VertexAI } = await import('@google-cloud/vertexai');

// Can't find a way to pass the credentials path in
process.env['GOOGLE_APPLICATION_CREDENTIALS'] = applicationCredentials;
const vertexAi = new VertexAI({ project, location });
const generativeModel = vertexAi.preview.getGenerativeModel({
model,
generation_config: {
max_output_tokens,
temperature,
top_p,
top_k,
}
});
const response = await generativeModel.generateContentStream({
contents: prompt,
});

let hadChunks = false;

for await (const chunk of response.stream) {
console.log('streaming google responses')
hadChunks = true;

if (!signal?.aborted && chunk.candidates[0]?.content.parts[0]?.text) {
yield {
completion: chunk.candidates[0]?.content.parts[0]?.text,
finish_reason: chunk.candidates[0]?.finishReason as any,
model,
};
} else {
return;
}
}

if (!hadChunks) {
throw new Error(`No chunks received.`);
}
}
3 changes: 3 additions & 0 deletions packages/core/src/plugins/google/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { googlePlugin } from './plugin.js';

export default googlePlugin;
Loading

0 comments on commit e0be905

Please sign in to comment.