crazywoola 972c4adddd Merge pull request #3 from KevinZhao/main
Add Support for workflow for both Blocking/Streaming
2024-10-31 22:33:54 +08:00
2024-10-30 22:08:42 +08:00
2024-02-28 10:49:57 +08:00
2024-02-28 10:49:57 +08:00
2024-10-30 22:08:42 +08:00
2024-02-19 10:40:57 +08:00
2024-02-19 10:40:57 +08:00
2024-10-14 08:02:17 +08:00
2023-08-01 10:34:16 +08:00

Dify Go SDK

This is the Go SDK for the Dify API, which allows you to easily integrate Dify into your Go applications.

Install

go get github.com/langgenius/dify-sdk-go

Usage

After installing the SDK, you can use it in your project like this:

package main

import (
	"context"
	"log"
	"strings"

	"github.com/langgenius/dify-sdk-go"
)

func main() {
	var (
		ctx = context.Background()
		c = dify.NewClient("your-dify-server-host", "your-api-key-here")

		req = &dify.ChatMessageRequest{
			Query: "your-question",
			User: "your-user",
		}

		ch chan dify.ChatMessageStreamChannelResponse
		err error
	)

	if ch, err = c.Api().ChatMessagesStream(ctx, req); err != nil {
		return
	}

	var strBuilder strings.Builder

	for {
		select {
		case <-ctx.Done():
			return
		case streamData, isOpen := <-ch:
			if err = streamData.Err; err != nil {
				log.Println(err.Error())
				return
			}
			if !isOpen {
				log.Println(strBuilder.String())
				return
			}

			strBuilder.WriteString(streamData.Answer)
		}
	}
}

License

This SDK is released under the MIT License.

S
Description
No description provided
Readme 78 KiB
Languages
Go 100%