Merge pull request #941 from trheyi/main
feat: Enhance context management and agent functionality in SUI
This commit is contained in:
commit
979057ae2b
4 changed files with 104 additions and 85 deletions
168
data/bindata.go
168
data/bindata.go
File diff suppressed because one or more lines are too long
|
|
@ -232,6 +232,12 @@ func (neo *DSL) handleChat(c *gin.Context) {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
defer ctx.Release() // Release the context after the request is done
|
defer ctx.Release() // Release the context after the request is done
|
||||||
|
|
||||||
|
// Set the assistant ID
|
||||||
|
assistantID := c.Query("assistant_id")
|
||||||
|
if assistantID != "" {
|
||||||
|
ctx = chatctx.WithAssistantID(ctx, assistantID)
|
||||||
|
}
|
||||||
|
|
||||||
err := neo.Answer(ctx, content, c)
|
err := neo.Answer(ctx, content, c)
|
||||||
|
|
||||||
// Error handling
|
// Error handling
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,12 @@ func NewWithCancel(sid, cid, payload string) (Context, context.CancelFunc) {
|
||||||
return WithCancel(ctx)
|
return WithCancel(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithAssistantID set the assistant ID
|
||||||
|
func WithAssistantID(ctx Context, assistantID string) Context {
|
||||||
|
ctx.AssistantID = assistantID
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|
||||||
// NewWithTimeout create a new context with timeout
|
// NewWithTimeout create a new context with timeout
|
||||||
func NewWithTimeout(sid, cid, payload string, timeout time.Duration) (Context, context.CancelFunc) {
|
func NewWithTimeout(sid, cid, payload string, timeout time.Duration) (Context, context.CancelFunc) {
|
||||||
ctx := New(sid, cid, payload)
|
ctx := New(sid, cid, payload)
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ class Agent {
|
||||||
* @param input Text message or input object with text and optional attachments
|
* @param input Text message or input object with text and optional attachments
|
||||||
* @param args Additional arguments to pass to the agent
|
* @param args Additional arguments to pass to the agent
|
||||||
*/
|
*/
|
||||||
async Call(input: AgentInput, ...args: any[]) {
|
async Call(input: AgentInput, ...args: any[]): Promise<any> {
|
||||||
const messages: AgentMessage[] = [];
|
const messages: AgentMessage[] = [];
|
||||||
let currentContent = "";
|
let currentContent = "";
|
||||||
let lastAssistant = {
|
let lastAssistant = {
|
||||||
|
|
@ -302,6 +302,13 @@ class Agent {
|
||||||
|
|
||||||
messages.push(newMessage);
|
messages.push(newMessage);
|
||||||
messageHandler(newMessage);
|
messageHandler(newMessage);
|
||||||
|
|
||||||
|
// If the message is done, close the event source
|
||||||
|
if (done) {
|
||||||
|
const doneHandler = this.events["done"] as DoneHandler;
|
||||||
|
doneHandler?.(messages);
|
||||||
|
es.close();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue