dify

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	ResponseModeBlocking  = "blocking"
	ResponseModeStreaming = "streaming"
)
View Source
const (
	RatingLike    = "like"
	RatingDislike = "dislike"
	RatingNull    = "null"
)
View Source
const (
	AppTypeTextGenerator = iota
	AppTypeChatApp
	AppTypeWorkflow
)

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Type int
	// contains filtered or unexported fields
}

func New

func New(baseURL, apiKey string) *App

func (*App) ChatMessage

func (a *App) ChatMessage(req ChatMessageRequest) (*ChatMessageResponse, error)

ChatMessage sends a chat message in blocking mode.

func (*App) ChatMessageStream

func (a *App) ChatMessageStream(req ChatMessageRequest) (*ChatMessageStream, error)

func (*App) CompletionMessage

func (a *App) CompletionMessage(req CompletionMessageRequest) (*ChatCompletionMessageResponse, error)

CompletionMessage sends a completion message and wait for completion in blocking mode.

func (*App) CompletionMessageStreaming

func (a *App) CompletionMessageStreaming(req CompletionMessageRequest) (*CompletionMessageStream, error)

CompletionMessageStreaming sends a completion message and wait for completion in streaming mode.

Example
client := New("", "")
client.SetDebug()

text := "Hello, how are you?"

req := CompletionMessageRequest{
	Inputs: map[string]interface{}{
		"query": text,
	},
	User: uuid.New().String(),
}

resp, err := client.CompletionMessageStreaming(req)
if err != nil {
	panic(err)
}
for {
	r, err := resp.Recv()
	if err != nil {
		if errors.Is(err, io.EOF) {
			break
		}
	}
	if r.Answer != "" {
		print(r.Answer)
	}
}
Output:

func (*App) Conversations

func (a *App) Conversations(req ConversationsRequest) (*ConversationsResponse, error)

func (*App) Feedback

func (*App) Messages

func (a *App) Messages(req MessagesRequest) (*MessagesResponse, error)

func (*App) Parameters

func (a *App) Parameters(req ParametersRequest) (*ParametersResponse, error)

func (*App) SetDebug

func (a *App) SetDebug()

SetDebug sets the client to debug mode.

func (*App) StopChatMessage

func (a *App) StopChatMessage(taskID string) error

func (*App) StopCompletionMessage

func (a *App) StopCompletionMessage(taskID string) error

StopCompletionMessage stops the completion.

func (*App) StopWorkflowRun

func (a *App) StopWorkflowRun(taskID string) error

func (*App) Suggested

func (a *App) Suggested(messageID, user string) (*SuggestedResponse, error)

func (*App) WorkflowRun

func (a *App) WorkflowRun(req WorkflowRunRequest) (*WorkflowRunResponse, error)

func (*App) WorkflowRunStream

func (a *App) WorkflowRunStream(req WorkflowRunRequest) (*WorkflowRunStream, error)

type ChatCompletionMessageResponse

type ChatCompletionMessageResponse struct {
	ID        string `json:"id"`
	Answer    string `json:"answer"`
	CreatedAt int    `json:"created_at"`
}

type ChatMessageRequest

type ChatMessageRequest struct {
	Inputs         map[string]interface{} `json:"inputs"`
	Query          string                 `json:"query"`
	ResponseMode   string                 `json:"response_mode"`
	ConversationID string                 `json:"conversation_id,omitempty"`
	User           string                 `json:"user"`
}

type ChatMessageResponse

type ChatMessageResponse struct {
	ID             string `json:"id"`
	Answer         string `json:"answer"`
	ConversationID string `json:"conversation_id"`
	CreatedAt      int    `json:"created_at"`
}

type ChatMessageStream

type ChatMessageStream struct {
	// contains filtered or unexported fields
}

func (ChatMessageStream) Close

func (stream ChatMessageStream) Close() error

func (ChatMessageStream) Recv

func (stream ChatMessageStream) Recv() (response T, err error)

type ChatMessageStreamChannelResponse

type ChatMessageStreamChannelResponse struct {
	ChatMessageStreamResponse
	Err error `json:"-"`
}

type ChatMessageStreamResponse

type ChatMessageStreamResponse struct {
	Event          string `json:"event"`
	TaskID         string `json:"task_id"`
	ID             string `json:"id"`
	Answer         string `json:"answer"`
	CreatedAt      int64  `json:"created_at"`
	ConversationID string `json:"conversation_id"`
}

type CompletionMessageRequest

type CompletionMessageRequest struct {
	Inputs         map[string]interface{} `json:"inputs"`
	ResponseMode   string                 `json:"response_mode"`
	ConversationID string                 `json:"conversation_id,omitempty"`
	User           string                 `json:"user"`
}

type CompletionMessageStream

type CompletionMessageStream struct {
	// contains filtered or unexported fields
}

func (CompletionMessageStream) Close

func (stream CompletionMessageStream) Close() error

func (CompletionMessageStream) Recv

func (stream CompletionMessageStream) Recv() (response T, err error)

type ConversationsDataResponse

type ConversationsDataResponse struct {
	ID        string            `json:"id"`
	Name      string            `json:"name"`
	Inputs    map[string]string `json:"inputs"`
	Status    string            `json:"status"`
	CreatedAt int64             `json:"created_at"`
}

type ConversationsRenamingRequest

type ConversationsRenamingRequest struct {
	ConversationID string `json:"conversation_id,omitempty"`
	Name           string `json:"name"`
	User           string `json:"user"`
}

type ConversationsRenamingResponse

type ConversationsRenamingResponse struct {
	Result string `json:"result"`
}

type ConversationsRequest

type ConversationsRequest struct {
	LastID string `json:"last_id,omitempty"`
	Limit  int    `json:"limit"`
	User   string `json:"user"`
}

type ConversationsResponse

type ConversationsResponse struct {
	Limit   int                         `json:"limit"`
	HasMore bool                        `json:"has_more"`
	Data    []ConversationsDataResponse `json:"data"`
}

type DefaultErrorAccumulator

type DefaultErrorAccumulator struct {
	Buffer errorBuffer
}

func (*DefaultErrorAccumulator) Bytes

func (e *DefaultErrorAccumulator) Bytes() (errBytes []byte)

func (*DefaultErrorAccumulator) Write

func (e *DefaultErrorAccumulator) Write(p []byte) error

type ErrorAccumulator

type ErrorAccumulator interface {
	Write(p []byte) error
	Bytes() []byte
}

func NewErrorAccumulator

func NewErrorAccumulator() ErrorAccumulator

type ErrorResponse

type ErrorResponse struct {
	Status  int    `json:"status"`
	Code    string `json:"code"`
	Message string `json:"message"`
	Params  string `json:"params"`
}

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

type JSONUnmarshaler

type JSONUnmarshaler struct{}

func (*JSONUnmarshaler) Unmarshal

func (u *JSONUnmarshaler) Unmarshal(data []byte, v any) error

type MessagesDataResponse

type MessagesDataResponse struct {
	ID             string                 `json:"id"`
	ConversationID string                 `json:"conversation_id"`
	Inputs         map[string]interface{} `json:"inputs"`
	Query          string                 `json:"query"`
	Answer         string                 `json:"answer"`
	Feedback       interface{}            `json:"feedback"`
	CreatedAt      int64                  `json:"created_at"`
}

type MessagesFeedbacksDataResponse

type MessagesFeedbacksDataResponse struct {
	ID             string `json:"id"`
	Username       string `json:"username"`
	PhoneNumber    string `json:"phone_number"`
	AvatarURL      string `json:"avatar_url"`
	DisplayName    string `json:"display_name"`
	ConversationID string `json:"conversation_id"`
	LastActiveAt   int64  `json:"last_active_at"`
	CreatedAt      int64  `json:"created_at"`
}

type MessagesFeedbacksRequest

type MessagesFeedbacksRequest struct {
	MessageID string `json:"message_id,omitempty"`
	Rating    string `json:"rating,omitempty"`
	User      string `json:"user"`
}

type MessagesFeedbacksResponse

type MessagesFeedbacksResponse struct {
	HasMore bool                            `json:"has_more"`
	Data    []MessagesFeedbacksDataResponse `json:"data"`
}

type MessagesRequest

type MessagesRequest struct {
	ConversationID string `json:"conversation_id"`
	FirstID        string `json:"first_id,omitempty"`
	Limit          int    `json:"limit"`
	User           string `json:"user"`
}

type MessagesResponse

type MessagesResponse struct {
	Limit   int                    `json:"limit"`
	HasMore bool                   `json:"has_more"`
	Data    []MessagesDataResponse `json:"data"`
}

type ParametersRequest

type ParametersRequest struct {
	User string `json:"user"`
}

type ParametersResponse

type ParametersResponse struct {
	OpeningStatement              string        `json:"opening_statement"`
	SuggestedQuestions            []interface{} `json:"suggested_questions"`
	SuggestedQuestionsAfterAnswer struct {
		Enabled bool `json:"enabled"`
	} `json:"suggested_questions_after_answer"`
	MoreLikeThis struct {
		Enabled bool `json:"enabled"`
	} `json:"more_like_this"`
	UserInputForm []map[string]interface{} `json:"user_input_form"`
}

type SuggestedResponse

type SuggestedResponse struct {
	Result string   `json:"result"`
	Data   []string `json:"data"`
}

type Unmarshaler

type Unmarshaler interface {
	Unmarshal(data []byte, v any) error
}

type WorkflowRunRequest

type WorkflowRunRequest struct {
	Inputs       map[string]interface{} `json:"inputs"`
	ResponseMode string                 `json:"response_mode"`
	User         string                 `json:"user"`
}

type WorkflowRunResponse

type WorkflowRunResponse struct {
	LogID  string `json:"log_id"`
	TaskID string `json:"task_id"`
	Data   struct {
		ID          string                 `json:"id"`
		WorkflowID  string                 `json:"workflow_id"`
		Status      string                 `json:"status"`
		Outputs     map[string]interface{} `json:"outputs"`
		Error       string                 `json:"error"`
		ElapsedTime float64                `json:"elapsed_time"`
		TotalTokens int                    `json:"total_tokens"`
		TotalSteps  int                    `json:"total_steps"`
		CreatedAt   int64                  `json:"created_at"`
		FinishedAt  int64                  `json:"finished_at"`
	}
}

type WorkflowRunStream

type WorkflowRunStream struct {
	// contains filtered or unexported fields
}

func (WorkflowRunStream) Close

func (stream WorkflowRunStream) Close() error

func (WorkflowRunStream) Recv

func (stream WorkflowRunStream) Recv() (response T, err error)

type WorkflowRunStreamResponse

type WorkflowRunStreamResponse struct {
	Event         string `json:"event"`
	TaskID        string `json:"task_id"`
	WorkflowRunID string `json:"workflow_run_id"`
	Data          struct {
		ID                string                 `json:"id"`
		WorkflowID        string                 `json:"workflow_id"`
		SequenceNumber    int                    `json:"sequence_number,omitempty"`
		CreatedAt         int64                  `json:"created_at,omitempty"`
		NodeID            string                 `json:"node_id,omitempty"`
		NodeType          string                 `json:"node_type,omitempty"`
		Title             string                 `json:"title,omitempty"`
		Index             int                    `json:"index,omitempty"`
		PredecessorNodeID string                 `json:"predecessor_node_id,omitempty"`
		Inputs            map[string]interface{} `json:"inputs,omitempty"`
		Outputs           string                 `json:"outputs,omitempty"` // JSON string
		Status            string                 `json:"status,omitempty"`
		Error             string                 `json:"error,omitempty"`
		ElapsedTime       float64                `json:"elapsed_time,omitempty"`
		TotalTokens       int                    `json:"total_tokens,omitempty"`
		TotalSteps        int                    `json:"total_steps,omitempty"`
		FinishedAt        int64                  `json:"finished_at,omitempty"`
	}
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL