LLM Functions

Christopher Wolfram

Connecting to an LLM

ServiceConnect["OpenAI"]

(*SystemCredential["OPENAI_API_KEY"]="..."*)

LLMSynthesize

LLMSynthesize["Write a single-stanza poem about a koala."]

LLMSynthesize["I'm doing a road trip from Chicago to Boston. Name a city that I should stop in along the way."]

LLMSynthesize["I'm doing a road trip from Chicago to Boston. Name a city that I should stop in along the way. Write only the name of the city and nothing else."]

LLMPrompt["NothingElse","city"]

LLMSynthesize[{
LLMPrompt["NothingElse","city"],
"I'm doing a road trip from Chicago to Boston. Name a city that I should stop in along the way."
}]

LLMSynthesize[{
LLMPrompt["NothingElse","city"],
"I'm doing a road trip from Chicago to Boston. Name a city that I should stop in along the way."
},"PromptText"]

LLMFunction

LLMFunction["Reverse this string ``"]["hello there!"]

LLMSynthesize[StringTemplate["Reverse this string ``"]["hello there!"]]

LLMFunction["Reverse this string ``"][(Entity["Chicago", Entity["City",{"Chicago","Illinois","UnitedStates"}], "Entity[\"City\", {\"Chicago\", \"Illinois\", \"UnitedStates\"}]", "city"])]

llmfunc=LLMFunction[{
LLMPrompt["NothingElse","city"],
"I'm doing a road trip from `1` to `2`. Name a city that I should stop in along the way."
},"City"]

llmfunc[,]

ChatObject / ChatEvaluate

chat=ChatObject["You are Socrates. Always respond as an ancient greek philosopher would."];
chat//=ChatEvaluate["Hello! How are you?"];
chat//=ChatEvaluate["What's the weather like?"];

chat

chat["Messages"]

ChatEvaluate[chat,"What's the weather like where you are?"]

LLMEvaluator / LLMConfiguration

LLMSynthesize
LLMFunction
ChatObject
ChatEvaluate

$LLMEvaluator=LLMConfiguration["Prompts"->{LLMPrompt["ELI5"],"Answer as Socrates."}]

LLMSynthesize["What is a circle?"]

LLMSynthesize["Write a single-stanza poem about a koala.",LLMEvaluator-><|"Model"->"gpt-4"|>]

LLMSynthesize["Write a single-stanza poem about a koala.",LLMEvaluator-><|"Temperature"->2|>,MaxItems->100]

LLMTool

tool=LLMTool["cityPopulationFinder","city"->"City",#city["Population"]&]

LLMSynthesize["Write a few sentences about Chicago. Use the tool!",LLMEvaluator-><|"Tools"->tool|>]