From 9f5a32a1bf511eb3e0a006cbb54399e86dd66afe Mon Sep 17 00:00:00 2001 From: mudler Date: Sat, 6 Apr 2024 15:08:39 +0200 Subject: [PATCH] If we didn't had any response, just use the reasoning --- agent/agent.go | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/agent/agent.go b/agent/agent.go index fa8e4dc..e6f896c 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -317,6 +317,14 @@ func (a *Agent) consumeJob(job *Job, role string) { } } + // decode the response + replyResponse := action.ReplyResponse{} + + if err := params.actionParams.Unmarshal(&replyResponse); err != nil { + job.Result.Finish(fmt.Errorf("error unmarshalling reply response: %w", err)) + return + } + // If we have already a reply from the action, just return it. // Otherwise generate a full conversation to get a proper message response // if chosenAction.Definition().Name.Is(action.ReplyActionName) { @@ -356,13 +364,23 @@ func (a *Agent) consumeJob(job *Job, role string) { } // Generate a human-readable response + // resp, err := a.client.CreateChatCompletion(ctx, + // openai.ChatCompletionRequest{ + // Model: a.options.LLMAPI.Model, + // Messages: append(a.currentConversation, + // openai.ChatCompletionMessage{ + // Role: "system", + // Content: "Assistant thought: " + replyResponse.Message, + // }, + // ), + // }, + // ) resp, err := a.client.CreateChatCompletion(ctx, openai.ChatCompletionRequest{ Model: a.options.LLMAPI.Model, Messages: a.currentConversation, }, ) - if err != nil { job.Result.Finish(err) return @@ -376,6 +394,15 @@ func (a *Agent) consumeJob(job *Job, role string) { // display OpenAI's response to the original question utilizing our function msg := resp.Choices[0].Message + // If we didn't got any message, we can use the response from the action + if chosenAction.Definition().Name.Is(action.ReplyActionName) && msg.Content == "" { + if a.options.debugMode { + fmt.Println("No output returned from conversation, using the action response as a reply.") + } + + msg.Content = replyResponse.Message + } + a.currentConversation = append(a.currentConversation, msg) job.Result.SetResponse(msg.Content) job.Result.Finish(nil)