Struct Api

Source
pub struct Api<'a> { /* private fields */ }
Expand description

Dify API

Implementations§

Source§

impl<'a> Api<'a>

Dify API

Source

pub fn new(client: &'a Client) -> Self

Creates a new Api instance with the specified client.

§Arguments
  • client - The client for interacting with the Dify API.
Source

pub fn before_send<F>(&mut self, hook: F)
where F: Fn(Request) -> Request + Send + Sync + 'static,

Sets a hook function to be called before sending a request. The hook function is called with the request before it is sent. The hook function can be used to modify the request before it is sent. The hook function should return the modified request. The hook function can be used to add headers, query parameters, etc.

§Arguments
  • hook - The hook function to be called before sending a request.
Source

pub async fn chat_messages( &self, req_data: ChatMessagesRequest, ) -> AnyResult<ChatMessagesResponse>

Sends a chat message request to the Dify API and returns the response.

§Arguments
  • req_data - The chat message request data.
§Returns

A Result containing the chat message response or an error.

Source

pub async fn chat_messages_stream( &self, req_data: ChatMessagesRequest, ) -> AnyResult<SseMessageEventStream<impl Stream<Item = Result<Bytes, Error>>>>

Sends a chat message request to the Dify API and returns the response as a stream.

§Arguments
  • req_data - The chat message request data.
§Returns

A Result containing SSE message event stream or an error.

§Errors

Returns an error if the request cannot be created or the stream fails.

§Stream response usage
while let Some(event) = stream.next().await {
    match event {
        Ok(event) => {
            println!("event: {:?}", event);
        }
        Err(error) => {
            eprintln!("Failed to receive event: {}", error);
        }
    }
}
Source

pub async fn files_upload( &self, req_data: FilesUploadRequest, ) -> AnyResult<FilesUploadResponse>

Sends a request to upload files to the Dify API and returns the response.
上传文件(目前仅支持图片)并在发送消息时使用,可实现图文多模态理解。
支持 png, jpg, jpeg, webp, gif 格式。
上传的文件仅供当前终端用户使用。

§Arguments
  • req_data - The files upload request data.
§Returns

A Result containing the files upload response or an error.

Source

pub async fn chat_messages_stop( &self, req_data: StreamTaskStopRequest, ) -> AnyResult<ResultResponse>

Sends a request to stop stream chat messages to the Dify API and returns the response.

§Arguments
  • req_data - The chat message stop request data.
§Returns

A Result containing the chat message stop response or an error.

Source

pub async fn messages_suggested( &self, req_data: MessagesSuggestedRequest, ) -> AnyResult<MessagesSuggestedResponse>

Sends a request to retrieve suggested messages from the Dify API and returns the response.

§Arguments
  • req_data - The messages suggested request data.
§Returns

A Result containing the messages suggested response or an error.

Source

pub async fn messages_feedbacks( &self, req_data: MessagesFeedbacksRequest, ) -> AnyResult<ResultResponse>

Sends a request to retrieve messages feedbacks from the Dify API and returns the response.

§Arguments
  • req_data - The messages feedbacks request data.
§Returns

A Result containing the messages feedbacks response or an error.

Source

pub async fn conversations( &self, req_data: ConversationsRequest, ) -> AnyResult<ConversationsResponse>

Sends a request to retrieve conversations from the Dify API and returns the response.

§Arguments
  • req_data - The conversations request data.
§Returns

A Result containing the conversations response or an error.

Source

pub async fn messages( &self, req_data: MessagesRequest, ) -> AnyResult<MessagesResponse>

Sends a request to retrieve history messages from the Dify API and returns the response.

§Arguments
  • req_data - The messages request data.
§Returns

A Result containing the messages response or an error.

Source

pub async fn conversations_renaming( &self, req_data: ConversationsRenameRequest, ) -> AnyResult<ResultResponse>

Sends a request to rename a conversation in the Dify API and returns the response.

§Arguments
  • req_data - The conversations rename request data.
§Returns

A Result containing the conversations rename response or an error.

Source

pub async fn conversations_delete( &self, req_data: ConversationsDeleteRequest, ) -> AnyResult<()>

Sends a request to delete a conversation in the Dify API and returns the response.

§Arguments
  • req_data - The conversations delete request data.
§Returns

A Result containing the conversations delete response or an error.

Source

pub async fn text_to_audio( &self, req_data: TextToAudioRequest, ) -> AnyResult<Bytes>

Sends a request to convert audio to text in the Dify API and returns the response.

§Arguments
  • req_data - The audio to text request data.
§Returns

A Result containing the audio to text response or an error.

Source

pub async fn audio_to_text( &self, req_data: AudioToTextRequest, ) -> AnyResult<AudioToTextResponse>

Sends a request to convert audio to text in the Dify API and returns the response.

§Arguments
  • req_data - The audio to text request data.
§Returns

A Result containing the audio to text response or an error.

Source

pub async fn parameters( &self, req_data: ParametersRequest, ) -> AnyResult<ParametersResponse>

Sends a request to retrieve parameters from the Dify API and returns the response.

§Arguments
  • req_data - The parameters request data.
§Returns

A Result containing the parameters response or an error.

Source

pub async fn meta(&self, req_data: MetaRequest) -> AnyResult<MetaResponse>

Sends a request to retrieve meta information from the Dify API and returns the response.

§Arguments
  • req_data - The meta request data.
§Returns

A Result containing the meta response or an error.

Source

pub async fn workflows_run( &self, req_data: WorkflowsRunRequest, ) -> AnyResult<WorkflowsRunResponse>

Sends a request to run workflows from the Dify API and returns the response.

§Arguments
  • req_data - The workflows run request data.
§Returns

A Result containing the workflows run response or an error.

Source

pub async fn workflows_run_stream( &self, req_data: WorkflowsRunRequest, ) -> AnyResult<SseMessageEventStream<impl Stream<Item = Result<Bytes, Error>>>>

Sends a request to run workflows from the Dify API and returns the response as a stream.

§Arguments
  • req_data - The workflows run request data.
§Returns

A Result containing SSE message event stream or an error.

§Errors

Returns an error if the request cannot be created or the stream fails.

Source

pub async fn workflows_stop( &self, req_data: StreamTaskStopRequest, ) -> AnyResult<ResultResponse>

Sends a request to stop stream workflows from the Dify API and returns the response.

§Arguments
  • req_data - The stream task stop request data.
§Returns

A Result containing the stream task stop response or an error.

Source

pub async fn completion_messages( &self, req_data: CompletionMessagesRequest, ) -> AnyResult<CompletionMessagesResponse>

Sends a request to create completion messages from the Dify API and returns the response. 发送请求给文本生成型应用

§Arguments
  • req_data - The completion messages request data.
§Returns

A Result containing the completion messages response or an error.

Source

pub async fn completion_messages_stream( &self, req_data: CompletionMessagesRequest, ) -> AnyResult<SseMessageEventStream<impl Stream<Item = Result<Bytes, Error>>>>

Sends a request to create completion messages from the Dify API and returns the response as a stream.

§Arguments
  • req_data - The completion messages request data.
§Returns

A Result containing SSE message event stream or an error.

§Errors

Returns an error if the request cannot be created or the stream fails.

Source

pub async fn completion_messages_stop( &self, req_data: StreamTaskStopRequest, ) -> AnyResult<ResultResponse>

Sends a request to stop stream completion messages from the Dify API and returns the response. 文本生成停止响应

§Arguments
  • req_data - The stream task stop request data.
§Returns

A Result containing the stream task stop response or an error.

Auto Trait Implementations§

§

impl<'a> Freeze for Api<'a>

§

impl<'a> !RefUnwindSafe for Api<'a>

§

impl<'a> Send for Api<'a>

§

impl<'a> Sync for Api<'a>

§

impl<'a> Unpin for Api<'a>

§

impl<'a> !UnwindSafe for Api<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,