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

[Hackathon] Agent #47993

Draft
wants to merge 52 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
fa1a978
wip: edit viz with LLMs
rafpaf Aug 31, 2024
4a4fa01
wip
rafpaf Sep 16, 2024
c2e2414
wip
rafpaf Sep 16, 2024
bfd9e29
wip: teaching AI more about mbql
rafpaf Sep 17, 2024
dc956b5
wip - creating filters by typing prose
rafpaf Sep 17, 2024
69b2f73
metabot section
heypoom Sep 18, 2024
29b8a06
wip
rafpaf Sep 18, 2024
9a0448a
wip
rafpaf Sep 18, 2024
df140f2
wip
rafpaf Sep 18, 2024
d610a21
wip
rafpaf Sep 18, 2024
55f595d
wip
rafpaf Sep 18, 2024
aa43eb6
wip
rafpaf Sep 18, 2024
e1d23c1
metabot agent
heypoom Sep 18, 2024
7b90cfa
wip
rafpaf Sep 18, 2024
0b2e204
Improve look of chat widget
rafpaf Sep 18, 2024
65b447f
Fix menu
rafpaf Sep 18, 2024
d80b5db
show/hide columns
heypoom Sep 18, 2024
d291dc6
Fix bug
rafpaf Sep 18, 2024
38291d2
Rename menu item
rafpaf Sep 18, 2024
fdf1d38
ai
heypoom Sep 18, 2024
bb644f3
pass messages
heypoom Sep 18, 2024
ba1c9ee
metabot section
heypoom Sep 18, 2024
1dd11d5
metabot agent
rafpaf Sep 18, 2024
13b9a70
show/hide columns
rafpaf Sep 18, 2024
157e747
ai
heypoom Sep 18, 2024
fd97647
pass messages
heypoom Sep 18, 2024
b06fb87
Reset change to sidebar
rafpaf Sep 18, 2024
bd8ab56
Reset question info sidebar entirely
rafpaf Sep 18, 2024
0ba458f
types
heypoom Sep 18, 2024
e1a05d0
wip
rafpaf Sep 18, 2024
d28c555
wip: adding filters
rafpaf Sep 18, 2024
8089f6a
summ/breakout
heypoom Sep 18, 2024
c2925d6
tool spec
heypoom Sep 18, 2024
125bec0
Merge remote-tracking branch 'origin/2024-hackathon-ai-agent' into 20…
rafpaf Sep 18, 2024
c2f8b1f
wip
rafpaf Sep 18, 2024
8671cd9
wip
rafpaf Sep 18, 2024
044374e
Merge branch 'sept2024-agent' into 2024-hackathon-ai-agent
rafpaf Sep 18, 2024
84c23d6
wip
rafpaf Sep 18, 2024
15de437
wip
rafpaf Sep 18, 2024
2bd893b
wip
rafpaf Sep 18, 2024
ad121f8
Add some metabot moods
rafpaf Sep 18, 2024
f104f00
Change visualization appropriately when summarization is applied.
maxzheng Sep 18, 2024
d897f8f
tool spec
heypoom Sep 18, 2024
435157a
Use new image for 'Metabot is thinking'
rafpaf Sep 18, 2024
fc356ef
Include distinct values for each field in the context
rafpaf Sep 18, 2024
f09a0bf
Merge remote-tracking branch 'origin/2024-hackathon-ai-agent' into 20…
rafpaf Sep 18, 2024
4c6bc92
Merge branch '2024-hackathon-ai-agent' of github.com:metabase/metabas…
heypoom Sep 18, 2024
41d1ab2
null tool call
heypoom Sep 18, 2024
0a57c2d
avg
heypoom Sep 18, 2024
ec9ff92
simpler filter
heypoom Sep 18, 2024
90527aa
fff
heypoom Sep 18, 2024
a7c4ff8
fff
heypoom Sep 18, 2024
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
Prev Previous commit
Next Next commit
wip
  • Loading branch information
rafpaf committed Sep 18, 2024
commit aa43eb608fa5a86e5ae3ec074d9190c2dfe24144
39 changes: 27 additions & 12 deletions frontend/src/metabase/chat/components/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,22 @@ import {
import type Question from "metabase-lib/v1/Question";
import type { FieldReference } from "metabase-types/api";

import Styles from "./EditVizPage.module.css";
import Styles from "./Chat.module.css";
import type { Message, QueryField } from "./types";
import { getColumnsWithSampleValues, getLLMResponse } from "./utils";
import { useMessages } from "./hooks/use-messages";

export const Chat = ({
scrollableStackRef,
question,
}: {
question: Question;
scrollableStackRef: React.RefObject<HTMLDivElement>;
}) => {
const { currentlyViewedQuestion: question, questionData } = (window as any)
._chatHacks;

console.log("question via hack", question);
console.log("questionData via hack", questionData);

const query = question._card.dataset_query;
const visualizationSettings = question._card.visualization_settings;

Expand All @@ -50,7 +54,7 @@ export const Chat = ({

const [isAwaitingLLMResponse, setIsAwaitingLLMResponse] = useState(false);

const data = (window as { questionData?: any }).questionData[0]?.data;
const data = questionData[0]?.data;
const { cols, rows } = data;
const fieldsWithSampleValues = useMemo(() => {
return getColumnsWithSampleValues(cols, rows);
Expand Down Expand Up @@ -168,7 +172,7 @@ export const Chat = ({
]);

return (
<>
<Box pos="relative">
<Stack
spacing="sm"
p="1rem"
Expand All @@ -177,21 +181,30 @@ export const Chat = ({
justify="flex-end"
>
<Messages messages={messages} question={question} />
{isAwaitingLLMResponse && (
<AIMessageDisplay
question={question}
message={{
author: "llm",
content: t`...`,
}}
></AIMessageDisplay>
)}
</Stack>
<Box
pos="absolute"
pos="sticky"
w="calc(100% - 1rem)"
bg="linear-gradient(to bottom, transparent, white 75%)"
bottom={0}
>
<Box p="1rem" pr=".5rem">
<Box p="1rem" pr="0">
<WriteMessage
isAwaitingLLMResponse={isAwaitingLLMResponse}
addMessage={addMessage}
/>
</Box>
</Box>
</>
</Box>
);
};

Expand Down Expand Up @@ -322,7 +335,7 @@ const LoadNewQuestionButton = ({
<Button
px="md"
py="xs"
variant="filled"
variant="default"
onClick={() => {
const nextQuestion = question.setDatasetQuery(
message.newQuery.dataset_query,
Expand All @@ -339,8 +352,10 @@ const LoadNewQuestionButton = ({
const UserMessageDisplay = ({ message }: { message: Message }) => {
return (
<Flex justify="flex-end">
<Paper shadow="none" bg="var(--mb-color-border)" maw="15rem" p=".75rem">
<Text lh="1.35rem">{message.content}</Text>
<Paper shadow="none" bg="var(--mb-color-brand)" maw="15rem" p=".75rem">
<Text c="#fff" lh="1.35rem">
{message.content}
</Text>
</Paper>
</Flex>
);
Expand Down Expand Up @@ -369,7 +384,7 @@ const Messages = ({
question: Question;
}) => {
return (
<Stack spacing="lg" pb="7rem">
<Stack spacing="lg">
{messages.map((message, index) => (
<MessageDisplay key={index} message={message} question={question} />
))}
Expand Down
15 changes: 15 additions & 0 deletions frontend/src/metabase/chat/components/ChatWidget.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,18 @@
bottom: 1rem;
right: 1rem;
}
.MetabotLogo {
width: 2rem;
}
.ChatLauncher {
border-radius: 100%;
cursor: pointer;
background-color: var(--mb-color-brand);
transition: background-color 0.1s;
&:hover {
background-color: color-mix(in srgb, var(--mb-color-brand) 90%, white);
}
&:active {
transform: scale(0.96);
}
}
24 changes: 17 additions & 7 deletions frontend/src/metabase/chat/components/ChatWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import { useRef } from "react";

import { MetabotIcon } from "metabase/metabot/components/MetabotMessage/MetabotMessage.styled";
import { Popover } from "metabase/ui";
import { Flex, Paper, Popover } from "metabase/ui";

import { Chat } from "./Chat";
import Styles from "./ChatWidget.module.css";
import MetabotLogo from "metabase/core/components/MetabotLogo";

export const ChatWidget = () => {
const scrollableStackRef = useRef<HTMLDivElement | null>(null);
return (
<div className={Styles.ChatWidget}>
<Popover>
<Popover position="bottom-end">
<Popover.Target>
<MetabotIcon />
<Flex
justify="center"
align="center"
w="3rem"
h="3rem"
className={Styles.ChatLauncher}
>
<MetabotLogo className={Styles.MetabotLogo} />
</Flex>
</Popover.Target>
<Popover.Dropdown>
<div ref={scrollableStackRef}>
<Chat scrollableStackRef={scrollableStackRef} />
</div>
<Paper mah="70dvh" maw="20rem">
<div ref={scrollableStackRef}>
<Chat scrollableStackRef={scrollableStackRef} />
</div>
</Paper>
</Popover.Dropdown>
</Popover>
</div>
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/metabase/query_builder/components/view/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class View extends Component {
onCloseChartType,
} = this.props;

// HACK: This makes the currently viewed question available to the ChatWidget
window._chatHacks ||= {};
window._chatHacks.currentlyViewedQuestion = this.props.question;

if (isShowingChartSettingsSidebar) {
const {
question,
Expand Down

This file was deleted.

7 changes: 4 additions & 3 deletions frontend/src/metabase/query_builder/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,9 +697,10 @@ export const getRawSeries = createSelector(
datasetQuery: lastRunDatasetQuery,
});

// HACK: expose data to be send to ai proxy/flask
window.questionData = rawSeries;
window.queryResult = queryResult;
// HACK: Make data available to ChatWidget
window._chatHacks ||= {};
window._chatHacks.questionData = rawSeries;
window._chatHacks.queryResult = queryResult;

if (isShowingRawTable && rawSeries?.length > 0) {
const [{ card, data }] = rawSeries;
Expand Down