forked from reworkd/AgentGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0643242
commit 41806d4
Showing
17 changed files
with
245 additions
and
33 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import type { Message } from "../../../types/message"; | ||
import { v1 } from "uuid"; | ||
import { streamText } from "../../stream-utils"; | ||
import { toApiModelSettings } from "../../../utils/interfaces"; | ||
import type AgentWork from "./agent-work"; | ||
import type AutonomousAgent from "../autonomous-agent"; | ||
|
||
export default class ChatWork implements AgentWork { | ||
constructor(private parent: AutonomousAgent, private message: string) {} | ||
|
||
run = async () => { | ||
const executionMessage: Message = { | ||
type: "task", | ||
status: "completed", | ||
value: `Response for '${this.message}'`, | ||
id: v1(), | ||
info: "Loading...", | ||
}; | ||
this.parent.messageService.sendMessage({ ...executionMessage }); | ||
|
||
// TODO: this should be moved to the api layer | ||
await streamText( | ||
"/api/agent/chat", | ||
{ | ||
run_id: this.parent.api.runId, | ||
goal: this.parent.model.getGoal(), | ||
model_settings: toApiModelSettings(this.parent.modelSettings, this.parent.session), | ||
message: this.message, | ||
results: this.parent.model | ||
.getCompletedTasks() | ||
.filter((task) => task.result && task.result !== "") | ||
.map((task) => task.result || ""), | ||
}, | ||
this.parent.api.props.session?.accessToken || "", | ||
() => { | ||
executionMessage.info = ""; | ||
}, | ||
(text) => { | ||
executionMessage.info += text; | ||
this.parent.messageService.updateMessage(executionMessage); | ||
}, | ||
() => this.parent.model.getLifecycle() === "stopped" | ||
); | ||
this.parent.api.saveMessages([executionMessage]); | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/require-await | ||
conclude = async () => void 0; | ||
|
||
next = () => undefined; | ||
|
||
onError = (e: unknown): boolean => { | ||
this.parent.messageService.sendErrorMessage(e); | ||
return true; | ||
}; | ||
} |
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
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
Oops, something went wrong.