From d4dda30320ab1b323d3389733089d561b05d06c8 Mon Sep 17 00:00:00 2001 From: mikeee Date: Tue, 5 Nov 2024 22:31:49 +0000 Subject: [PATCH] fix: cleanup convo example Signed-off-by: mikeee --- .github/workflows/test-on-push.yaml | 9 +----- .github/workflows/validate_examples.yaml | 3 +- client/conversation.go | 9 ------ examples/conversation/README.md | 36 ++++++++++++++++++++++++ examples/conversation/main.go | 16 +++++++++-- 5 files changed, 52 insertions(+), 21 deletions(-) create mode 100644 examples/conversation/README.md diff --git a/.github/workflows/test-on-push.yaml b/.github/workflows/test-on-push.yaml index cdc35578..3e450d1e 100644 --- a/.github/workflows/test-on-push.yaml +++ b/.github/workflows/test-on-push.yaml @@ -10,14 +10,7 @@ jobs: build: name: Test on ${{ matrix.gover }} runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - gover: - - "1.21" - - "1.22" env: - GOVER: ${{ matrix.gover }} GOLANGCILINT_VER: v1.55.2 steps: @@ -29,7 +22,7 @@ jobs: - name: Setup uses: actions/setup-go@v5 with: - go-version: ${{ env.GOVER }} + go-version-file: 'go.mod' - name: Tidy run: make tidy diff --git a/.github/workflows/validate_examples.yaml b/.github/workflows/validate_examples.yaml index cc627998..39962efe 100644 --- a/.github/workflows/validate_examples.yaml +++ b/.github/workflows/validate_examples.yaml @@ -33,7 +33,7 @@ jobs: GOPROXY: https://proxy.golang.org DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/master/install/install.sh DAPR_CLI_REF: ${{ github.event.inputs.daprcli_commit }} - DAPR_REF: ${{ github.event.inputs.daprdapr_commit }} + DAPR_REF: 334ae9eea43d487a7b29a0e4aef904e3eba57a10 CHECKOUT_REPO: ${{ github.repository }} CHECKOUT_REF: ${{ github.ref }} outputs: @@ -164,6 +164,7 @@ jobs: [ "actor", "configuration", + "conversation", "crypto", "dist-scheduler", "grpc-service", diff --git a/client/conversation.go b/client/conversation.go index 0118b079..5c83c1cf 100644 --- a/client/conversation.go +++ b/client/conversation.go @@ -15,7 +15,6 @@ package client import ( "context" - "fmt" runtimev1pb "github.com/dapr/dapr/pkg/proto/runtime/v1" "google.golang.org/protobuf/types/known/anypb" ) @@ -36,12 +35,6 @@ type ConversationInput struct { ScrubPII *bool // Scrub PII from the input } -type ConversationInputOption func(*ConversationInput) - -func NewConversationInput(message string, opts ...ConversationInputOption) ConversationInput { - return ConversationInput{} -} - type ConversationResponse struct { ContextID string Outputs []ConversationResult @@ -110,8 +103,6 @@ func (c *GRPCClient) ConverseAlpha1(ctx context.Context, componentName string, i Temperature: o.Temperature, } - fmt.Println("invoking") - resp, err := c.protoClient.ConverseAlpha1(ctx, &request) if err != nil { return nil, err diff --git a/examples/conversation/README.md b/examples/conversation/README.md new file mode 100644 index 00000000..b27ed7b7 --- /dev/null +++ b/examples/conversation/README.md @@ -0,0 +1,36 @@ +# Dapr Conversation Example with go-sdk + +## Step + +### Prepare + +- Dapr installed + +### Run Conversation Example + + + +```bash +dapr run --app-id conversation \ + --dapr-grpc-port 50001 \ + --log-level debug \ + --resources-path ./config \ + -- go run ./main.go +``` + + + +## Result + +``` + - '== APP == conversation output: hello world' +``` diff --git a/examples/conversation/main.go b/examples/conversation/main.go index 70f1fd15..f6f3ab10 100644 --- a/examples/conversation/main.go +++ b/examples/conversation/main.go @@ -22,15 +22,25 @@ import ( ) func main() { - client, err := dapr.NewClientWithPort("47649") + client, err := dapr.NewClient() if err != nil { panic(err) } - resp, err := client.ConverseAlpha1(context.Background(), "echo", []dapr.ConversationInput{{Message: "hello"}}) + input := dapr.ConversationInput{ + Message: "hello world", + // Role: nil, // Optional + // ScrubPII: nil, // Optional + } + + fmt.Printf("conversation input: %s\n", input.Message) + + var conversationComponent = "echo" + + resp, err := client.ConverseAlpha1(context.Background(), conversationComponent, []dapr.ConversationInput{input}) if err != nil { log.Fatalf("err: %v", err) } - fmt.Println(resp.Outputs) + fmt.Printf("conversation output: %s\n", resp.Outputs[0].Result) }