🚧 prompt inspection
This commit is contained in:
parent
55b2f394ca
commit
e5c050e5cd
12 changed files with 361 additions and 282 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1253,7 +1253,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
|
|||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
if (props.active && props.groupIndices) {
|
||||
client?.deleteAtIndex(props.groupIndices[1]);
|
||||
client?.stopSession();
|
||||
} else {
|
||||
props.onDelete?.();
|
||||
}
|
||||
|
|
@ -1402,6 +1402,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
|
|||
if (active) {
|
||||
// TODO: Stop running steps
|
||||
// client?.deleteAtIndex(sessionHistory.current_index);
|
||||
client?.stopSession();
|
||||
dispatch(setActive(false));
|
||||
} else {
|
||||
props.onEnter?.(undefined);
|
||||
|
|
|
|||
|
|
@ -324,7 +324,7 @@ const UserInputContainer = (props: UserInputContainerProps) => {
|
|||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
if (props.active) {
|
||||
client?.deleteAtIndex(props.groupIndices[1]);
|
||||
client.stopSession();
|
||||
} else {
|
||||
props.onDelete();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@ abstract class AbstractContinueGUIClientProtocol {
|
|||
|
||||
abstract retryAtIndex(index: number): void;
|
||||
|
||||
abstract deleteAtIndex(index: number): void;
|
||||
|
||||
abstract deleteContextWithIds(ids: ContextItemId[], index?: number): void;
|
||||
|
||||
abstract setEditingAtIds(ids: string[]): void;
|
||||
|
|
|
|||
|
|
@ -107,6 +107,10 @@ class ContinueGUIClientProtocol extends AbstractContinueGUIClientProtocol {
|
|||
});
|
||||
}
|
||||
|
||||
stopSession() {
|
||||
this.messenger?.send("stop_session", {});
|
||||
}
|
||||
|
||||
sendClear() {
|
||||
this.messenger?.send("clear_history", {});
|
||||
}
|
||||
|
|
@ -115,10 +119,6 @@ class ContinueGUIClientProtocol extends AbstractContinueGUIClientProtocol {
|
|||
this.messenger?.send("retry_at_index", { index });
|
||||
}
|
||||
|
||||
deleteAtIndex(index: number) {
|
||||
this.messenger?.send("delete_at_index", { index });
|
||||
}
|
||||
|
||||
deleteContextWithIds(ids: ContextItemId[], index?: number) {
|
||||
this.messenger?.send("delete_context_with_ids", {
|
||||
ids: ids.map((id) => `${id.provider_title}-${id.item_id}`),
|
||||
|
|
|
|||
|
|
@ -226,8 +226,8 @@ function GUI(props: GUIProps) {
|
|||
!e.shiftKey &&
|
||||
active
|
||||
) {
|
||||
// TODO: Stop
|
||||
// client?.deleteAtIndex(history.current_index);
|
||||
client?.stopSession();
|
||||
dispatch(setActive(false));
|
||||
} else if (e.key === "Escape") {
|
||||
dispatch(setBottomMessage(undefined));
|
||||
}
|
||||
|
|
@ -401,6 +401,23 @@ function GUI(props: GUIProps) {
|
|||
client.sendStepUserInput(input, index);
|
||||
};
|
||||
|
||||
const isLastUserInput = useCallback(
|
||||
(index: number): boolean => {
|
||||
let foundLaterUserInput = false;
|
||||
for (let i = index + 1; i < sessionState.history.length; i++) {
|
||||
if (
|
||||
sessionState.history[i].name === "User Input" &&
|
||||
sessionState.history[i].hide === false
|
||||
) {
|
||||
foundLaterUserInput = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return !foundLaterUserInput;
|
||||
},
|
||||
[sessionState.history]
|
||||
);
|
||||
|
||||
const getStepsInUserInputGroup = useCallback(
|
||||
(index: number): number[] => {
|
||||
// index is the index in the entire timeline, hidden steps included
|
||||
|
|
@ -624,12 +641,32 @@ function GUI(props: GUIProps) {
|
|||
<ComboBox
|
||||
isMainInput={false}
|
||||
value={step.description as string}
|
||||
active={
|
||||
// TODO: Should only be if it's the last user input
|
||||
active
|
||||
}
|
||||
active={active && isLastUserInput(index)}
|
||||
onEnter={(e, value) => {
|
||||
if (value) client?.editStepAtIndex(value, index);
|
||||
if (value) {
|
||||
client?.stopSession();
|
||||
const newHistory = [
|
||||
...sessionState.history.slice(0, index),
|
||||
{
|
||||
name: "User Input",
|
||||
description: value,
|
||||
observations: [],
|
||||
logs: [],
|
||||
step_type: "UserInputStep",
|
||||
params: { user_input: value },
|
||||
hide: false,
|
||||
depth: 0,
|
||||
},
|
||||
];
|
||||
dispatch(setHistory(newHistory));
|
||||
dispatch(setActive(true));
|
||||
const state = {
|
||||
history: newHistory,
|
||||
context_items: sessionState.context_items,
|
||||
};
|
||||
console.log("State: ", state);
|
||||
client.runFromState(state);
|
||||
}
|
||||
e?.stopPropagation();
|
||||
e?.preventDefault();
|
||||
}}
|
||||
|
|
@ -659,7 +696,7 @@ function GUI(props: GUIProps) {
|
|||
onDelete={() => {
|
||||
// Delete the input and all steps until the next user input
|
||||
getStepsInUserInputGroup(index).forEach((i) => {
|
||||
client?.deleteAtIndex(i);
|
||||
// client?.deleteAtIndex(i);
|
||||
});
|
||||
}}
|
||||
/>
|
||||
|
|
@ -693,7 +730,10 @@ function GUI(props: GUIProps) {
|
|||
<ErrorStepContainer
|
||||
onClose={() => onToggleAtIndex(index)}
|
||||
error={step.error}
|
||||
onDelete={() => client?.deleteAtIndex(index)}
|
||||
onDelete={() => {
|
||||
// TODO: Deleting steps, all UI
|
||||
// client?.deleteAtIndex(index)
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<StepContainer
|
||||
|
|
@ -718,7 +758,8 @@ function GUI(props: GUIProps) {
|
|||
setWaitingForSteps(true);
|
||||
}}
|
||||
onDelete={() => {
|
||||
client?.deleteAtIndex(index);
|
||||
// TODO
|
||||
// client?.deleteAtIndex(index);
|
||||
}}
|
||||
noUserInputParent={
|
||||
getStepsInUserInputGroup(index).length === 0
|
||||
|
|
|
|||
|
|
@ -384,9 +384,20 @@ class Autopilot:
|
|||
await self.sdk.gui.send_session_update(update)
|
||||
|
||||
async def run(self):
|
||||
async def add_log(log: str):
|
||||
await self.handle_session_update(
|
||||
SessionUpdate(
|
||||
index=len(self.session_state.history) - 1,
|
||||
update=DeltaStep(logs=[log]),
|
||||
)
|
||||
)
|
||||
|
||||
logger_id = self.config.models.add_logger(add_log)
|
||||
while next_step := self.policy.next(self.sdk.config, self.session_state):
|
||||
await self.run_step(next_step)
|
||||
|
||||
self.config.models.remove_logger(logger_id)
|
||||
|
||||
# async def create_title(self, backup: str = None):
|
||||
# # Want sdk.gui.update_title(title)
|
||||
# # Use the first input and first response to create title for session info, and make the session saveable
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from typing import List, Optional
|
||||
from typing import Callable, Coroutine, List, Optional, Union
|
||||
import uuid
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
|
@ -100,6 +101,7 @@ class Models(BaseModel):
|
|||
setattr(self, role, self.default)
|
||||
else:
|
||||
await model.start(unique_id)
|
||||
model.write_log = self.write_log
|
||||
|
||||
self.set_main_config_params(system_message, temperature)
|
||||
|
||||
|
|
@ -107,3 +109,18 @@ class Models(BaseModel):
|
|||
"""Stop each LLM (if it's not the default, which is shared)"""
|
||||
for model in self.all_models:
|
||||
await model.stop()
|
||||
|
||||
_loggers = {}
|
||||
|
||||
async def write_log(self, msg):
|
||||
for logger in self._loggers.values():
|
||||
await logger(msg)
|
||||
|
||||
def add_logger(self, logger: Callable[[str], None]) -> str:
|
||||
logger_id = uuid.uuid4().hex
|
||||
self._loggers[logger_id] = logger
|
||||
return logger_id
|
||||
|
||||
def remove_logger(self, logger_id: str):
|
||||
if logger_id in self._loggers:
|
||||
del self._loggers[logger_id]
|
||||
|
|
|
|||
|
|
@ -349,7 +349,7 @@ Settings:
|
|||
prompt = self.template_prompt_like_messages(prompt)
|
||||
|
||||
if log and self.write_log:
|
||||
self.write_log(self.compile_log_message(prompt, options))
|
||||
await self.write_log(self.compile_log_message(prompt, options))
|
||||
|
||||
completion = ""
|
||||
async for chunk in self._stream_complete(prompt=prompt, options=options):
|
||||
|
|
@ -397,7 +397,7 @@ Settings:
|
|||
prompt = self.template_prompt_like_messages(prompt)
|
||||
|
||||
if log and self.write_log:
|
||||
self.write_log(self.compile_log_message(prompt, options))
|
||||
await self.write_log(self.compile_log_message(prompt, options))
|
||||
|
||||
completion = await self._complete(prompt=prompt, options=options)
|
||||
|
||||
|
|
@ -444,7 +444,7 @@ Settings:
|
|||
prompt = format_chat_messages(messages)
|
||||
|
||||
if log and self.write_log:
|
||||
self.write_log(self.compile_log_message(prompt, options))
|
||||
await self.write_log(self.compile_log_message(prompt, options))
|
||||
|
||||
completion = ""
|
||||
|
||||
|
|
|
|||
|
|
@ -56,6 +56,9 @@ class GUIProtocolServer:
|
|||
data = msg.data
|
||||
if msg.message_type == "run_from_state":
|
||||
await self.run_from_state(SessionState.parse_obj(data["state"]))
|
||||
elif msg.message_type == "stop_session":
|
||||
await self.stop_session()
|
||||
|
||||
elif msg.message_type == "set_current_session_title":
|
||||
self.set_current_session_title(data["title"])
|
||||
elif msg.message_type == "show_logs_at_index":
|
||||
|
|
@ -337,9 +340,17 @@ class GUIProtocolServer:
|
|||
|
||||
# region: Send data to GUI
|
||||
|
||||
_running_autopilot: Optional[Autopilot] = None
|
||||
|
||||
async def run_from_state(self, state: SessionState):
|
||||
autopilot = self.get_autopilot(state)
|
||||
self._running_autopilot = autopilot
|
||||
await autopilot.run()
|
||||
self._running_autopilot = None
|
||||
|
||||
async def stop_session(self):
|
||||
if self._running_autopilot is not None:
|
||||
self._running_autopilot.stopped = True
|
||||
|
||||
async def send_session_update(self, session_update: SessionUpdate):
|
||||
await self.messenger.send("session_update", session_update.dict())
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class Window:
|
|||
gui: Optional[GUIProtocolServer] = None
|
||||
config: Optional[ContinueConfig] = None
|
||||
|
||||
def get_autopilot(self, session_state: SessionState) -> Optional[Autopilot]:
|
||||
def get_autopilot(self, session_state: SessionState) -> Autopilot:
|
||||
return Autopilot(
|
||||
session_state=session_state,
|
||||
ide=self.ide,
|
||||
|
|
@ -151,7 +151,7 @@ class WindowManager:
|
|||
def get_gui(self, sid: str) -> Optional[GUIProtocolServer]:
|
||||
return self.guis.get(sid)
|
||||
|
||||
async def register_gui(self, window_id: str, sio: str, sid: str):
|
||||
async def register_gui(self, window_id: str, sio, sid: str):
|
||||
if window_id not in self.windows:
|
||||
self.windows[window_id] = Window()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue