Skip to content

Commit d1a7f32

Browse files
gustavocidornelaswhoseoyster
authored andcommitted
Define model config variables in separate cells to avoid calling OpenAI unnecessarily
1 parent 46f1f0a commit d1a7f32

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

examples/llms/langchain/question-answering/question-answering.ipynb

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,16 @@
126126
"system_message_prompt = SystemMessagePromptTemplate.from_template(template)\n",
127127
"\n",
128128
"human_template = \"{question}\"\n",
129-
"human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)\n",
130-
"\n",
129+
"human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)"
130+
]
131+
},
132+
{
133+
"cell_type": "code",
134+
"execution_count": null,
135+
"id": "bbd06c94",
136+
"metadata": {},
137+
"outputs": [],
138+
"source": [
131139
"chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])"
132140
]
133141
},
@@ -485,6 +493,20 @@
485493
"Let's create a `model_config` for our model:"
486494
]
487495
},
496+
{
497+
"cell_type": "code",
498+
"execution_count": null,
499+
"id": "1053c839",
500+
"metadata": {},
501+
"outputs": [],
502+
"source": [
503+
"# Useful variable that will also go into our config\n",
504+
"template = \"\"\"You are a helpful assistant who answers user's questions about Python.\n",
505+
"A user will pass in a question, and you should answer it very objectively.\n",
506+
"Use AT MOST 5 sentences. If you need more than 5 sentences to answer, say that the\n",
507+
"user should make their question more objective.\"\"\""
508+
]
509+
},
488510
{
489511
"cell_type": "code",
490512
"execution_count": null,
@@ -498,7 +520,7 @@
498520
" \"modelType\": \"shell\",\n",
499521
" \"prompt\": [ # Optionally log the prompt, following the same format as OpenAI\n",
500522
" {\"role\": \"system\", \"content\": template}, \n",
501-
" {\"role\": \"user\", \"content\": human_template}\n",
523+
" {\"role\": \"user\", \"content\": \"{question}\"}\n",
502524
" ], \n",
503525
" \"metadata\": { # Can add anything here, as long as it is a dict\n",
504526
" \"output_parser\": None,\n",

0 commit comments

Comments
 (0)