fix: show last tool response

pull/31/head
hanchchch 1 year ago
parent a4eb16d4bf
commit 1497029f50

@ -20,8 +20,13 @@ celery_app.conf.update(
def task_execute(self, session: str, prompt: str):
executor = agent_manager.create_executor(session, self)
response = executor({"input": prompt})
result = {"output": response["output"]}
return {"output": response["output"]}
previous = AsyncResult(self.request.id)
if previous and previous.info:
result.update(previous.info)
return result
def get_task_result(task_id):

@ -174,7 +174,10 @@ class ExecutionTracingCallbackHandler(BaseCallbackHandler):
def on_tool_error(
self, error: Union[Exception, KeyboardInterrupt], **kwargs: Any
) -> None:
self.execution.update_state(state="TOOL_ERROR", meta={"error": str(error)})
previous = self.execution.AsyncResult(self.execution.request.id)
self.execution.update_state(
state="TOOL_ERROR", meta={**previous.info, "error": str(error)}
)
def on_text(
self,
@ -188,7 +191,4 @@ class ExecutionTracingCallbackHandler(BaseCallbackHandler):
def on_agent_finish(
self, finish: AgentFinish, color: Optional[str] = None, **kwargs: Any
) -> None:
self.execution.update_state(
state="AGENT_FINISH",
meta={"output": finish.return_values.get("output", "")},
)
pass

@ -35,8 +35,8 @@ class EvalApi {
constructor({ onComplete, onError, onSettle, onLLMEnd, onToolEnd }) {
this.executionId = null;
this.pollInterval = null;
this.onComplete = (answer, files) => {
onComplete(answer, files);
this.onComplete = (answer, files, info) => {
onComplete(answer, files, info);
onSettle();
};
this.onError = (error) => {
@ -116,7 +116,7 @@ class EvalApi {
break;
case "SUCCESS":
clearInterval(this.pollInterval);
this.onComplete(result.answer, result.files);
this.onComplete(result.answer, result.files, info);
break;
}
} catch (e) {
@ -131,36 +131,31 @@ const submit = async () => {
setLoader(true);
const actions = $("#actions");
actions.innerHTML = "";
const onInfo = (info) => {
const w = document.createElement("div");
w.innerHTML = createActionCard(
1,
info.action,
info.action_input,
info.what_i_did,
info.plan,
info.observation
);
actions.innerHTML = "";
actions.appendChild(w);
};
const api = new EvalApi({
onComplete: (answer, files) => setAnswer(answer, files),
onError: (error) => setAnswer(`Error: ${error.message}`, []),
onSettle: () => setLoader(false),
onLLMEnd: (info) => {
const w = document.createElement("div");
w.innerHTML = createActionCard(
1,
info.action,
info.action_input,
info.what_i_did,
info.plan
);
actions.innerHTML = "";
actions.appendChild(w);
},
onToolEnd: (info) => {
const w = document.createElement("div");
w.innerHTML = createActionCard(
1,
info.action,
info.action_input,
info.what_i_did,
info.plan,
info.observation
);
actions.innerHTML = "";
actions.appendChild(w);
onError: (error) => setAnswer(`Error: ${error.message}`, []),
onComplete: (answer, files, info) => {
setAnswer(answer, files);
onInfo(info);
},
onLLMEnd: onInfo,
onToolEnd: onInfo,
});
const prompt = $("#prompt").value;

Loading…
Cancel
Save