{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from typing import Annotated\n", "from typing_extensions import TypedDict\n", "from langgraph.graph.message import add_messages\n", "from langgraph.prebuilt import create_react_agent\n", "from langchain.tools.render import format_tool_to_openai_function\n", "from nodes.design_rag import DesignRAG\n", "from langchain_openai import ChatOpenAI\n", "from langgraph.prebuilt import ToolNode\n", "from tools.design_retriever import design_retriever_tool\n", "\n", "class State(TypedDict):\n", " # Messages have the type \"list\". The `add_messages` function\n", " # in the annotation defines how this state key should be updated\n", " # (in this case, it appends messages to the list, rather than overwriting them)\n", " messages: Annotated[list, add_messages]\n", "\n", "model = ChatOpenAI(model=\"gpt-4o-mini\", temperature=0)\n", "\n", "tools = [\n", " design_retriever_tool\n", "]\n", "\n", "tool_node = ToolNode(tools=tools)\n", "\n", "model_with_tools = model.bind_tools(tools)\n", "\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'name': 'design_retriever_tool',\n", " 'args': {'state': {'messages': [{'content': 'Can you show me two designs with a comic book style?',\n", " 'type': 'human'}]},\n", " 'num_examples': 2},\n", " 'id': 'call_6GZ0WpBwYGzmioC0p9IyyZ7h',\n", " 'type': 'tool_call'}]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model_with_tools.invoke(\"Can you show me two designs with a comic book style?\").tool_calls" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tool_node.ainvoke({\"messages\": [model_with_tools.invoke(\"Can you show me a design with a comic book style?\")]})" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "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.11.11" } }, "nbformat": 4, "nbformat_minor": 2 }