Joke evaluator part two

In the second half of the joke evaluator assignment we are going to add an additional requirement for jokes - originality. We will do this by building a database of jokes. Each time a user proposes a new joke we will compare it against the jokes already in the database to see whether or not the joke is sufficiently original. If it is not original enough we will show them the existing joke that their joke is too close to and ask them to try again.

To implement the joke database we will use the RAG technique with a chroma database as described in chapter six. Each time we obtain a new joke from a user we will store that joke in a chroma database. Each time a new user proposes a new joke we will pull three similar jokes from the database and pass the new joke along with the three existing jokes to an LLM and ask the LLM to judge whether or not the new joke is too close to one of the exising jokes. If the LLM thinks that the proposed joke is too similar to one of the existing ones it will return that information to us so we can show the user the existing joke that is too close to their proposed joke and ask them to try again.

What to do

Start with your solution to assignment three. Add some code to set up a chroma database to store jokes.

Write a prefill() function that asks the LLM to write 20 chicken jokes. Store those 20 jokes in the database.

Add a new node to your langgraph graph. This node will sit between the prompt node and the classify node. This node will take the joke the user entered and pull the three most similar jokes from the database. The node will then pass the user's proposed joke and the three closest jokes to the LLM and ask it whether or not the proposed joke is too similar to one of the existing ones. If it thinks that the new joke is too close to one of the existing ones, the node will print the existing joke for the user to see and route them back to the prompt node. If the LLM thinks that the new joke is original enough, you can go on to the classify node instead.