mirror of
				https://github.com/hwchase17/langchain.git
				synced 2025-11-04 10:10:09 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			98 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			98 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
{
 | 
						|
 "cells": [
 | 
						|
  {
 | 
						|
   "cell_type": "markdown",
 | 
						|
   "metadata": {},
 | 
						|
   "source": [
 | 
						|
    "# LLMCheckerChain\n",
 | 
						|
    "This notebook showcases how to use LLMCheckerChain."
 | 
						|
   ]
 | 
						|
  },
 | 
						|
  {
 | 
						|
   "cell_type": "code",
 | 
						|
   "execution_count": 1,
 | 
						|
   "metadata": {},
 | 
						|
   "outputs": [
 | 
						|
    {
 | 
						|
     "name": "stdout",
 | 
						|
     "output_type": "stream",
 | 
						|
     "text": [
 | 
						|
      "\n",
 | 
						|
      "\n",
 | 
						|
      "\u001b[1m> Entering new LLMCheckerChain chain...\u001b[0m\n",
 | 
						|
      "\n",
 | 
						|
      "\n",
 | 
						|
      "\u001b[1m> Entering new SequentialChain chain...\u001b[0m\n",
 | 
						|
      "\u001b[1mChain 0\u001b[0m:\n",
 | 
						|
      "{'statement': '\\nThe largest mammal that lays eggs is the platypus.'}\n",
 | 
						|
      "\n",
 | 
						|
      "\u001b[1mChain 1\u001b[0m:\n",
 | 
						|
      "{'assertions': '\\n• The largest mammal is the platypus.\\n• The platypus lays eggs.\\n• There is no larger mammal than the platypus that lays eggs.'}\n",
 | 
						|
      "\n",
 | 
						|
      "\u001b[1mChain 2\u001b[0m:\n",
 | 
						|
      "{'checked_assertions': '\\n1. The largest mammal is the platypus. False. The blue whale is the largest mammal.\\n\\n2. The platypus lays eggs. True. The Platypus is one of only two mammals that lay eggs.\\n\\n3. There is no larger mammal than the platypus that lays eggs. False. The echidna is another mammal that lays eggs and is larger than the platypus.'}\n",
 | 
						|
      "\n",
 | 
						|
      "\u001b[1mChain 3\u001b[0m:\n",
 | 
						|
      "{'revised_statement': ' The echidna is the type of mammal that lays the biggest eggs.'}\n",
 | 
						|
      "\n",
 | 
						|
      "\n",
 | 
						|
      "\u001b[1m> Finished SequentialChain chain.\u001b[0m\n",
 | 
						|
      "\n",
 | 
						|
      "\u001b[1m> Finished LLMCheckerChain chain.\u001b[0m\n"
 | 
						|
     ]
 | 
						|
    },
 | 
						|
    {
 | 
						|
     "data": {
 | 
						|
      "text/plain": [
 | 
						|
       "' The echidna is the type of mammal that lays the biggest eggs.'"
 | 
						|
      ]
 | 
						|
     },
 | 
						|
     "execution_count": 1,
 | 
						|
     "metadata": {},
 | 
						|
     "output_type": "execute_result"
 | 
						|
    }
 | 
						|
   ],
 | 
						|
   "source": [
 | 
						|
    "from langchain.chains import LLMCheckerChain\n",
 | 
						|
    "from langchain.llms import OpenAI\n",
 | 
						|
    "\n",
 | 
						|
    "llm = OpenAI(temperature=0.7)\n",
 | 
						|
    "\n",
 | 
						|
    "text = \"What type of mammal lays the biggest eggs?\"\n",
 | 
						|
    "\n",
 | 
						|
    "checker_chain = LLMCheckerChain(llm=llm, verbose=True)\n",
 | 
						|
    "\n",
 | 
						|
    "checker_chain.run(text)"
 | 
						|
   ]
 | 
						|
  },
 | 
						|
  {
 | 
						|
   "cell_type": "code",
 | 
						|
   "execution_count": null,
 | 
						|
   "metadata": {},
 | 
						|
   "outputs": [],
 | 
						|
   "source": []
 | 
						|
  }
 | 
						|
 ],
 | 
						|
 "metadata": {
 | 
						|
  "kernelspec": {
 | 
						|
   "display_name": "Python 3 (ipykernel)",
 | 
						|
   "language": "python",
 | 
						|
   "name": "python3"
 | 
						|
  },
 | 
						|
  "language_info": {
 | 
						|
   "codemirror_mode": {
 | 
						|
    "name": "ipython",
 | 
						|
    "version": 3
 | 
						|
   },
 | 
						|
   "file_extension": ".py",
 | 
						|
   "mimetype": "text/x-python",
 | 
						|
   "name": "python",
 | 
						|
   "nbconvert_exporter": "python",
 | 
						|
   "pygments_lexer": "ipython3",
 | 
						|
   "version": "3.10.8"
 | 
						|
  }
 | 
						|
 },
 | 
						|
 "nbformat": 4,
 | 
						|
 "nbformat_minor": 4
 | 
						|
}
 |