http_request.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package dify_invocation
  2. import (
  3. "github.com/langgenius/dify-plugin-daemon/internal/utils/requests"
  4. "github.com/langgenius/dify-plugin-daemon/internal/utils/stream"
  5. )
  6. func Request[T any](method string, path string, options ...requests.HttpOptions) (*T, error) {
  7. options = append(options, requests.HttpHeader(map[string]string{
  8. "X-Inner-Api-Key": PLUGIN_INNER_API_KEY,
  9. }))
  10. return requests.RequestAndParse[T](client, difyPath(path), method, options...)
  11. }
  12. func StreamResponse[T any](method string, path string, options ...requests.HttpOptions) (*stream.StreamResponse[T], error) {
  13. options = append(options, requests.HttpHeader(map[string]string{
  14. "X-Inner-Api-Key": PLUGIN_INNER_API_KEY,
  15. }))
  16. return requests.RequestAndParseStream[T](client, difyPath(path), method, options...)
  17. }
  18. func InvokeModel(payload InvokeModelRequest) (*stream.StreamResponse[InvokeModelResponseChunk], error) {
  19. return StreamResponse[InvokeModelResponseChunk]("POST", "invoke/model", requests.HttpPayloadJson(payload))
  20. }
  21. func InvokeTool(payload InvokeToolRequest) (*stream.StreamResponse[InvokeToolResponseChunk], error) {
  22. return StreamResponse[InvokeToolResponseChunk]("POST", "invoke/tool", requests.HttpPayloadJson(payload))
  23. }
  24. func InvokeNode[T WorkflowNodeData](payload InvokeNodeRequest[T]) (*InvokeNodeResponse, error) {
  25. return Request[InvokeNodeResponse]("POST", "invoke/node", requests.HttpPayloadJson(payload))
  26. }