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

Langchain prompt single braces #816

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JannisConen
Copy link

Goal: be able to use single braces in langfuse prompts later interacting with langchain

Why?
I am working a lot with generated latex which kind of revolves around { and }. Also, I am using langchain as a framework. Therefore I am not able to use { and } in my prompts on langfuse because then langchain expects them to hold variables inside them. To escape { and } for langchain, you would use {{ and }} but in langfuse {{ and }} circumenvent variables.

My quick suggestion
First replace all single { and } with temporary placeholders, then have the usual langfuse -> langchain prompt transformation and finally replace the temporary placeholders with double quotes.

I am a little unsure how this might impact the vast variety of prompts there is. Maybe some people use this as a feature to have variables in the prompt for langchain and not mark them variables for langfuse.

@CLAassistant
Copy link

CLAassistant commented Jul 23, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Disclaimer: Experimental PR review

PR Summary

Introduced a mechanism to handle single braces {} in prompts for Langchain compatibility.

  • Modified langfuse/model.py to replace single braces with placeholders before converting double braces for Langchain variables.
  • Added a new test case test_get_langchain_prompt_with_braces in tests/test_langchain.py to verify single brace handling.
  • Ensured backward compatibility and thorough testing to avoid edge cases.

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

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.

2 participants