-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expression Language for LLM driven template replacements #298
Conversation
core/src/commonMain/kotlin/com/xebia/functional/xef/prompt/expressions/Expression.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to know your opinion about my message
core/src/commonMain/kotlin/com/xebia/functional/xef/prompt/expressions/Expression.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was worried about creating different Expression
s with the same conversationId
, because we create several SYSTEM
messages in the middle of the conversation
After my local tests, this is not really a problem. I have created 2 different plans with the same conversationId
and got the expected results and did not mix the messages.
Anyway, Expression
now has no control over the conversations, we are always using the conversation in the Scope
. Maybe we should provide a way for doing that by passing a conversationId
as a parameter in Expression.run
. It's just a suggestion
🚀 LGTM!
* Add wikipedia search * Add encodeURLQueryComponent() * Format * Expression Language for LLM driven template replacements (#298) * Expression Language for LLM driven template replacements * Prompt adjustments * Prompt adjustments and better structure for building final prompt based on messages * Spotless Apply (#304) * add encodeURLQueryComponent() * Add wikipedia search * Add encodeURLQueryComponent() * Format * add encodeURLQueryComponent() --------- Co-authored-by: Raúl Raja Martínez <[email protected]> Co-authored-by: Javi Pacheco <[email protected]>
The
Expression
class is a utility class designed to simplify the process of creating and running expressions for a chatbot or conversational AI system. It provides a fluent API for building expressions with different roles (SYSTEM, USER, and ASSISTANT) and generating dynamic prompts with variable keys.Here's a breakdown of the key components and functionalities of the
Expression
class:Constructor:
Expression
class takes three parameters:scope
,model
, and ablock
function.scope
is an instance ofCoreAIScope
,model
is an instance ofChatWithFunctions
, andblock
is a lambda function that takes asuspend Expression.() -> Unit
as its parameter. Theblock
function is used to define the sequence of messages and prompts within the expression.Logging:
KotlinLogging
library to create an instance ofKLogger
for logging purposes.Messages and Generation Keys:
messages
andgenerationKeys
. Themessages
list stores messages with different roles (SYSTEM, USER, ASSISTANT) that are added using thesystem
,user
, andassistant
functions. ThegenerationKeys
list keeps track of variable keys used in the prompts, which are added using theprompt
function.Message Builders:
system
,user
, andassistant
functions are used to add messages to themessages
list with the corresponding roles.Prompt Generation:
prompt
function is used to generate prompts with variable keys (e.g., {{$key}}) and store the variable keys in thegenerationKeys
list.run
Function:run
function executes the expression defined in theblock
function. It builds an instruction message using anExpertSystem
, adds it to themessages
list, and then runs the prompt messages using themodel.prompt
function. The function also replaces the variable keys in the prompts with actual values obtained from the chatbot response.companion object run
Function:run
function within thecompanion object
allows for a concise way of creating and executing anExpression
instance. It is a convenience function that takes ascope
,model
, and ablock
lambda as arguments, and it automatically calls therun
function on theExpression
instance.New methods for the
Chat
interface that can consume a list ofMessage
instead of aString
or aPrompt
The code example below demonstrates how to use the
Expression
class to create a workout plan based on user input and the responses generated by the assistant.