Skip to content
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

Kotlin prompt chain #173

Closed
wants to merge 7 commits into from
Closed

Kotlin prompt chain #173

wants to merge 7 commits into from

Conversation

necosta
Copy link
Contributor

@necosta necosta commented Jun 7, 2023

I need some input on this one, can't find an elegant solution for prompt templating in Kotlin and Scala.

See #157 (comment) , initially prompt "chaining" was implemented in Scala, should be both in Scala and Kotlin which is now done in this PR.

I'm unsure how to call the Kotlin chain method from Scala, there seems to be some limitations on Kotlin, trying to get to the bottom of it.

Using loom to call chain method from Kotlin in Scala, removed PromptTemplate logic.

Ready for review.

Comment on lines +19 to +22
val playScore = Play("The power of Zuluastral", "Modern Era")
.chain<Play, Synopsis>(this) { play -> synopsisTemplate(play) }
.chain<Synopsis, Review>(this) { synopsis -> reviewTemplate(synopsis) }
.chain<Review, Score>(this) { review -> scoreTemplate(review) }
Copy link
Contributor

@nomisRev nomisRev Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure I understand the benefit over 🤔

val play = Play("The power of Zuluastral", "Modern Era")
val synopsis: Synopsis  = prompt(synopsisTemplate(play))
val review: Review = prompt(reviewTemplate(synopsis))
val score: Score = prompt(scoreTemplate(review))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your point and it has been an ongoing discussion on how much prompt "templating/chaining" adds to the basic functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion we should keep it as it enhances the API for chaining prompts. (but of course we can chain prompts without this new functionality)
Lets try to get more opinions, I'm ok to remove it if we go in the direction of minimum API extensions possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are several issue to consider here from an OSS / Library maintenance point of view.

  1. Duplicated APIs, cause confusion for users to use 1 way over the other.
  2. More code results in higher maintenance
  3. With the current work we're doing in core this brings the question on how we can make this Java friendly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We took a similar decision some time ago, removing chains in favor of being more explicit (or just use function composition!)

Chaining makes more sense in a LangChain-style API, in which you put the results of AI calls under keys in the context. Since all elements of the chain share the context, this is the main way to share data between agents. However, we want a more explicit style, hence the much less powerful design of contexts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the solution discussed in this thread. Although the chain approach had also influenced me, I comprehend and acknowledge the perspectives shared by Alex and Simon. My apologies, @necosta, for the additional effort needed in this matter. 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. I also understand this goes in a direction that we may not want to take just yet.
I'll close this PR and create a new one removing the Scala logic in this area.
thanks all for your comments.

@necosta necosta changed the title WIP: Kotlin prompt chain Kotlin prompt chain Jun 7, 2023
@necosta necosta closed this Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants