Skip to content

Commit 5c3da79

Browse files
awkoyYaroslav Boiko
and
Yaroslav Boiko
authored
[OPIK-1237] Add new experiment Config env update (#1597)
* [OPIK-1237] fix duplicated os import * [OPIK-1237] remove env import section, put inside code directly instead * [OPIK-1237] revert config updates * [OPIK-1237] revert putConfig --------- Co-authored-by: Yaroslav Boiko <[email protected]>
1 parent 42cf185 commit 5c3da79

File tree

9 files changed

+85
-62
lines changed

9 files changed

+85
-62
lines changed

apps/opik-frontend/src/components/pages-shared/onboarding/ConfigureEnvCode/ConfigureEnvCode.tsx

-15
This file was deleted.

apps/opik-frontend/src/components/pages-shared/onboarding/ConfigureEnvCode/ConfigureEnvCodeCore.tsx

-19
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from "react";
2+
import usePluginsStore from "@/store/PluginsStore";
3+
import CreateExperimentCodeCore, {
4+
CreateExperimentCodeCoreProps,
5+
} from "./CreateExperimentCodeCore";
6+
7+
export type CreateExperimentCodeProps = Omit<
8+
CreateExperimentCodeCoreProps,
9+
"apiKey"
10+
>;
11+
const CreateExperimentCode: React.FC<CreateExperimentCodeProps> = (props) => {
12+
const CreateExperimentCode = usePluginsStore(
13+
(state) => state.CreateExperimentCode,
14+
);
15+
16+
if (CreateExperimentCode) {
17+
return <CreateExperimentCode {...props} />;
18+
}
19+
20+
return <CreateExperimentCodeCore {...props} />;
21+
};
22+
23+
export default CreateExperimentCode;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import CodeHighlighter from "@/components/shared/CodeHighlighter/CodeHighlighter";
2+
import { putConfigInCode } from "@/lib/formatCodeSnippets";
3+
import useAppStore from "@/store/AppStore";
4+
5+
export type CreateExperimentCodeCoreProps = {
6+
apiKey?: string;
7+
code: string;
8+
};
9+
const CreateExperimentCodeCore: React.FC<CreateExperimentCodeCoreProps> = ({
10+
apiKey,
11+
code,
12+
}) => {
13+
const workspaceName = useAppStore((state) => state.activeWorkspaceName);
14+
const { code: codeWithConfig } = putConfigInCode({
15+
code,
16+
workspaceName,
17+
apiKey,
18+
shouldMaskApiKey: true,
19+
});
20+
const { code: codeWithConfigToCopy } = putConfigInCode({
21+
code,
22+
workspaceName,
23+
apiKey,
24+
});
25+
26+
return (
27+
<CodeHighlighter data={codeWithConfig} copyData={codeWithConfigToCopy} />
28+
);
29+
};
30+
31+
export default CreateExperimentCodeCore;

apps/opik-frontend/src/components/pages/ExperimentsShared/AddExperimentDialog.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import SideDialog from "@/components/shared/SideDialog/SideDialog";
1010
import { SheetTitle } from "@/components/ui/sheet";
1111
import ApiKeyCard from "@/components/pages-shared/onboarding/ApiKeyCard/ApiKeyCard";
1212
import GoogleColabCard from "@/components/pages-shared/onboarding/GoogleColabCard/GoogleColabCard";
13-
import ConfigureEnvCode from "@/components/pages-shared/onboarding/ConfigureEnvCode/ConfigureEnvCode";
13+
import CreateExperimentCode from "@/components/pages-shared/onboarding/CreateExperimentCode/CreateExperimentCode";
1414

1515
export enum EVALUATOR_MODEL {
1616
equals = "equals",
@@ -197,8 +197,12 @@ const AddExperimentDialog: React.FunctionComponent<
197197

198198
const section3 =
199199
"" +
200-
`from opik import Opik
200+
`import os
201+
from opik import Opik
201202
from opik.evaluation import evaluate
203+
204+
# INJECT_OPIK_CONFIGURATION
205+
202206
${importString}
203207
client = Opik()
204208
dataset = client.get_dataset(name="${
@@ -334,13 +338,9 @@ eval_results = evaluate(
334338
</div>
335339
<CodeHighlighter data={section1} />
336340
<div className="comet-body-s mt-4 text-foreground-secondary">
337-
3. Configure your API key
338-
</div>
339-
<ConfigureEnvCode />
340-
<div className="comet-body-s mt-4 text-foreground-secondary">
341-
4. Create an Experiment
341+
3. Create an Experiment
342342
</div>
343-
<CodeHighlighter data={section3} />
343+
<CreateExperimentCode code={section3} />
344344
</div>
345345

346346
<div className="flex w-[250px] shrink-0 flex-col gap-6 self-start">

apps/opik-frontend/src/lib/formatCodeSnippets.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { BASE_API_URL } from "@/api/api";
44
export const OPIK_API_KEY_TEMPLATE = "# INJECT_OPIK_CONFIGURATION";
55
export const OPIK_HIGHLIGHT_LINE_TEMPLATE = " # HIGHLIGHTED_LINE";
66

7-
export const IMPORT_OS_TEMPLATE = "import os";
8-
97
export const buildApiKeyConfig = (
108
apiKey: string,
119
masked = false,
@@ -24,7 +22,7 @@ export const buildWorkspaceNameConfig = (
2422
}`;
2523

2624
export const buildOpikUrlOverrideConfig = (withHighlight = false) =>
27-
`${IMPORT_OS_TEMPLATE} \n os.environ["OPIK_URL_OVERRIDE"] = "${new URL(
25+
`os.environ["OPIK_URL_OVERRIDE"] = "${new URL(
2826
BASE_API_URL,
2927
window.location.origin,
3028
).toString()}${withHighlight ? OPIK_HIGHLIGHT_LINE_TEMPLATE : ""}"`;
@@ -55,7 +53,7 @@ export const getConfigCode = (
5553
withHighlight,
5654
);
5755

58-
return `${IMPORT_OS_TEMPLATE} \n${apiKeyConfig} \n${workspaceConfig}`;
56+
return `${apiKeyConfig} \n${workspaceConfig}`;
5957
};
6058

6159
export const putConfigInCode = ({

apps/opik-frontend/src/plugins/comet/ConfigureEnvCode.tsx

-13
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from "react";
2+
import useUser from "./useUser";
3+
import CreateExperimentCodeCore, {
4+
CreateExperimentCodeCoreProps,
5+
} from "@/components/pages-shared/onboarding/CreateExperimentCode/CreateExperimentCodeCore";
6+
7+
const CreateExperimentCode: React.FC<CreateExperimentCodeCoreProps> = (
8+
props,
9+
) => {
10+
const { data: user } = useUser();
11+
12+
if (!user) return;
13+
14+
return <CreateExperimentCodeCore {...props} apiKey={user.apiKeys[0]} />;
15+
};
16+
17+
export default CreateExperimentCode;

apps/opik-frontend/src/store/PluginsStore.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { GoogleColabCardCoreProps } from "@/components/pages-shared/onboarding/G
66
import { FrameworkIntegrationsProps } from "@/components/pages-shared/onboarding/FrameworkIntegrations/FrameworkIntegrations";
77
import { CommentsViewerCoreProps } from "@/components/pages-shared/traces/TraceDetailsPanel/CommentsViewer/CommentsViewerCore";
88
import { ExperimentCommentsViewerCoreProps } from "@/components/pages/CompareExperimentsPage/CompareExperimentsPanel/DataTab/ExperimentCommentsViewerCore";
9+
import { CreateExperimentCodeCoreProps } from "@/components/pages-shared/onboarding/CreateExperimentCode/CreateExperimentCodeCore";
910

1011
type PluginStore = {
1112
Logo: React.ComponentType<{ expanded: boolean }> | null;
@@ -15,7 +16,7 @@ type PluginStore = {
1516
FrameworkIntegrations: React.ComponentType<FrameworkIntegrationsProps> | null;
1617
GoogleColabCard: React.ComponentType<GoogleColabCardCoreProps> | null;
1718
ApiKeyCard: React.ComponentType | null;
18-
ConfigureEnvCode: React.ComponentType | null;
19+
CreateExperimentCode: React.ComponentType<CreateExperimentCodeCoreProps> | null;
1920
EvaluationExamples: React.ComponentType | null;
2021
CommentsViewer: React.ComponentType<CommentsViewerCoreProps> | null;
2122
ExperimentCommentsViewer: React.ComponentType<ExperimentCommentsViewerCoreProps> | null;
@@ -31,7 +32,7 @@ const PLUGIN_NAMES = [
3132
"FrameworkIntegrations",
3233
"GoogleColabCard",
3334
"ApiKeyCard",
34-
"ConfigureEnvCode",
35+
"CreateExperimentCode",
3536
"CommentsViewer",
3637
"WorkspacePreloader",
3738
"EvaluationExamples",
@@ -47,7 +48,7 @@ const usePluginsStore = create<PluginStore>((set) => ({
4748
GoogleColabCard: null,
4849
ApiKeyCard: null,
4950
WorkspacePreloader: null,
50-
ConfigureEnvCode: null,
51+
CreateExperimentCode: null,
5152
CommentsViewer: null,
5253
EvaluationExamples: null,
5354
ExperimentCommentsViewer: null,

0 commit comments

Comments
 (0)