Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add .gitignore and fix go mod and fix stream chat message #4

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
39 changes: 37 additions & 2 deletions api_chat_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,40 @@ type ChatMessageStreamResponse struct {
Answer string `json:"answer"`
CreatedAt int64 `json:"created_at"`
ConversationID string `json:"conversation_id"`
Type string `json:"type"`
BelongsTo string `json:"belongs_to"`
Url string `json:"url"`
Audio string `json:"audio"`
WorkflowRunId string `json:"workflow_run_id"`
Metadata struct {
Usage interface{} `json:"usage"`
RetrieverResources []interface{} `json:"retriever_resources"`
} `json:"metadata"`
Data struct {
Id string `json:"id"`
CreatedAt int64 `json:"created_at"`
FinishedAt int64 `json:"finished_at"`
WorkflowId string `json:"workflow_id"`
SequenceNumber int `json:"sequence_number"`
NodeId string `json:"node_id"`
NodeType string `json:"node_type"`
Title string `json:"title"`
Index int `json:"index"`
PredecessorNodeId string `json:"predecessor_node_id"`
ProcessData string `json:"process_data"`
Status string `json:"status"`
Error string `json:"error"`
ElapsedTime float32 `json:"elapsed_time"`
Inputs interface{} `json:"inputs,omitempty"`
Outputs interface{} `json:"outputs"`
TotalTokens int `json:"total_tokens"`
TotalSteps int `json:"total_steps"`
ExecutionMetadata struct {
TotalTokens int `json:"total_tokens"`
TotalPrice float64 `json:"total_price,omitempty"`
Currency string `json:"currency,omitempty"`
} `json:"execution_metadata"`
} `json:"data"`
}

type ChatMessageStreamChannelResponse struct {
Expand Down Expand Up @@ -79,10 +113,11 @@ func (api *API) chatMessagesStreamHandle(ctx context.Context, resp *http.Respons
Err: errors.New("error streaming event: " + string(line)),
}
return
} else if resp.Answer == "" {
return
}
streamChannel <- resp
if resp.Event == "workflow_finished" {
return
}
}
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/KevinZhao/dify-sdk-go
module github.com/langgenius/dify-sdk-go

go 1.16
5 changes: 2 additions & 3 deletions test/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package test
import (
"context"
"encoding/json"
"github.com/langgenius/dify-sdk-go"
"log"
"strings"
"testing"
"time"

"sync"

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

var (
Expand Down Expand Up @@ -162,7 +161,7 @@ func TestParameters(t *testing.T) {

func TestRunWorkflow(t *testing.T) {
client := dify.NewClient(host, apiSecretKey)
//client := dify.NewClient("https://dify.zhaokm.org", "app-")
// client := dify.NewClient("https://dify.zhaokm.org", "app-")

// 测试带图片的工作流请求
workflowReq := dify.WorkflowRequest{
Expand Down