From 80361a64006172da12231c4a7b670494aff9b79a Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Mon, 8 Apr 2024 23:25:17 +0200 Subject: [PATCH] small fixups --- agent/agent.go | 4 ++++ example/webui/agentpool.go | 22 +++++++++++++--------- example/webui/connector/telegram.go | 17 +++++++++++++++-- example/webui/create.html | 3 +++ 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index 5e3a59c..c6d980c 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -91,6 +91,10 @@ func (a *Agent) Context() context.Context { return a.context.Context } +func (a *Agent) ConversationChannel() chan openai.ChatCompletionMessage { + return a.newConversations +} + // Ask is a pre-emptive, blocking call that returns the response as soon as it's ready. // It discards any other computation. func (a *Agent) Ask(opts ...JobOption) *JobResult { diff --git a/example/webui/agentpool.go b/example/webui/agentpool.go index a4da8ff..847f04e 100644 --- a/example/webui/agentpool.go +++ b/example/webui/agentpool.go @@ -27,15 +27,16 @@ type AgentConfig struct { Connector []ConnectorConfig `json:"connectors" form:"connectors" ` Actions []ActionsConfig `json:"actions" form:"actions"` // This is what needs to be part of ActionsConfig - Model string `json:"model" form:"model"` - Name string `json:"name" form:"name"` - HUD bool `json:"hud" form:"hud"` - Debug bool `json:"debug" form:"debug"` - StandaloneJob bool `json:"standalone_job" form:"standalone_job"` - RandomIdentity bool `json:"random_identity" form:"random_identity"` - IdentityGuidance string `json:"identity_guidance" form:"identity_guidance"` - PeriodicRuns string `json:"periodic_runs" form:"periodic_runs"` - PermanentGoal string `json:"permanent_goal" form:"permanent_goal"` + Model string `json:"model" form:"model"` + Name string `json:"name" form:"name"` + HUD bool `json:"hud" form:"hud"` + Debug bool `json:"debug" form:"debug"` + StandaloneJob bool `json:"standalone_job" form:"standalone_job"` + RandomIdentity bool `json:"random_identity" form:"random_identity"` + InitiateConversations bool `json:"initiate_conversations" form:"initiate_conversations"` + IdentityGuidance string `json:"identity_guidance" form:"identity_guidance"` + PeriodicRuns string `json:"periodic_runs" form:"periodic_runs"` + PermanentGoal string `json:"permanent_goal" form:"permanent_goal"` } type AgentPool struct { @@ -260,6 +261,9 @@ func (a *AgentPool) startAgentWithConfig(name string, config *AgentConfig) error if config.StandaloneJob { opts = append(opts, EnableStandaloneJob) } + if config.InitiateConversations { + opts = append(opts, EnableInitiateConversations) + } if config.RandomIdentity { if config.IdentityGuidance != "" { opts = append(opts, WithRandomIdentity(config.IdentityGuidance)) diff --git a/example/webui/connector/telegram.go b/example/webui/connector/telegram.go index 13188a9..434f500 100644 --- a/example/webui/connector/telegram.go +++ b/example/webui/connector/telegram.go @@ -12,8 +12,8 @@ import ( ) type Telegram struct { - Token string - Conttext context.Context + Token string + lastChatID int64 } // Send any text message to the bot after the bot has been started @@ -45,6 +45,7 @@ func (t *Telegram) Start(a *agent.Agent) { ChatID: update.Message.Chat.ID, Text: res.Response, }) + t.lastChatID = update.Message.Chat.ID }), } @@ -53,6 +54,18 @@ func (t *Telegram) Start(a *agent.Agent) { panic(err) } + go func() { + for m := range a.ConversationChannel() { + if t.lastChatID == 0 { + continue + } + b.SendMessage(ctx, &bot.SendMessageParams{ + ChatID: t.lastChatID, + Text: m.Content, + }) + } + }() + b.Start(ctx) } diff --git a/example/webui/create.html b/example/webui/create.html index 557a207..ab12da5 100644 --- a/example/webui/create.html +++ b/example/webui/create.html @@ -96,6 +96,9 @@ + + +