| foundry_chat | R Documentation |
Send a message to an Azure AI Foundry deployed model and receive a response. Returns a tibble with the assistant's response and usage metadata.
foundry_chat(
message,
system = NULL,
model = NULL,
history = NULL,
temperature = NULL,
max_tokens = NULL,
max_completion_tokens = NULL,
top_p = NULL,
frequency_penalty = NULL,
presence_penalty = NULL,
stop = NULL,
reasoning_effort = NULL,
api = c("v1", "deployment"),
api_key = NULL,
api_version = NULL,
...
)
message |
Character. The user message to send. |
system |
Character. Optional system prompt to set the assistant's behavior. |
model |
Character. The deployment name. Defaults to the environment variable
|
history |
List. Optional conversation history as a list of message objects,
each with |
temperature |
Numeric. Sampling temperature between 0 and 2. Higher values make output more random, lower values more deterministic. Default: 1. |
max_tokens |
Integer. Maximum tokens in response (legacy parameter, use
|
max_completion_tokens |
Integer. Maximum tokens in response. Preferred
parameter for newer models (gpt-4o, etc.). Takes precedence over |
top_p |
Numeric. Nucleus sampling parameter between 0 and 1. Default: 1. |
frequency_penalty |
Numeric. Penalty for token frequency (-2.0 to 2.0). Default: 0. |
presence_penalty |
Numeric. Penalty for token presence (-2.0 to 2.0). Default: 0. |
stop |
Character vector. Up to 4 sequences where the API will stop generating. |
reasoning_effort |
Character. Optional reasoning effort ( |
api |
Character. Endpoint style. |
api_key |
Character. Optional API key override. |
api_version |
Character. Optional API version override. |
... |
Additional parameters passed to the API. |
A tibble with columns:
Character. Always "assistant".
Character. The generated response text.
Character. The deployment/model name used.
Character. Why generation stopped: "stop", "length", etc.
Integer. Tokens in the prompt.
Integer. Tokens in the response.
Integer. Hidden reasoning tokens, when reported.
Integer. Cached prompt tokens, when reported.
Integer. Total tokens used.
## Not run:
# Requires a configured Azure endpoint, credentials, and AZURE_FOUNDRY_MODEL
# naming a chat deployment that supports the requested parameters.
# Simple chat
foundry_chat("What is the capital of France?")
# With system prompt
foundry_chat(
"Explain tibbles",
system = "You are a helpful R programming tutor. Be concise."
)
# With parameters (use max_completion_tokens for newer models)
foundry_chat(
"Write a haiku about data science",
temperature = 0.9,
max_completion_tokens = 100
)
# With conversation history
history <- list(
list(role = "user", content = "My name is Alex"),
list(role = "assistant", content = "Hello Alex! How can I help you?")
)
foundry_chat("What's my name?", history = history)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.