diff --git a/week2/day4.ipynb b/week2/day4.ipynb index 0151e7d..75d498d 100644 --- a/week2/day4.ipynb +++ b/week2/day4.ipynb @@ -173,28 +173,6 @@ "\n", "What we actually do is give the LLM the opportunity to inform us that it wants us to run the tool.\n", "\n", - "Here's how the new chat function looks:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ce9b0744-9c78-408d-b9df-9f6fd9ed78cf", - "metadata": {}, - "outputs": [], - "source": [ - "def chat(message, history):\n", - " messages = [{\"role\": \"system\", \"content\": system_message}] + history + [{\"role\": \"user\", \"content\": message}]\n", - " response = openai.chat.completions.create(model=MODEL, messages=messages, tools=tools)\n", - "\n", - " if response.choices[0].finish_reason==\"tool_calls\":\n", - " message = response.choices[0].message\n", - " response, city = handle_tool_call(message)\n", - " messages.append(message)\n", - " messages.append(response)\n", - " response = openai.chat.completions.create(model=MODEL, messages=messages)\n", - " \n", - " return response.choices[0].message.content" ] }, { @@ -219,6 +197,27 @@ " return response, city" ] }, +{ + "cell_type": "code", + "execution_count": null, + "id": "ce9b0744-9c78-408d-b9df-9f6fd9ed78cf", + "metadata": {}, + "outputs": [], + "source": [ + "def chat(message, history):\n", + " messages = [{\"role\": \"system\", \"content\": system_message}] + history + [{\"role\": \"user\", \"content\": message}]\n", + " response = openai.chat.completions.create(model=MODEL, messages=messages, tools=tools)\n", + "\n", + " if response.choices[0].finish_reason==\"tool_calls\":\n", + " message = response.choices[0].message\n", + " response, city = handle_tool_call(message)\n", + " messages.append(message)\n", + " messages.append(response)\n", + " response = openai.chat.completions.create(model=MODEL, messages=messages)\n", + " \n", + " return response.choices[0].message.content" + ] + }, { "cell_type": "code", "execution_count": null,