Skip to content

Commit

Permalink
fix: charts custom events (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
hughcrt authored Feb 24, 2025
1 parent a7f9ea8 commit 9ef6bd2
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 84 deletions.
11 changes: 2 additions & 9 deletions packages/backend/src/api/v1/analytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1466,15 +1466,8 @@ analytics.get("/topics/top", async (ctx: Context) => {

analytics.get("/custom-events", async (ctx: Context) => {
const { projectId } = ctx.state;
const { startDate, endDate, timeZone, filteredRunsQuery } = parseQuery(
projectId,
ctx.querystring,
ctx.query,
);

const checks = deserializeLogic(
(ctx.query?.checks as string | undefined) || '["AND"]',
);
const { startDate, endDate, timeZone, filteredRunsQuery, checks } =
parseQuery(projectId, ctx.querystring, ctx.query);

let eventFilter = sql`(r.type = 'custom-event')`;
const eventNames = checks?.find((check) => check?.id === "custom-events")
Expand Down
8 changes: 4 additions & 4 deletions packages/backend/src/api/v1/analytics/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export function buildFiltersQuery(deserializedChecks: LogicNode) {
}

export function parseQuery(projectId: string, queryString: string, query: any) {
const deserializedChecks = deserializeLogic(queryString);
const filtersQuery = buildFiltersQuery(deserializedChecks);
const checks = deserializeLogic(queryString);
const filtersQuery = buildFiltersQuery(checks);

return z
.object({
Expand All @@ -24,9 +24,8 @@ export function parseQuery(projectId: string, queryString: string, query: any) {
z.literal("weekly"),
z.literal("monthly"),
]),
checks: z.string().optional(),
})
.transform(({ startDate, endDate, timeZone, granularity, checks }) => {
.transform(({ startDate, endDate, timeZone, granularity }) => {
const granularityToIntervalMap = {
hourly: "1 hour",
daily: "1 day",
Expand Down Expand Up @@ -73,6 +72,7 @@ export function parseQuery(projectId: string, queryString: string, query: any) {
granularity,
timeZone,
localCreatedAt,
checks,
};
})
.parse(query);
Expand Down
1 change: 0 additions & 1 deletion packages/frontend/components/SmartViewer/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,6 @@ export function ChatMessage({
size="sm"
color="black"
onClick={() => {
console.log(data);
clipboard.copy(
data.content || data.text || JSON.stringify(data.toolCalls),
);
Expand Down
7 changes: 5 additions & 2 deletions packages/frontend/components/analytics/DashboardModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,15 @@ export default function DashboardModal({
<Modal opened={opened} onClose={close} withCloseButton={false} size="80vw">
{!isCreatingCustomChart && (
<Group justify="right">
<Tooltip label="Feature available to selected customers. Please contact us at hello@lunary.ai or on the chat to request access.">
<Tooltip
label="Feature available to selected customers. Please contact us at hello@lunary.ai or on the chat to request access."
disabled={customChartsEnabled}
>
<Button
variant="outline"
leftSection={<IconPlus />}
onClick={() => setIsCreatingCustomChart(true)}
data-disabled={!customChartsEnabled}
disabled={!customChartsEnabled}
>
Create Chart
</Button>
Expand Down
116 changes: 48 additions & 68 deletions packages/frontend/components/prompts/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,24 @@ import { jsonrepair } from "jsonrepair";

import {
ActionIcon,
Anchor,
Button,
Checkbox,
Group,
JsonInput,
Modal,
NavLink,
NumberInput,
Popover,
Select,
Text,
Tooltip,
} from "@mantine/core";

import { notifications } from "@mantine/notifications";

import { MODELS, Provider } from "shared";
import { use, useCallback, useEffect, useState } from "react";
import Link from "next/link";
import { IconInfoCircle, IconSettings, IconTools } from "@tabler/icons-react";
import {
useAllProviderModels,
useProviderModels,
} from "@/utils/dataHooks/providers";
import Link from "next/link";
import { useRouter } from "next/router";
import { useState } from "react";
import { MODELS, Provider } from "shared";
import ModelSelect from "./ModelSelect";

function convertOpenAIToolsToAnthropic(openAITools) {
return openAITools.map((openAITool) => {
Expand Down Expand Up @@ -135,74 +128,61 @@ export default function ProviderEditor({
},
});

function handleModelSelectChange(model) {
if (!model || !value.model) {
return;
}
// Handle conversion between OpenAI and Anthropic tools format
const isPreviousProviderOpenAI =
value.model.startsWith("gpt") || value.model.includes("mistral");
const isNewProviderOpenAI =
model.startsWith("gpt") || model.includes("mistral");

const isPreviousProviderAnthropic = value.model.startsWith("claude");

const isNewProviderAnthropic = model.startsWith("claude");

let updatedTools = value.config.tools;

if (
isPreviousProviderOpenAI &&
isNewProviderAnthropic &&
value.config.tools
) {
updatedTools = convertOpenAIToolsToAnthropic(value.config.tools);
} else if (
isPreviousProviderAnthropic &&
isNewProviderOpenAI &&
value.config.tools
) {
updatedTools = convertAnthropicToolsToOpenAI(value.config.tools);
}
onChange({
...value,
model,
config: {
...value.config,
tools: updatedTools,
},
});
}

return (
<>
<ParamItem
name="Model"
value={
<Group>
<Select
data={models.map((model) => ({
value: model.id,
label: `${model.name} ${model.providerName ? `(${model.providerName})` : ""}`,
}))}
w={250}
size="xs"
searchable
inputMode="search"
value={value?.model}
onChange={(model) => {
if (!model || !value.model) {
return;
}
// Handle conversion between OpenAI and Anthropic tools format
const isPreviousProviderOpenAI =
value.model.startsWith("gpt") ||
value.model.includes("mistral");
const isNewProviderOpenAI =
model.startsWith("gpt") || model.includes("mistral");

const isPreviousProviderAnthropic =
value.model.startsWith("claude");

const isNewProviderAnthropic = model.startsWith("claude");

let updatedTools = value.config.tools;

if (
isPreviousProviderOpenAI &&
isNewProviderAnthropic &&
value.config.tools
) {
updatedTools = convertOpenAIToolsToAnthropic(
value.config.tools,
);
} else if (
isPreviousProviderAnthropic &&
isNewProviderOpenAI &&
value.config.tools
) {
updatedTools = convertAnthropicToolsToOpenAI(
value.config.tools,
);
}

onChange({
...value,
model,
config: {
...value.config,
tools: updatedTools,
},
});
}}
<ModelSelect
handleChange={handleModelSelectChange}
selectedModel={value.model}
/>
{/* <ActionIcon
<ActionIcon
variant="default"
onClick={() => router.push("/settings/providers")}
>
<IconSettings width={18} opacity="0.7" />
</ActionIcon> */}
</ActionIcon>
</Group>
}
/>
Expand Down

0 comments on commit 9ef6bd2

Please sign in to comment.