pub struct Api<'a> { /* private fields */ }
Expand description
Dify API
Implementations§
Source§impl<'a> Api<'a>
Dify API
impl<'a> Api<'a>
Dify API
Sourcepub fn new(client: &'a Client) -> Self
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.
Sourcepub fn before_send<F>(&mut self, hook: F)
pub fn before_send<F>(&mut self, hook: F)
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.
Sourcepub async fn chat_messages(
&self,
req_data: ChatMessagesRequest,
) -> AnyResult<ChatMessagesResponse>
pub async fn chat_messages( &self, req_data: ChatMessagesRequest, ) -> AnyResult<ChatMessagesResponse>
Sourcepub async fn chat_messages_stream(
&self,
req_data: ChatMessagesRequest,
) -> AnyResult<SseMessageEventStream<impl Stream<Item = Result<Bytes, Error>>>>
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);
}
}
}
Sourcepub async fn files_upload(
&self,
req_data: FilesUploadRequest,
) -> AnyResult<FilesUploadResponse>
pub async fn files_upload( &self, req_data: FilesUploadRequest, ) -> AnyResult<FilesUploadResponse>
Sourcepub async fn chat_messages_stop(
&self,
req_data: StreamTaskStopRequest,
) -> AnyResult<ResultResponse>
pub async fn chat_messages_stop( &self, req_data: StreamTaskStopRequest, ) -> AnyResult<ResultResponse>
Sourcepub async fn messages_suggested(
&self,
req_data: MessagesSuggestedRequest,
) -> AnyResult<MessagesSuggestedResponse>
pub async fn messages_suggested( &self, req_data: MessagesSuggestedRequest, ) -> AnyResult<MessagesSuggestedResponse>
Sourcepub async fn messages_feedbacks(
&self,
req_data: MessagesFeedbacksRequest,
) -> AnyResult<ResultResponse>
pub async fn messages_feedbacks( &self, req_data: MessagesFeedbacksRequest, ) -> AnyResult<ResultResponse>
Sourcepub async fn conversations(
&self,
req_data: ConversationsRequest,
) -> AnyResult<ConversationsResponse>
pub async fn conversations( &self, req_data: ConversationsRequest, ) -> AnyResult<ConversationsResponse>
Sourcepub async fn messages(
&self,
req_data: MessagesRequest,
) -> AnyResult<MessagesResponse>
pub async fn messages( &self, req_data: MessagesRequest, ) -> AnyResult<MessagesResponse>
Sourcepub async fn conversations_renaming(
&self,
req_data: ConversationsRenameRequest,
) -> AnyResult<ResultResponse>
pub async fn conversations_renaming( &self, req_data: ConversationsRenameRequest, ) -> AnyResult<ResultResponse>
Sourcepub async fn conversations_delete(
&self,
req_data: ConversationsDeleteRequest,
) -> AnyResult<()>
pub async fn conversations_delete( &self, req_data: ConversationsDeleteRequest, ) -> AnyResult<()>
Sourcepub async fn text_to_audio(
&self,
req_data: TextToAudioRequest,
) -> AnyResult<Bytes>
pub async fn text_to_audio( &self, req_data: TextToAudioRequest, ) -> AnyResult<Bytes>
Sourcepub async fn audio_to_text(
&self,
req_data: AudioToTextRequest,
) -> AnyResult<AudioToTextResponse>
pub async fn audio_to_text( &self, req_data: AudioToTextRequest, ) -> AnyResult<AudioToTextResponse>
Sourcepub async fn parameters(
&self,
req_data: ParametersRequest,
) -> AnyResult<ParametersResponse>
pub async fn parameters( &self, req_data: ParametersRequest, ) -> AnyResult<ParametersResponse>
Sourcepub async fn meta(&self, req_data: MetaRequest) -> AnyResult<MetaResponse>
pub async fn meta(&self, req_data: MetaRequest) -> AnyResult<MetaResponse>
Sourcepub async fn workflows_run(
&self,
req_data: WorkflowsRunRequest,
) -> AnyResult<WorkflowsRunResponse>
pub async fn workflows_run( &self, req_data: WorkflowsRunRequest, ) -> AnyResult<WorkflowsRunResponse>
Sourcepub async fn workflows_run_stream(
&self,
req_data: WorkflowsRunRequest,
) -> AnyResult<SseMessageEventStream<impl Stream<Item = Result<Bytes, Error>>>>
pub async fn workflows_run_stream( &self, req_data: WorkflowsRunRequest, ) -> AnyResult<SseMessageEventStream<impl Stream<Item = Result<Bytes, Error>>>>
Sourcepub async fn workflows_stop(
&self,
req_data: StreamTaskStopRequest,
) -> AnyResult<ResultResponse>
pub async fn workflows_stop( &self, req_data: StreamTaskStopRequest, ) -> AnyResult<ResultResponse>
Sourcepub async fn completion_messages(
&self,
req_data: CompletionMessagesRequest,
) -> AnyResult<CompletionMessagesResponse>
pub async fn completion_messages( &self, req_data: CompletionMessagesRequest, ) -> AnyResult<CompletionMessagesResponse>
Sourcepub async fn completion_messages_stream(
&self,
req_data: CompletionMessagesRequest,
) -> AnyResult<SseMessageEventStream<impl Stream<Item = Result<Bytes, Error>>>>
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.