Title: | What the Package Does (Title Case) |
---|---|
Description: | More about what it does (maybe more than one line) Use four spaces when indenting paragraphs within the Description. |
Authors: | Who wrote it |
Maintainer: | The package maintainer <[email protected]> |
License: | What license is it under? |
Version: | 0.1.0 |
Built: | 2024-11-07 20:14:40 UTC |
Source: | https://github.com/ecohealthalliance/ehallm |
Format the function call dataframe. Nest parameters based on the group column and format the list structure for conversion to JSON
format_function_call_df(function_call_df)
format_function_call_df(function_call_df)
function_call_df |
A formatted tibble
function_call_df <- get_function_call_params() |> format_function_call_df()
function_call_df <- get_function_call_params() |> format_function_call_df()
Convert the JSON formatted openAI responses into a more human readable nested tibble.
format_openai_results(model_response)
format_openai_results(model_response)
model_response |
A nested tibble
#' specific_context <- "Chronic wasting disease (CWD) is a fatal, prion disease of cervids that was first detected in Alberta in 2005" common_context <- "Please use the extract_outbreak_data function to extract outbreak details from the given abstract and return only the results" chat_results <- openai_chat(specific_context, common_context) formatted_chat_results <- format_openai_results(chat_results)
#' specific_context <- "Chronic wasting disease (CWD) is a fatal, prion disease of cervids that was first detected in Alberta in 2005" common_context <- "Please use the extract_outbreak_data function to extract outbreak details from the given abstract and return only the results" chat_results <- openai_chat(specific_context, common_context) formatted_chat_results <- format_openai_results(chat_results)
Arrange parameter details in JSON schema format
get_function_call_parameter( parameter_name, description, type = c("string", "null"), enum = NULL )
get_function_call_parameter( parameter_name, description, type = c("string", "null"), enum = NULL )
parameter_name |
The name of the parameter openAI should return |
description |
A description of the parameter. OpenAI will use this description to construct it's response |
type |
What type or types are allowed in OpenAI's response. i.e. c("string", "null") constrains openAI to returning a character string or NULL. |
enum |
A list of the return values that OpenAI should adhere to when choosing a response. |
A formatted and named parameter list
function_call_parameter <- get_function_call_parameter("disease", "The outbreak event disease name")
function_call_parameter <- get_function_call_parameter("disease", "The outbreak event disease name")
Construct a tibble of parameters that openAI will return and specify constraints such as type and enumeration
get_function_call_params(country = NA, disease = NA)
get_function_call_params(country = NA, disease = NA)
country |
Country context can be added to parameter descriptions by modifying the tribble to include glue or paste statements |
disease |
Disease context can be added to parameter descriptions by modifying the tribble to include glue or paste statements |
A tibble outlining the parameters that openAI should use in it's reply. Will be further processed by format_function_call_df
function_call_params <- get_function_call_params()
function_call_params <- get_function_call_params()
context aware openai function call.
get_openai_function_call( country = NA, disease = NA, function_name = "exract_outbreak_data", function_description = "Extract outbreak details from provided abstract" )
get_openai_function_call( country = NA, disease = NA, function_name = "exract_outbreak_data", function_description = "Extract outbreak details from provided abstract" )
country |
Passed to get_function_call_params if parameter descriptions need to include context |
disease |
Passed to get_function_call_params if parameter descriptions need to include context |
function_name |
The name of the imaginary function openAI will be formatting it's response for. Should be descriptive of the desired task it will perform. |
function_description |
# A description of the what the function would accomplish |
Returns a list containing a formatted function call as an R list, as a compact JSON, a pretty JSON, and a tibble of the parameters used in constructing the call.
function_call <- get_openai_function_call()
function_call <- get_openai_function_call()
Initiate a conversation with openAI using the provided model and system, common, and specific context. Note: to use these functions you need to provide an openai key in the .env file as in:
openai_chat( specific_context, common_context, hint = NA, model = "gpt-3.5-turbo", system_context = "You act as a function to extract outbreak infromation from a provided abstract." )
openai_chat( specific_context, common_context, hint = NA, model = "gpt-3.5-turbo", system_context = "You act as a function to extract outbreak infromation from a provided abstract." )
specific_context |
This is the text specific to each query you would like OpenAI to consider |
common_context |
This is the text OpenAI should consider in every query |
hint |
An optional hint to get OpenAI on the right track. |
model |
The identity of the model you would like to submit the context to. |
system_context |
Text explaining to the model what role you would like it to play. In example, "Respond as if you an 18th century naturalist." |
A tibble containing the responses from openAI for each query
specific_context <- "Chronic wasting disease (CWD) is a fatal, prion disease of cervids that was first detected in Alberta in 2005" common_context <- "Please use the extract_outbreak_data function to extract outbreak details from the given abstract and return only the results" chat_results <- openai_chat(specific_context, common_context)
specific_context <- "Chronic wasting disease (CWD) is a fatal, prion disease of cervids that was first detected in Alberta in 2005" common_context <- "Please use the extract_outbreak_data function to extract outbreak details from the given abstract and return only the results" chat_results <- openai_chat(specific_context, common_context)