Skip to content

Commit 6bf8b9a

Browse files
committed
Add agent function to generate pipeline from user request
Addresses #21
1 parent 93e3635 commit 6bf8b9a

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

app/components/agent/Chat.tsx

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { PaperAirplaneIcon } from '@heroicons/react/24/solid';
22
import { useAtomValue, useSetAtom } from 'jotai';
3-
import { useState } from 'react';
3+
import { useEffect, useRef, useState } from 'react';
44
import { litlyticsAtom, pipelineAtom } from '~/store/store';
55
import { Button } from '../catalyst/button';
66
import { Input } from '../catalyst/input';
@@ -33,6 +33,7 @@ function MessageRender({ message }: { message: Message }) {
3333
}
3434

3535
export function Chat() {
36+
const messageBoxRef = useRef<HTMLDivElement>(null);
3637
const litlytics = useAtomValue(litlyticsAtom);
3738
const setPipeline = useSetAtom(pipelineAtom);
3839
const [input, setInput] = useState<string>('');
@@ -44,6 +45,16 @@ export function Chat() {
4445
},
4546
]);
4647

48+
useEffect(() => {
49+
// scroll to bottom
50+
if (messageBoxRef.current) {
51+
messageBoxRef.current.scrollTo({
52+
top: messageBoxRef.current.scrollHeight,
53+
behavior: 'smooth',
54+
});
55+
}
56+
}, [messages]);
57+
4758
const sendMessage = async () => {
4859
const inputMessage = input;
4960
// reset input
@@ -72,7 +83,10 @@ export function Chat() {
7283

7384
return (
7485
<div className="flex flex-col w-full h-full">
75-
<div className="flex flex-1 flex-col gap-4 p-3 pt-20">
86+
<div
87+
ref={messageBoxRef}
88+
className="flex flex-1 flex-col gap-4 p-3 pt-20 max-h-screen overflow-auto"
89+
>
7690
{messages.map((m) => (
7791
<MessageRender key={m.id} message={m} />
7892
))}

app/components/agent/agent.ts

+35-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LitLytics allows creating custom text document processing pipelines using custom
1010
1111
You have access to following LitLytics functions:
1212
- Suggest a list of possible pipelines that can be applied to user's documents
13-
- Generate a suggested pipeline for processing documents
13+
- Generate a new pipeline for processing documents for given task from user
1414
- Refine suggested pipeline for processing documents
1515
- Add a new step to pipeline
1616
- Edit a step in the pipeline
@@ -87,6 +87,40 @@ Generate a text description for user.`,
8787
);
8888
},
8989
}),
90+
generatePipeline: tool({
91+
description: `Generate a new pipeline for processing documents for given task from user.`,
92+
parameters: z.object({
93+
task: z.string(),
94+
}),
95+
execute: async ({ task }) => {
96+
litlytics.setPipeline({
97+
pipelineDescription: task,
98+
});
99+
// run task
100+
const newPipeline = await litlytics.generatePipeline();
101+
setPipeline(newPipeline);
102+
// generate a response
103+
const agentMessagesWithResult = agentMessages.concat([
104+
{
105+
content: `Suggested pipeline from function execution:
106+
${newPipeline.pipelinePlan}
107+
108+
Ask a user if that look fine.`,
109+
role: 'system',
110+
},
111+
]);
112+
const result = await litlytics.runPromptFromMessages({
113+
messages: agentMessagesWithResult,
114+
});
115+
resolve(
116+
messages.concat({
117+
id: String(messages.length),
118+
from: 'assistant',
119+
text: result.result,
120+
})
121+
);
122+
},
123+
}),
90124
};
91125

92126
// execute request

0 commit comments

Comments
 (0)