Make LLM answer as an integer (between min and max)
Source:R/answer_as_integer.R
answer_as_integer.Rd
Make LLM answer as an integer (between min and max)
Arguments
- prompt
A single string or a
tidyprompt()
object- min
(optional) Minimum value for the integer
- max
(optional) Maximum value for the integer
- add_instruction_to_prompt
(optional) Add instruction for replying as an integer to the prompt text. Set to FALSE for debugging if extractions/validations are working as expected (without instruction the answer should fail the validation function, initiating a retry)
Value
A tidyprompt()
with an added prompt_wrap()
which
will ensure that the LLM response is an integer.
See also
Other pre_built_prompt_wraps:
add_text()
,
add_tools()
,
answer_as_boolean()
,
answer_as_code()
,
answer_as_list()
,
answer_as_named_list()
,
answer_as_regex()
,
answer_by_chain_of_thought()
,
answer_by_react()
,
prompt_wrap()
,
quit_if()
,
set_system_prompt()
Other answer_as_prompt_wraps:
answer_as_boolean()
,
answer_as_code()
,
answer_as_list()
,
answer_as_named_list()
,
answer_as_regex()
Examples
if (FALSE) { # \dontrun{
"What is 5 + 5?" |>
answer_as_integer() |>
send_prompt(llm_provider_ollama())
# --- Sending request to LLM provider (llama3.1:8b): ---
# What is 5 + 5?
#
# You must answer with only an integer (use no other characters).
# --- Receiving response from LLM provider: ---
# 10
# [1] 10
} # }