Reformulate

Reformulate your system responses using LLM

Overview

The llm.reformulate() function allows you to generate reformulated responses based on the description of the intended speaker, creating dynamic and context-aware conversational experiences. With this function, you can engage users through natural language and maintain the essence of your conversation design while providing personalized and relevant responses.

Function Signature

fun reformulate(
    context: Context,
    numTurns: Int = 5,
    personaName: String = "System",
    personaPersonality: String = "You are is helpful, creative, clever, and very friendly.",
    defaultResponse: String = "System",
    prompt: String = "You are roleplaying as $personaName. $personaName is $personaPersonality." +
            "Your goal is to change the words of the following sentence but you are forbidden from changing its meaning. \n" +
            "SENTENCE: $defaultResponse\n\n" +
            "You can also utilize the previous context of the conversation\n",
    config: LLMConfig = LLMConfig()
): String

Parameters

  1. context (Context): The context of the conversation. It contains relevant information about the ongoing conversation, represented as a Context object.

  2. numTurns (Int, optional, default=5): The number of previous turns to consider when generating the response. Defaults to 5.

  3. personaName (String, optional, default="System"): The name of the persona roleplaying in the conversation. By defining a persona, you can give the AI a distinct personality to emulate during interactions.

  4. personaPersonality (String, optional, default="You are helpful, creative, clever, and very friendly."): The personality traits of the persona roleplaying. This parameter helps to define the tone and style of the AI's responses.

  5. defaultResponse (String, optional, default="System"): The default sentence that the AI will attempt to reformulate without changing its meaning. This allows you to set the context for the reformulation task.

  6. prompt (String, optional): A custom prompt for the AI persona. This prompt provides additional context for the AI, guiding it on how to approach the reformulation task effectively. If not provided, a default prompt will be used.

  7. config (LLMConfig, optional): A configuration object of type LLMConfig. This parameter is optional and defaults to the default configuration values.

Return Value

The function returns a String, which is the reformulated response generated by the AI persona based on the input parameters and the provided context.

Example Use Cases

Use Case 1: Contextual Conversation

val context = Context("Previous conversation context...")
val defaultResponse = "Tell me a joke."
val reformulatedResponse = llm.reformulate(context, numTurns = 3, personaName = "Jokester", personaPersonality = "Playful and witty.")
println(reformulatedResponse)

Output:

You are roleplaying as Jokester. Jokester is Playful and witty.
Your goal is to change the words of the following sentence but you are forbidden from changing its meaning. 
SENTENCE: Tell me a joke.

Reformulated Response 1: Share with me a humorous anecdote.
Reformulated Response 2: Please entertain me with a funny story.
Reformulated Response 3: I'd love to hear a witty joke from you.

Use Case 2: Personalized Response

val context = Context("Previous conversation context...")
val defaultResponse = "What's the weather like today?"
val reformulatedResponse = llm.reformulate(context, personaName = "WeatherBot", personaPersonality = "Knowledgeable and informative.")
println(reformulatedResponse)

Output:

You are roleplaying as WeatherBot. WeatherBot is Knowledgeable and informative.
Your goal is to change the words of the following sentence but you are forbidden from changing its meaning. 
SENTENCE: What's the weather like today?

Reformulated Response 1: Can you provide me with the current weather conditions?
Reformulated Response 2: I'm interested to know about the weather situation today.
Reformulated Response 3: Please inform me of today's weather forecast.

Last updated