docs: format (#17143)

This commit is contained in:
Erick Friis 2024-02-06 16:32:53 -08:00 committed by GitHub
parent 2187268208
commit d397721a34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 21 additions and 15 deletions

View File

@ -90,16 +90,20 @@
} }
], ],
"source": [ "source": [
"system = \"You are a helpful assistant that translates {input_language} to {output_language}.\"\n", "system = (\n",
" \"You are a helpful assistant that translates {input_language} to {output_language}.\"\n",
")\n",
"human = \"{text}\"\n", "human = \"{text}\"\n",
"prompt = ChatPromptTemplate.from_messages([(\"system\", system), (\"human\", human)])\n", "prompt = ChatPromptTemplate.from_messages([(\"system\", system), (\"human\", human)])\n",
"\n", "\n",
"chain = prompt | chat\n", "chain = prompt | chat\n",
"chain.invoke({\n", "chain.invoke(\n",
" \"input_language\": \"English\",\n", " {\n",
" \"output_language\": \"Korean\",\n", " \"input_language\": \"English\",\n",
" \"text\": \"I love Python\",\n", " \"output_language\": \"Korean\",\n",
"})" " \"text\": \"I love Python\",\n",
" }\n",
")"
] ]
}, },
{ {

View File

@ -424,9 +424,7 @@
"human = \"{text}\"\n", "human = \"{text}\"\n",
"prompt = ChatPromptTemplate.from_messages([(\"system\", system), (\"human\", human)])\n", "prompt = ChatPromptTemplate.from_messages([(\"system\", system), (\"human\", human)])\n",
"\n", "\n",
"chat = ChatVertexAI(\n", "chat = ChatVertexAI(model_name=\"chat-bison\", max_output_tokens=1000, temperature=0.5)\n",
" model_name=\"chat-bison\", max_output_tokens=1000, temperature=0.5\n",
")\n",
"chain = prompt | chat\n", "chain = prompt | chat\n",
"\n", "\n",
"asyncio.run(\n", "asyncio.run(\n",

View File

@ -460,9 +460,7 @@
"Given a user question, write the Python code to answer it. \\\n", "Given a user question, write the Python code to answer it. \\\n",
"Return ONLY the valid Python code and nothing else. \\\n", "Return ONLY the valid Python code and nothing else. \\\n",
"Don't assume you have access to any libraries other than built-in Python ones and pandas.\"\"\"\n", "Don't assume you have access to any libraries other than built-in Python ones and pandas.\"\"\"\n",
"prompt = ChatPromptTemplate.from_messages(\n", "prompt = ChatPromptTemplate.from_messages([(\"system\", system), (\"human\", \"{question}\")])\n",
" [(\"system\", system), (\"human\", \"{question}\")]\n",
")\n",
"code_chain = prompt | llm_with_tools | parser\n", "code_chain = prompt | llm_with_tools | parser\n",
"code_chain.invoke({\"question\": \"What's the correlation between age and fare\"})" "code_chain.invoke({\"question\": \"What's the correlation between age and fare\"})"
] ]

View File

@ -721,7 +721,9 @@
"\n", "\n",
"If the question does not seem related to the database, just return \"I don't know\" as the answer.\"\"\"\n", "If the question does not seem related to the database, just return \"I don't know\" as the answer.\"\"\"\n",
"\n", "\n",
"prompt = ChatPromptTemplate.from_messages([(\"system\", system), (\"human\", \"{input}\"), MessagesPlaceholder(\"agent_scratchpad\")])\n", "prompt = ChatPromptTemplate.from_messages(\n",
" [(\"system\", system), (\"human\", \"{input}\"), MessagesPlaceholder(\"agent_scratchpad\")]\n",
")\n",
"agent = create_sql_agent(\n", "agent = create_sql_agent(\n",
" llm=llm,\n", " llm=llm,\n",
" db=db,\n", " db=db,\n",

View File

@ -294,11 +294,15 @@
"First draft: <<FIRST_DRAFT_QUERY>>\n", "First draft: <<FIRST_DRAFT_QUERY>>\n",
"Final answer: <<FINAL_ANSWER_QUERY>>\n", "Final answer: <<FINAL_ANSWER_QUERY>>\n",
"\"\"\"\n", "\"\"\"\n",
"prompt = ChatPromptTemplate.from_messages([(\"system\", system), (\"human\", \"{input}\")]).partial(dialect=db.dialect)\n", "prompt = ChatPromptTemplate.from_messages(\n",
" [(\"system\", system), (\"human\", \"{input}\")]\n",
").partial(dialect=db.dialect)\n",
"\n",
"\n", "\n",
"def parse_final_answer(output: str) -> str:\n", "def parse_final_answer(output: str) -> str:\n",
" return output.split(\"Final answer: \")[1]\n", " return output.split(\"Final answer: \")[1]\n",
" \n", "\n",
"\n",
"chain = create_sql_query_chain(llm, db, prompt=prompt) | parse_final_answer\n", "chain = create_sql_query_chain(llm, db, prompt=prompt) | parse_final_answer\n",
"prompt.pretty_print()" "prompt.pretty_print()"
] ]