-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove unused meta planner files * Re-plan every time one step is done * Stop meta-planner in case of user interrupt * Adjust meta planner steps based on feedback
- Loading branch information
1 parent
82a0877
commit 30086b9
Showing
5 changed files
with
69 additions
and
54 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,63 @@ | ||
import chat from "../chat/chat"; | ||
import { DefaultMessageContent } from '../state/chat/types' | ||
import { getState } from "../state/store" | ||
import { getState, RootState } from "../state/store" | ||
import { sleep } from "../helpers/utils" | ||
import _ from "lodash" | ||
import _, { isEmpty } from "lodash" | ||
import { getMetaPlan } from "../helpers/LLM/remote"; | ||
import { ChatMessage } from "../state/chat/reducer"; | ||
|
||
const getMessageHistory = () => { | ||
const state = getState() | ||
const thread = state.chat.activeThread | ||
const messageHistory = JSON.stringify( | ||
state.chat.threads[thread].messages.map((msg: ChatMessage) => ({ | ||
role: msg.role, | ||
content: msg.content | ||
})) | ||
) | ||
console.log('Message history is', messageHistory) | ||
return messageHistory | ||
} | ||
|
||
export async function metaPlanner({text}: {text: string}) { | ||
|
||
const steps = await getMetaPlan(text) | ||
let steps = await getMetaPlan(text, [], getMessageHistory()) | ||
console.log('Initial steps are', steps) | ||
|
||
console.log(steps, "steps") | ||
for (const step of steps) { | ||
while (!isEmpty(steps)) { | ||
const step = steps.shift() | ||
const content: DefaultMessageContent = { | ||
type: "DEFAULT", | ||
text: step, | ||
//@ts-ignore | ||
text: step, | ||
images: [] | ||
} | ||
chat.addUserMessage({content}) | ||
while (true){ | ||
await sleep(2000) // hack to avoid race condition | ||
let shouldContinue = true | ||
while (true) { | ||
await sleep(500) | ||
const state = getState() | ||
const thread = state.chat.activeThread | ||
const threadStatus = state.chat.threads[thread].status | ||
const isInterrupted = state.chat.threads[thread].interrupted | ||
if (isInterrupted) { | ||
shouldContinue = false | ||
break; | ||
} | ||
if (threadStatus === "FINISHED") { | ||
console.log("Thread finished!") | ||
break; | ||
} | ||
console.log(threadStatus) | ||
await sleep(100) | ||
} | ||
if (!shouldContinue) { | ||
break; | ||
} | ||
|
||
const newSteps = await getMetaPlan(text, steps, getMessageHistory()) | ||
if (!isEmpty(newSteps)) { | ||
steps = newSteps | ||
} | ||
console.log('New steps are', steps) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters