Skip to content

Commit

Permalink
Merge branch 'master' into fix-flaky-int-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dapr-bot authored Oct 11, 2024
2 parents dda3c0d + 78e5cfd commit 5fe166a
Show file tree
Hide file tree
Showing 7 changed files with 449 additions and 81 deletions.
14 changes: 10 additions & 4 deletions dapr/proto/runtime/v1/dapr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1284,8 +1284,8 @@ message ConversationAlpha1Request {
// The name of Coverstaion component
string name = 1;

// Conversation context - the Id of an existing chat room (like in ChatGPT)
optional string conversationContext = 2;
// The ID of an existing chat (like in ChatGPT)
optional string contextID = 2;

// Inputs for the conversation, support multiple input in one time.
repeated ConversationInput inputs = 3;
Expand All @@ -1295,6 +1295,9 @@ message ConversationAlpha1Request {

// The metadata passing to conversation components.
map<string, string> metadata = 5;

// Scrub PII data that comes back from the LLM
optional bool scrubPII = 6;
}

message ConversationInput {
Expand All @@ -1303,6 +1306,9 @@ message ConversationInput {

// The role to set for the message
optional string role = 2;

// Scrub PII data that goes into the LLM
optional bool scrubPII = 3;
}

// ConversationAlpha1Result is the result for one input.
Expand All @@ -1315,8 +1321,8 @@ message ConversationAlpha1Result {

// ConversationAlpha1Response is the response for Conversation.
message ConversationAlpha1Response {
// Conversation context - the Id of an existing chat room (like in ChatGPT)
optional string conversationContext = 1;
// The ID of an existing chat (like in ChatGPT)
optional string contextID = 1;

// An array of results.
repeated ConversationAlpha1Result outputs = 2;
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
contrib.go.opencensus.io/exporter/prometheus v0.4.2
github.com/PaesslerAG/jsonpath v0.1.1
github.com/PuerkitoBio/purell v1.2.1
github.com/aavaz-ai/pii-scrubber v0.0.0-20220812094047-3fa450ab6973
github.com/alphadose/haxmap v1.4.0
github.com/argoproj/argo-rollouts v1.4.1
github.com/cenkalti/backoff/v4 v4.3.0
Expand Down Expand Up @@ -148,6 +149,7 @@ require (
github.com/aliyun/aliyun-tablestore-go-sdk v1.7.10 // indirect
github.com/aliyun/credentials-go v1.1.2 // indirect
github.com/andybalholm/brotli v1.0.6 // indirect
github.com/anshal21/go-worker v1.1.0 // indirect
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
github.com/apache/dubbo-getty v1.4.9-0.20220610060150-8af010f3f3dc // indirect
github.com/apache/dubbo-go-hessian2 v1.11.5 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/
github.com/Workiva/go-datastructures v1.0.52/go.mod h1:Z+F2Rca0qCsVYDS8z7bAGm8f3UkzuWYS/oBZz5a7VVA=
github.com/Workiva/go-datastructures v1.0.53 h1:J6Y/52yX10Xc5JjXmGtWoSSxs3mZnGSaq37xZZh7Yig=
github.com/Workiva/go-datastructures v1.0.53/go.mod h1:1yZL+zfsztete+ePzZz/Zb1/t5BnDuE2Ya2MMGhzP6A=
github.com/aavaz-ai/pii-scrubber v0.0.0-20220812094047-3fa450ab6973 h1:oMQQEYwu9V0O+IcRs7ButCPjsbOS0eEtMOImkvaeWLA=
github.com/aavaz-ai/pii-scrubber v0.0.0-20220812094047-3fa450ab6973/go.mod h1:Y5HcXSyXAlR6rvJ5kqvPEtQlRLhekJFI/w/9CRZkpHs=
github.com/aerospike/aerospike-client-go/v6 v6.12.0 h1:4RKpcUlfINyIsjyOK8DBKn6NaBUl5UaHrWVY07/R99Q=
github.com/aerospike/aerospike-client-go/v6 v6.12.0/go.mod h1:sBqeA3mli2vT5JInbp+XGFbajxEFg4kANUHsOl3meUk=
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 h1:rFw4nCn9iMW+Vajsk51NtYIcwSTkXr+JGrMd36kTDJw=
Expand Down Expand Up @@ -215,6 +217,8 @@ github.com/alphadose/haxmap v1.4.0 h1:1yn+oGzy2THJj1DMuJBzRanE3sMnDAjJVbU0L31Jp3
github.com/alphadose/haxmap v1.4.0/go.mod h1:rjHw1IAqbxm0S3U5tD16GoKsiAd8FWx5BJ2IYqXwgmM=
github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sxfOI=
github.com/andybalholm/brotli v1.0.6/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/anshal21/go-worker v1.1.0 h1:TPt2jBN/6dmPDPDTq8DHA0MtoXG8RWKGoJVHqED+s5g=
github.com/anshal21/go-worker v1.1.0/go.mod h1:6GiLOIr/VvVg80vfW65ytLuouSvndU2IoJTu+8M47lI=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
Expand Down
49 changes: 42 additions & 7 deletions pkg/api/universal/conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package universal
import (
"context"

piiscrubber "github.com/aavaz-ai/pii-scrubber"

"github.com/dapr/components-contrib/conversation"
"github.com/dapr/dapr/pkg/messages"
runtimev1pb "github.com/dapr/dapr/pkg/proto/runtime/v1"
Expand Down Expand Up @@ -51,17 +53,37 @@ func (a *Universal) ConverseAlpha1(ctx context.Context, req *runtimev1pb.Convers
return nil, err
}

scrubber, err := piiscrubber.NewDefaultScrubber()
if err != nil {
err := messages.ErrConversationMissingInputs.WithFormat(req.GetName())
a.logger.Debug(err)
return &runtimev1pb.ConversationAlpha1Response{}, err
}

for _, i := range req.GetInputs() {
msg := i.GetMessage()

if i.GetScrubPII() {
scrubbed, sErr := scrubber.ScrubTexts([]string{i.GetMessage()})
if sErr != nil {
sErr = messages.ErrConversationInvoke.WithFormat(req.GetName(), sErr.Error())
a.logger.Debug(sErr)
return &runtimev1pb.ConversationAlpha1Response{}, sErr
}

msg = scrubbed[0]
}

c := conversation.ConversationInput{
Message: i.GetMessage(),
Message: msg,
Role: conversation.Role(i.GetRole()),
}

request.Inputs = append(request.Inputs, c)
}

request.Parameters = req.GetParameters()
request.ConversationContext = req.GetConversationContext()
request.ConversationContext = req.GetContextID()

// do call
policyRunner := resiliency.NewRunner[*conversation.ConversationResponse](ctx,
Expand All @@ -75,21 +97,34 @@ func (a *Universal) ConverseAlpha1(ctx context.Context, req *runtimev1pb.Convers
if err != nil {
err = messages.ErrConversationInvoke.WithFormat(req.GetName(), err.Error())
a.logger.Debug(err)
return nil, err
return &runtimev1pb.ConversationAlpha1Response{}, err
}

// handle response
response := &runtimev1pb.ConversationAlpha1Response{}
a.logger.Debug(response)
if resp != nil {
if resp.ConversationContext != "" {
response.ConversationContext = &resp.ConversationContext
response.ContextID = &resp.ConversationContext
}

for i := range resp.Outputs {
for _, o := range resp.Outputs {
res := o.Result

if req.GetScrubPII() {
scrubbed, sErr := scrubber.ScrubTexts([]string{o.Result})
if sErr != nil {
sErr = messages.ErrConversationInvoke.WithFormat(req.GetName(), sErr.Error())
a.logger.Debug(sErr)
return &runtimev1pb.ConversationAlpha1Response{}, sErr
}

res = scrubbed[0]
}

response.Outputs = append(response.GetOutputs(), &runtimev1pb.ConversationAlpha1Result{
Result: resp.Outputs[i].Result,
Parameters: resp.Outputs[i].Parameters,
Result: res,
Parameters: o.Parameters,
})
}
}
Expand Down
Loading

0 comments on commit 5fe166a

Please sign in to comment.