Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { extractLastArtifact } from "@llamaindex/server";
import { ChatMemoryBuffer, LLM, MessageContent, Settings } from "llamaindex";
import { ChatMemoryBuffer, MessageContent, Settings } from "llamaindex";

import {
agentStreamEvent,
Expand All @@ -12,12 +12,6 @@ import {

import { z } from "zod";

export const workflowFactory = async (reqBody: any) => {
const workflow = createCodeArtifactWorkflow(reqBody);

return workflow;
};

export const RequirementSchema = z.object({
next_step: z.enum(["answering", "coding"]),
language: z.string().nullable().optional(),
Expand Down Expand Up @@ -71,32 +65,28 @@ const artifactEvent = workflowEvent<{
};
}>();

export function createCodeArtifactWorkflow(reqBody: any, llm?: LLM) {
if (!llm) {
llm = Settings.llm;
}
export function workflowFactory(reqBody: any) {
const llm = Settings.llm;

const { withState, getContext } = createStatefulMiddleware(() => {
return {
memory: new ChatMemoryBuffer({
llm,
chatHistory: reqBody.chatHistory,
}),
memory: new ChatMemoryBuffer({ llm }),
lastArtifact: extractLastArtifact(reqBody),
};
});
const workflow = withState(createWorkflow());

workflow.handle([startAgentEvent], async ({ data: { userInput } }) => {
workflow.handle([startAgentEvent], async ({ data }) => {
const { userInput, chatHistory = [] } = data;
// Prepare chat history
const { state } = getContext();
// Put user input to the memory
if (!userInput) {
throw new Error("Missing user input to start the workflow");
}
state.memory.put({
role: "user",
content: userInput,
});
state.memory.set(chatHistory);
state.memory.put({ role: "user", content: userInput });

return planEvent.with({
userInput: userInput,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { extractLastArtifact } from "@llamaindex/server";
import { ChatMemoryBuffer, LLM, MessageContent, Settings } from "llamaindex";
import { ChatMemoryBuffer, MessageContent, Settings } from "llamaindex";

import {
agentStreamEvent,
Expand All @@ -12,12 +12,6 @@ import {

import { z } from "zod";

export const workflowFactory = async (reqBody: any) => {
const workflow = createDocumentArtifactWorkflow(reqBody);

return workflow;
};

export const DocumentRequirementSchema = z.object({
type: z.enum(["markdown", "html"]),
title: z.string(),
Expand Down Expand Up @@ -74,32 +68,28 @@ const artifactEvent = workflowEvent<{
};
}>();

export function createDocumentArtifactWorkflow(reqBody: any, llm?: LLM) {
if (!llm) {
llm = Settings.llm;
}
export function workflowFactory(reqBody: any) {
const llm = Settings.llm;

const { withState, getContext } = createStatefulMiddleware(() => {
return {
memory: new ChatMemoryBuffer({
llm,
chatHistory: reqBody.chatHistory,
}),
memory: new ChatMemoryBuffer({ llm }),
lastArtifact: extractLastArtifact(reqBody),
};
});
const workflow = withState(createWorkflow());

workflow.handle([startAgentEvent], async ({ data: { userInput } }) => {
workflow.handle([startAgentEvent], async ({ data }) => {
const { userInput, chatHistory = [] } = data;
// Prepare chat history
const { state } = getContext();
// Put user input to the memory
if (!userInput) {
throw new Error("Missing user input to start the workflow");
}
state.memory.put({
role: "user",
content: userInput,
});
state.memory.set(chatHistory);
state.memory.put({ role: "user", content: userInput });

return planEvent.with({
userInput,
context: state.lastArtifact
Expand Down
Loading