Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add experiment logging support for BrainTrust #49

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
705 changes: 442 additions & 263 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.
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.
16 changes: 16 additions & 0 deletions packages/app/src/components/trivet/TestSuite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ import {
} from '@ironclad/trivet';
import { trivetState } from '../../state/trivet';
import Button from '@atlaskit/button';

import { TryRunTests } from './api';
import { useOpenUrl } from '../../hooks/useOpenUrl';
import { ReactComponent as BrowserLineIcon } from 'majesticons/line/browser-line.svg';
import { ReactComponent as AlertCircleIcon } from 'majesticons/line/alert-circle-line.svg';
import { NoTestCasesSplash } from './NoTestCasesSplash';
import { useTestSuite } from '../../hooks/useTestSuite';
import { braintrustSummariesState } from '../../state/plugins/braintrust';
import { useIsPluginEnabled } from '../../hooks/useIsPluginEnabled';

const styles = css`
min-height: 100%;
Expand Down Expand Up @@ -135,6 +138,10 @@ export const TestSuiteRenderer: FC<{ tryRunTests: TryRunTests }> = ({ tryRunTest
export const TestSuite: FC<{ testSuite: TrivetTestSuite; tryRunTests: TryRunTests }> = ({ testSuite, tryRunTests }) => {
const [{ selectedTestSuiteId, editingTestCaseId, recentTestResults, runningTests }, setState] =
useRecoilState(trivetState);
const [{ brainTrustSummaries }, setBrainTrustSummariesState] = useRecoilState(braintrustSummariesState);

const brainTrustEnabled = useIsPluginEnabled('braintrust');

const savedGraphs = useRecoilValue(savedGraphsState);

const { addTestCase, updateTestSuite, testGraph, setEditingTestCase, deleteTestCase, duplicateTestCase } =
Expand Down Expand Up @@ -218,6 +225,7 @@ export const TestSuite: FC<{ testSuite: TrivetTestSuite; tryRunTests: TryRunTest
}, [testCaseValidationResults, testSuite, updateTestSuite]);

const viewDocumentation = useOpenUrl('https://rivet.ironcladapp.com/docs/trivet');
const brainTrustSummary = brainTrustEnabled && brainTrustSummaries?.[testSuite.id];

return (
<div css={styles}>
Expand Down Expand Up @@ -290,6 +298,14 @@ export const TestSuite: FC<{ testSuite: TrivetTestSuite; tryRunTests: TryRunTest
<Button appearance="primary" onClick={() => tryRunTests({ testSuiteIds: [testSuite.id] })}>
Run Test Suite
</Button>

{brainTrustSummary && (
<div style={{ marginLeft: 10 }}>
<Button appearance="primary" onClick={useOpenUrl(brainTrustSummary.experimentUrl)}>
View results in BrainTrust ({brainTrustSummary.experimentName})
</Button>
</div>
)}
</div>
<TestCaseTable
testCases={testSuite.testCases}
Expand Down
23 changes: 7 additions & 16 deletions packages/app/src/hooks/useBuiltInPlugins.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
import { plugins } from '@ironclad/rivet-core';
import { orderBy } from 'lodash-es';

const builtInPlugins = orderBy(
[
{
label: 'Anthropic',
value: 'anthropic',
},
{
label: 'AssemblyAI',
value: 'assemblyAi',
},
{
label: 'Autoevals',
value: 'autoevals',
},
] as const,
const pluginOptions = orderBy(
Object.entries(plugins).map(([id, plugin]) => ({
value: id,
label: plugin.name ?? plugin.id,
})),
'label',
);

export function useBuiltInPlugins() {
return builtInPlugins;
return pluginOptions;
}
8 changes: 8 additions & 0 deletions packages/app/src/hooks/useIsPluginEnabled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { BuiltInPluginID } from '@ironclad/rivet-core';
import { useDependsOnPlugins } from './useDependsOnPlugins';

export function useIsPluginEnabled(plugin: BuiltInPluginID): boolean {
const plugins = useDependsOnPlugins();

return plugins.some((p) => p.id === plugin);
}
19 changes: 19 additions & 0 deletions packages/app/src/hooks/useLocalExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { lastRecordingState, loadedRecordingState } from '../state/execution';
import { fillMissingSettingsFromEnvironmentVariables } from '../utils/tauri';
import { trivetState } from '../state/trivet';
import { runTrivet } from '@ironclad/trivet';
import { useDependsOnPlugins } from './useDependsOnPlugins';

export function useLocalExecutor() {
const project = useRecoilValue(projectState);
Expand Down Expand Up @@ -134,6 +135,8 @@ export function useLocalExecutor() {
},
);

const plugins = useDependsOnPlugins();

const tryRunTests = useStableCallback(
async (options: { testSuiteIds?: string[]; testCaseIds?: string[]; iterationCount?: number } = {}) => {
toast.info(
Expand All @@ -158,6 +161,7 @@ export function useLocalExecutor() {
}))
: testSuites;
try {
const settings = await fillMissingSettingsFromEnvironmentVariables(savedSettings, plugins);
const result = await runTrivet({
project,
iterationCount: options.iterationCount,
Expand All @@ -182,6 +186,21 @@ export function useLocalExecutor() {
inputs,
);
},
// braintrustApiKey: settings.braintrustApiKey,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the WIP section?

// setBrainTrustSummary: (id, summary) =>
// setTrivetState((s) => {
// let brainTrustSummaries = s.brainTrustSummaries;
// if (summary === undefined) {
// const { [id]: _, ...rest } = s.brainTrustSummaries || {};
// brainTrustSummaries = rest;
// } else {
// brainTrustSummaries = { ...s.brainTrustSummaries, [id]: summary };
// }
// return {
// ...s,
// brainTrustSummaries,
// };
// }),
});
setTrivetState((s) => ({
...s,
Expand Down
11 changes: 11 additions & 0 deletions packages/app/src/state/plugins/braintrust.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { BTExperimentSummary } from '@ironclad/trivet';
import { atom } from 'recoil';

export type BraintrustSummariesState = {
brainTrustSummaries?: Record<string, BTExperimentSummary>;
};

export const braintrustSummariesState = atom<BraintrustSummariesState>({
key: 'braintrustSummariesState',
default: {},
});
6 changes: 5 additions & 1 deletion packages/core/src/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import anthropicPlugin from './plugins/anthropic/index.js';
import autoevalsPlugin from './plugins/autoevals/index.js';
import assemblyAiPlugin from './plugins/assemblyAi/index.js';
import { braintrustPlugin } from './plugins/braintrust/plugin.js';

export { anthropicPlugin, autoevalsPlugin, assemblyAiPlugin };
export { anthropicPlugin, autoevalsPlugin, assemblyAiPlugin, braintrustPlugin };

export const plugins = {
anthropic: anthropicPlugin,
autoevals: autoevalsPlugin,
assemblyAi: assemblyAiPlugin,
braintrust: braintrustPlugin,
};

export type BuiltInPluginID = keyof typeof plugins;
Empty file.
16 changes: 16 additions & 0 deletions packages/core/src/plugins/braintrust/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { RivetPlugin } from '../../index.js';

export const braintrustPlugin: RivetPlugin = {
id: 'braintrust',
name: 'Braintrust',

configSpec: {
braintrustApiKey: {
type: 'secret',
label: 'Braintrust API Key',
description: 'API key for Braintrust',
pullEnvironmentVariable: 'BRAINTRUST_API_KEY',
helperText: 'Alternatively, set the BRAINTRUST_API_KEY environment variable',
},
},
};
2 changes: 2 additions & 0 deletions packages/trivet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
},
"dependencies": {
"@ironclad/rivet-core": "workspace:^",
"braintrust": "^0.0.41",
"eventemitter3": "^5.0.1",
"lodash-es": "^4.17.21",
"yaml": "^2.3.1"
},
Expand Down
Loading