diff --git a/agent/agent.go b/agent/agent.go index d86d279..117b41d 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -30,7 +30,7 @@ type Agent struct { currentReasoning string currentState *action.StateResult nextAction Action - currentConversation []openai.ChatCompletionMessage + currentConversation Messages selfEvaluationInProgress bool newConversations chan openai.ChatCompletionMessage @@ -392,7 +392,7 @@ func (a *Agent) consumeJob(job *Job, role string) { job.Result.Finish(fmt.Errorf("error renderTemplate: %w", err)) return } - if !Messages(a.currentConversation).Exist(prompt) { + if !a.currentConversation.Exist(prompt) { a.currentConversation = append([]openai.ChatCompletionMessage{ { Role: "system", diff --git a/example/webui/elements.go b/example/webui/elements.go index df2b2a0..a3a1bd2 100644 --- a/example/webui/elements.go +++ b/example/webui/elements.go @@ -3,5 +3,17 @@ package main import "fmt" func chatDiv(content string, color string) string { - return fmt.Sprintf(`
%s
`, color, htmlIfy(content)) + return fmt.Sprintf(`
%s
`, color, htmlIfy(content)) +} + +func loader() string { + return `
` +} + +func inputMessageDisabled(disabled bool) string { + if disabled { + return `` + } + + return `` } diff --git a/example/webui/index.html b/example/webui/index.html index 74445aa..9e542ea 100644 --- a/example/webui/index.html +++ b/example/webui/index.html @@ -1,5 +1,3 @@ - - @@ -22,93 +20,73 @@ .htmx-request .htmx-indicator{ opacity:1 } - /* https://cssloaders.github.io/ */ .loader { - width: 4px; - height: 20px; - border-radius: 4px; - display: block; - margin: 20px auto; - position: relative; - background: currentColor; - color: #FFF; - box-sizing: border-box; - animation: animloader 0.3s 0.3s linear infinite alternate; -} + width: 12px; + height: 12px; + border-radius: 50%; + display: block; + margin:15px auto; + position: relative; + color: #FFF; + box-sizing: border-box; + animation: animloader 2s linear infinite; + } -.loader::after, .loader::before { - content: ''; - width: 4px; - height: 20px; - border-radius: 4px; - background: currentColor; - position: absolute; - top: 50%; - transform: translateY(-50%); - left: 20px; - box-sizing: border-box; - animation: animloader 0.3s 0.45s linear infinite alternate; -} -.loader::before { - left: -20px; - animation-delay: 0s; -} - -@keyframes animloader { - 0% { height: 24px} - 100% { height: 2px} -} - - + @keyframes animloader { + 0% { box-shadow: 14px 0 0 -2px, 38px 0 0 -2px, -14px 0 0 -2px, -38px 0 0 -2px; } + 25% { box-shadow: 14px 0 0 -2px, 38px 0 0 -2px, -14px 0 0 -2px, -38px 0 0 2px; } + 50% { box-shadow: 14px 0 0 -2px, 38px 0 0 -2px, -14px 0 0 2px, -38px 0 0 -2px; } + 75% { box-shadow: 14px 0 0 2px, 38px 0 0 -2px, -14px 0 0 -2px, -38px 0 0 -2px; } + 100% { box-shadow: 14px 0 0 -2px, 38px 0 0 2px, -14px 0 0 -2px, -38px 0 0 -2px; } + } - -
+ +
-
+

Talk to '{{.Character.Name}}'

-
+

Clients:

-
+
-
+
-
+

Status:

-
+
-
+
- -
-
+
+
- -
+

Agent:

-
+
-
+
+ class="p-2 border rounded w-full bg-gray-600 text-white placeholder-gray-300" placeholder="Type a message..." _="on htmx:afterRequest set my value to ''">
Loading...
+
diff --git a/example/webui/main.go b/example/webui/main.go index 7e18435..102f566 100644 --- a/example/webui/main.go +++ b/example/webui/main.go @@ -181,7 +181,7 @@ func (a *App) Chat(m sse.Manager) func(w http.ResponseWriter, r *http.Request) { } m.Send( sse.NewMessage( - chatDiv(query, "blue"), + chatDiv(query, "gray"), ).WithEvent("messages")) go func() { @@ -191,11 +191,11 @@ func (a *App) Chat(m sse.Manager) func(w http.ResponseWriter, r *http.Request) { fmt.Println("response is", res.Response) m.Send( sse.NewMessage( - chatDiv(res.Response, "red"), + chatDiv(res.Response, "blue"), ).WithEvent("messages")) m.Send( sse.NewMessage( - "", + inputMessageDisabled(false), // show again the input ).WithEvent("message_status")) //result := `done` @@ -204,7 +204,7 @@ func (a *App) Chat(m sse.Manager) func(w http.ResponseWriter, r *http.Request) { m.Send( sse.NewMessage( - `
`, + loader() + inputMessageDisabled(true), ).WithEvent("message_status")) } }