From 4e9f8f66286c27f8a0ed842746e2f172b2df8e29 Mon Sep 17 00:00:00 2001 From: Vladyslav Len Date: Tue, 20 Feb 2024 00:10:28 +0100 Subject: [PATCH] feat(): updates for openai plugin --- internal/processors/openai/plugin.go | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/internal/processors/openai/plugin.go b/internal/processors/openai/plugin.go index 5bea1d2..090171f 100644 --- a/internal/processors/openai/plugin.go +++ b/internal/processors/openai/plugin.go @@ -45,13 +45,13 @@ func (p *Plugin) Process(context context.Context, msg *message.Message) (*messag if msg.GetStream() != p.config.StreamName { return msg, nil } - if p.rateLimiterTick != nil && p.messagesProcessedWithinALimit >= p.config.LimitPerMinute { - p.logger.Info("Rate limit wait") - <-p.rateLimiterTick.C - p.mutx.Lock() - p.messagesProcessedWithinALimit = 0 - p.mutx.Unlock() - } + //if p.rateLimiterTick != nil && p.messagesProcessedWithinALimit >= p.config.LimitPerMinute { + // p.logger.Info("Rate limit wait") + // <-p.rateLimiterTick.C + // p.mutx.Lock() + // p.messagesProcessedWithinALimit = 0 + // p.mutx.Unlock() + //} processedMessage, err := p.processMessage(context, msg) if err != nil { @@ -67,7 +67,12 @@ func (p *Plugin) Process(context context.Context, msg *message.Message) (*messag func (p *Plugin) processMessage(context context.Context, msg *message.Message) (*message.Message, error) { sourceFieldValue := msg.Data.AccessProperty(p.config.SourceField) - prompt := fmt.Sprintf("Strictly follow the instructions. Take the data: %s and respond after doing following: %s . Provide the shortest response possible \n Do not explain your actions.", sourceFieldValue, p.prompt) + command := "You are data pipeline assistant. You take the data from the user and perform various checks and " + + "analysis. You are capable of checking the data for different patterns, harmful content, etc " + + "You must strictly follow a given instruction:" + p.prompt + + "Your responses must always be short, without any explanation, unless your wants you to do so." + + "You should never explain your thoughts or process. You need to respond with an answer only" + + "Yours response will most likely used in database field to try to assume the correct form of response based on the instructions given" resp, err := p.client.CreateChatCompletion( context, @@ -76,7 +81,11 @@ func (p *Plugin) processMessage(context context.Context, msg *message.Message) ( Messages: []openai.ChatCompletionMessage{ { Role: openai.ChatMessageRoleUser, - Content: prompt, + Content: fmt.Sprintf("%v", sourceFieldValue), + }, + { + Role: openai.ChatMessageRoleAssistant, + Content: command, }, }, },