From e87f4078644a1292d5b3fdbe89c1a751aecfd4ee Mon Sep 17 00:00:00 2001 From: Fernando Rocha Date: Sun, 19 Jan 2025 21:17:59 -0800 Subject: [PATCH] COnverstaion API Signed-off-by: Fernando Rocha --- conversation/go/http/README.md | 2 + .../go/http/components/conversation.yaml | 0 conversation/go/http/conversation/go.mod | 3 ++ conversation/go/http/conversation/go.sum | 0 conversation/go/http/conversation/main.go | 48 ++++++++++++++++++ conversation/go/http/dapr.yaml | 7 +++ conversation/go/http/makefile | 2 + conversation/go/sdk/README.md | 1 + .../go/sdk/components/conversation.yaml | 0 conversation/go/sdk/conversation/go.mod | 21 ++++++++ conversation/go/sdk/conversation/go.sum | 43 ++++++++++++++++ conversation/go/sdk/conversation/main.go | 49 +++++++++++++++++++ conversation/go/sdk/dapr.yaml | 7 +++ conversation/go/sdk/go.mod | 3 ++ conversation/go/sdk/makefile | 2 + .../http/order-processor/package-lock.json | 1 + .../react-calculator/client/yarn.lock | 5 ++ .../react-calculator/yarn.lock | 5 ++ tutorials/pub-sub/react-form/client/yarn.lock | 5 ++ tutorials/pub-sub/react-form/yarn.lock | 5 ++ 20 files changed, 209 insertions(+) create mode 100644 conversation/go/http/components/conversation.yaml create mode 100644 conversation/go/http/conversation/go.mod create mode 100644 conversation/go/http/conversation/go.sum create mode 100644 conversation/go/http/conversation/main.go create mode 100644 conversation/go/http/dapr.yaml create mode 100644 conversation/go/http/makefile create mode 100644 conversation/go/sdk/components/conversation.yaml create mode 100644 conversation/go/sdk/conversation/go.mod create mode 100644 conversation/go/sdk/conversation/go.sum create mode 100644 conversation/go/sdk/conversation/main.go create mode 100644 conversation/go/sdk/dapr.yaml create mode 100644 conversation/go/sdk/go.mod create mode 100644 conversation/go/sdk/makefile diff --git a/conversation/go/http/README.md b/conversation/go/http/README.md index e69de29bb..eb07be211 100644 --- a/conversation/go/http/README.md +++ b/conversation/go/http/README.md @@ -0,0 +1,2 @@ +# Dapr Conversation + diff --git a/conversation/go/http/components/conversation.yaml b/conversation/go/http/components/conversation.yaml new file mode 100644 index 000000000..e69de29bb diff --git a/conversation/go/http/conversation/go.mod b/conversation/go/http/conversation/go.mod new file mode 100644 index 000000000..6f4384989 --- /dev/null +++ b/conversation/go/http/conversation/go.mod @@ -0,0 +1,3 @@ +module conversation + +go 1.21 diff --git a/conversation/go/http/conversation/go.sum b/conversation/go/http/conversation/go.sum new file mode 100644 index 000000000..e69de29bb diff --git a/conversation/go/http/conversation/main.go b/conversation/go/http/conversation/main.go new file mode 100644 index 000000000..4e24e5022 --- /dev/null +++ b/conversation/go/http/conversation/main.go @@ -0,0 +1,48 @@ +package main + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + "net/http" + "os" + "time" +) + +const stateStoreComponentName = "statestore" + +func main() { + daprHost := os.Getenv("DAPR_HOST") + if daprHost == "" { + daprHost = "http://localhost" + } + daprHttpPort := os.Getenv("DAPR_HTTP_PORT") + if daprHttpPort == "" { + daprHttpPort = "3500" + } + + client := http.Client{ + Timeout: 15 * time.Second, + } + + input, _ := json.Marshal([]map[string]string{ + { + "inputs": "what is Dapr", + }, + }) + + res, err := client.Post(daprHost+":"+daprHttpPort+"/v1.0-alpha1/conversation/"+stateStoreComponentName+"/converse", "application/json", bytes.NewReader(input)) + if err != nil { + panic(err) + } + + output, err := io.ReadAll(res.Request.Response.Body) + if err != nil { + panic(err) + } + fmt.Println("Retrieved response:", string(output)) + + res.Body.Close() + fmt.Println("Input sent sent:", input) +} diff --git a/conversation/go/http/dapr.yaml b/conversation/go/http/dapr.yaml new file mode 100644 index 000000000..e355de4d5 --- /dev/null +++ b/conversation/go/http/dapr.yaml @@ -0,0 +1,7 @@ +version: 1 +apps: + - appDirPath: ./conversation/ + appID: conversation + appPort: 6300 + daprHTTPPort: 6380 + command: ["go", "run", "."] diff --git a/conversation/go/http/makefile b/conversation/go/http/makefile new file mode 100644 index 000000000..e7a8826bf --- /dev/null +++ b/conversation/go/http/makefile @@ -0,0 +1,2 @@ +include ../../../docker.mk +include ../../../validate.mk \ No newline at end of file diff --git a/conversation/go/sdk/README.md b/conversation/go/sdk/README.md index e69de29bb..276317d6d 100644 --- a/conversation/go/sdk/README.md +++ b/conversation/go/sdk/README.md @@ -0,0 +1 @@ +# Dapr Conversation \ No newline at end of file diff --git a/conversation/go/sdk/components/conversation.yaml b/conversation/go/sdk/components/conversation.yaml new file mode 100644 index 000000000..e69de29bb diff --git a/conversation/go/sdk/conversation/go.mod b/conversation/go/sdk/conversation/go.mod new file mode 100644 index 000000000..74bc557c1 --- /dev/null +++ b/conversation/go/sdk/conversation/go.mod @@ -0,0 +1,21 @@ +module conversation + +go 1.22.6 + +toolchain go1.22.11 + +require github.com/dapr/go-sdk v1.11.0 + +require ( + github.com/dapr/dapr v1.14.0 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/kr/pretty v0.3.1 // indirect + go.opentelemetry.io/otel v1.27.0 // indirect + golang.org/x/net v0.26.0 // indirect + golang.org/x/sys v0.21.0 // indirect + golang.org/x/text v0.16.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240624140628-dc46fd24d27d // indirect + google.golang.org/grpc v1.65.0 // indirect + google.golang.org/protobuf v1.34.2 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/conversation/go/sdk/conversation/go.sum b/conversation/go/sdk/conversation/go.sum new file mode 100644 index 000000000..d2b2ab596 --- /dev/null +++ b/conversation/go/sdk/conversation/go.sum @@ -0,0 +1,43 @@ +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/dapr/dapr v1.14.0 h1:SIQsNX1kH31JRDIS4k8IZ6eomM/BAcOP844PhQIT+BQ= +github.com/dapr/dapr v1.14.0/go.mod h1:oDNgaPHQIDZ3G4n4g89TElXWgkluYwcar41DI/oF4gw= +github.com/dapr/go-sdk v1.11.0 h1:clANpOQd6MsfvSa6snaX8MVk6eRx26Vsj5GxGdQ6mpE= +github.com/dapr/go-sdk v1.11.0/go.mod h1:btZ/tX8eYnx0fg3HiJUku8J5QBRXHsp3kAB1BUiTxXY= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg= +go.opentelemetry.io/otel v1.27.0/go.mod h1:DMpAK8fzYRzs+bi3rS5REupisuqTheUlSZJ1WnZaPAQ= +golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY= +golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI= +golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= +golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240624140628-dc46fd24d27d h1:k3zyW3BYYR30e8v3x0bTDdE9vpYFjZHK+HcyqkrppWk= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240624140628-dc46fd24d27d/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= +google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc= +google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/conversation/go/sdk/conversation/main.go b/conversation/go/sdk/conversation/main.go new file mode 100644 index 000000000..089200d56 --- /dev/null +++ b/conversation/go/sdk/conversation/main.go @@ -0,0 +1,49 @@ +/* +Copyright 2024 The Dapr Authors +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package main + +import ( + "context" + "fmt" + "log" + + dapr "github.com/dapr/go-sdk/client" +) + +func main() { + client, err := dapr.NewClient() + if err != nil { + panic(err) + } + + input := dapr.ConversationInput{ + Message: "hello world", + // Role: nil, // Optional + // ScrubPII: nil, // Optional + } + + fmt.Printf("conversation input: %s\n", input.Message) + + var conversationComponent = "echo" + + request := dapr.NewConversationRequest(conversationComponent, []dapr.ConversationInput{input}) + + resp, err := client.ConverseAlpha1(context.Background(), request) + if err != nil { + log.Fatalf("err: %v", err) + } + + fmt.Printf("conversation output: %s\n", resp.Outputs[0].Result) +} diff --git a/conversation/go/sdk/dapr.yaml b/conversation/go/sdk/dapr.yaml new file mode 100644 index 000000000..e355de4d5 --- /dev/null +++ b/conversation/go/sdk/dapr.yaml @@ -0,0 +1,7 @@ +version: 1 +apps: + - appDirPath: ./conversation/ + appID: conversation + appPort: 6300 + daprHTTPPort: 6380 + command: ["go", "run", "."] diff --git a/conversation/go/sdk/go.mod b/conversation/go/sdk/go.mod new file mode 100644 index 000000000..bdfba7c87 --- /dev/null +++ b/conversation/go/sdk/go.mod @@ -0,0 +1,3 @@ +module dapr_conversation_quickstart + +go 1.22.5 diff --git a/conversation/go/sdk/makefile b/conversation/go/sdk/makefile new file mode 100644 index 000000000..e7a8826bf --- /dev/null +++ b/conversation/go/sdk/makefile @@ -0,0 +1,2 @@ +include ../../../docker.mk +include ../../../validate.mk \ No newline at end of file diff --git a/pub_sub/javascript/http/order-processor/package-lock.json b/pub_sub/javascript/http/order-processor/package-lock.json index 4815c51c6..6c342295a 100644 --- a/pub_sub/javascript/http/order-processor/package-lock.json +++ b/pub_sub/javascript/http/order-processor/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "body-parser": "^1.19.0", "express": "^4.17.2" } }, diff --git a/tutorials/distributed-calculator/react-calculator/client/yarn.lock b/tutorials/distributed-calculator/react-calculator/client/yarn.lock index 61cf96285..ac9807e90 100644 --- a/tutorials/distributed-calculator/react-calculator/client/yarn.lock +++ b/tutorials/distributed-calculator/react-calculator/client/yarn.lock @@ -4525,6 +4525,11 @@ fs.realpath@^1.0.0: resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== +fsevents@^2.3.2, fsevents@~2.3.2: + version "2.3.2" + resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz" + integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== + function-bind@^1.1.1: version "1.1.1" resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz" diff --git a/tutorials/distributed-calculator/react-calculator/yarn.lock b/tutorials/distributed-calculator/react-calculator/yarn.lock index 8c21580fa..1b86a59e1 100644 --- a/tutorials/distributed-calculator/react-calculator/yarn.lock +++ b/tutorials/distributed-calculator/react-calculator/yarn.lock @@ -381,6 +381,11 @@ fresh@0.5.2: resolved "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz" integrity sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q== +fsevents@~2.3.2: + version "2.3.2" + resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz" + integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== + function-bind@^1.1.2: version "1.1.2" resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz" diff --git a/tutorials/pub-sub/react-form/client/yarn.lock b/tutorials/pub-sub/react-form/client/yarn.lock index c26994644..59a85ac2d 100644 --- a/tutorials/pub-sub/react-form/client/yarn.lock +++ b/tutorials/pub-sub/react-form/client/yarn.lock @@ -4418,6 +4418,11 @@ fs.realpath@^1.0.0: resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== +fsevents@^2.3.2, fsevents@~2.3.2: + version "2.3.2" + resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz" + integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== + function-bind@^1.1.1: version "1.1.1" resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz" diff --git a/tutorials/pub-sub/react-form/yarn.lock b/tutorials/pub-sub/react-form/yarn.lock index 2aabf7654..666864f06 100644 --- a/tutorials/pub-sub/react-form/yarn.lock +++ b/tutorials/pub-sub/react-form/yarn.lock @@ -381,6 +381,11 @@ fresh@0.5.2: resolved "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz" integrity sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q== +fsevents@~2.3.2: + version "2.3.2" + resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz" + integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== + function-bind@^1.1.2: version "1.1.2" resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz"