DifyChat4R: DifyChat4R Function (Completion Messages Only)

View source: R/DifyChat4R.R

DifyChat4RR Documentation

DifyChat4R Function (Completion Messages Only)

Description

This function sends a query to the Dify API using the completion-messages endpoint in blocking mode. It provides a simple interface for interacting with Dify AI applications. The function uses the stable blocking response mode to avoid streaming parsing issues.

Usage

DifyChat4R(
  query,
  user = "abc-123",
  api_key = Sys.getenv("DIFY_API_KEY"),
  conversation_id = "",
  files = NULL
)

Arguments

query

A character string representing the user's input query.

user

A character string representing the user identifier. Default is "abc-123".

api_key

A character string for the Dify API secret key. Defaults to the value of the environment variable "DIFY_API_KEY".

conversation_id

A character string representing the conversation ID. Default is an empty string.

files

A list of lists representing file information to be sent with the query. Default is NULL. Each file should be a list containing at least the keys: - type (e.g., "image") - transfer_method (e.g., "remote_url") - url (the file URL)

Value

A list containing the parsed JSON response from the Dify API.

Examples

## Not run: 
  # Set your Dify API key in the environment or pass it directly
  Sys.setenv(DIFY_API_KEY = "YOUR-DIFY-SECRET-KEY")

  # Basic usage
  response <- DifyChat4R(query = "Hello world!")
  print(response)

  # With conversation context
  response <- DifyChat4R(
    query = "How are you?",
    conversation_id = "conv-123",
    user = "user-456"
  )
  print(response)

## End(Not run)


chatAI4R documentation built on Jan. 10, 2026, 5:07 p.m.