Skip to content

Commit

Permalink
feat(persistence.ipynb): add workflow execution
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Sep 2, 2024
1 parent f09aeb6 commit c4bf081
Showing 1 changed file with 120 additions and 12 deletions.
132 changes: 120 additions & 12 deletions how-tos/persistence.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -13,19 +13,69 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[0mRepository \u001b[1m\u001b[32mlocal\u001b[0m url: \u001b[1m\u001b[32mfile:///Users/bsorrentino/.m2/repository/\u001b[0m added.\n",
"\u001b[0mRepositories count: 5\n",
"\u001b[0mname: \u001b[1m\u001b[32mcentral \u001b[0murl: \u001b[1m\u001b[32mhttps://repo.maven.apache.org/maven2/ \u001b[0mrelease:\u001b[32mtrue \u001b[0mupdate:\u001b[32mnever \u001b[0msnapshot:\u001b[32mfalse \u001b[0mupdate:\u001b[32mnever \n",
"\u001b[0m\u001b[0mname: \u001b[1m\u001b[32mjcenter \u001b[0murl: \u001b[1m\u001b[32mhttps://jcenter.bintray.com/ \u001b[0mrelease:\u001b[32mtrue \u001b[0mupdate:\u001b[32mnever \u001b[0msnapshot:\u001b[32mfalse \u001b[0mupdate:\u001b[32mnever \n",
"\u001b[0m\u001b[0mname: \u001b[1m\u001b[32mjboss \u001b[0murl: \u001b[1m\u001b[32mhttps://repository.jboss.org/nexus/content/repositories/releases/ \u001b[0mrelease:\u001b[32mtrue \u001b[0mupdate:\u001b[32mnever \u001b[0msnapshot:\u001b[32mfalse \u001b[0mupdate:\u001b[32mnever \n",
"\u001b[0m\u001b[0mname: \u001b[1m\u001b[32matlassian \u001b[0murl: \u001b[1m\u001b[32mhttps://packages.atlassian.com/maven/public \u001b[0mrelease:\u001b[32mtrue \u001b[0mupdate:\u001b[32mnever \u001b[0msnapshot:\u001b[32mfalse \u001b[0mupdate:\u001b[32mnever \n",
"\u001b[0m\u001b[0mname: \u001b[1m\u001b[32mlocal \u001b[0murl: \u001b[1m\u001b[32mfile:///Users/bsorrentino/.m2/repository/ \u001b[0mrelease:\u001b[32mtrue \u001b[0mupdate:\u001b[32mnever \u001b[0msnapshot:\u001b[32mtrue \u001b[0mupdate:\u001b[32malways \n",
"\u001b[0m"
]
}
],
"source": [
"%dependency /add-repo local \\{localRespoUrl} release|never snapshot|never\n",
"%dependency /add-repo local \\{localRespoUrl} release|never snapshot|always\n",
"%dependency /list-repos\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Adding dependency \u001b[0m\u001b[1m\u001b[32morg.bsc.langgraph4j:langgraph4j-core-jdk8:1.0-SNAPSHOT\n",
"\u001b[0mAdding dependency \u001b[0m\u001b[1m\u001b[32mdev.langchain4j:langchain4j:0.33.0\n",
"\u001b[0mAdding dependency \u001b[0m\u001b[1m\u001b[32mdev.langchain4j:langchain4j-open-ai:0.33.0\n",
"\u001b[0mSolving dependencies\n",
"Resolved artifacts count: 22\n",
"Add to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/org/bsc/langgraph4j/langgraph4j-core-jdk8/1.0-SNAPSHOT/langgraph4j-core-jdk8-1.0-SNAPSHOT.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/org/bsc/async/async-generator-jdk8/2.0.1/async-generator-jdk8-2.0.1.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/org/slf4j/slf4j-api/2.0.9/slf4j-api-2.0.9.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/dev/langchain4j/langchain4j/0.33.0/langchain4j-0.33.0.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/dev/langchain4j/langchain4j-core/0.33.0/langchain4j-core-0.33.0.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/com/google/code/gson/gson/2.10.1/gson-2.10.1.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/org/apache/opennlp/opennlp-tools/1.9.4/opennlp-tools-1.9.4.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/org/jsoup/jsoup/1.16.1/jsoup-1.16.1.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/dev/langchain4j/langchain4j-open-ai/0.33.0/langchain4j-open-ai-0.33.0.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/dev/ai4j/openai4j/0.17.0/openai4j-0.17.0.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/com/squareup/retrofit2/retrofit/2.9.0/retrofit-2.9.0.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/com/squareup/retrofit2/converter-gson/2.9.0/converter-gson-2.9.0.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/com/squareup/okhttp3/okhttp/4.12.0/okhttp-4.12.0.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/com/squareup/okio/okio/3.6.0/okio-3.6.0.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/com/squareup/okio/okio-jvm/3.6.0/okio-jvm-3.6.0.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/org/jetbrains/kotlin/kotlin-stdlib-common/1.9.10/kotlin-stdlib-common-1.9.10.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.8.21/kotlin-stdlib-jdk8-1.8.21.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/org/jetbrains/kotlin/kotlin-stdlib/1.8.21/kotlin-stdlib-1.8.21.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/org/jetbrains/annotations/13.0/annotations-13.0.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.8.21/kotlin-stdlib-jdk7-1.8.21.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/com/squareup/okhttp3/okhttp-sse/4.12.0/okhttp-sse-4.12.0.jar\u001b[0m\n",
"\u001b[0mAdd to classpath: \u001b[0m\u001b[32m/Users/bsorrentino/Library/Jupyter/kernels/rapaio-jupyter-kernel/mima_cache/com/knuddels/jtokkit/1.1.0/jtokkit-1.1.0.jar\u001b[0m\n",
"\u001b[0m"
]
}
],
"source": [
"%dependency /add org.bsc.langgraph4j:langgraph4j-core-jdk8:1.0-SNAPSHOT\n",
"%dependency /add dev.langchain4j:langchain4j:\\{langchain4jVersion}\n",
Expand Down Expand Up @@ -90,7 +140,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -143,7 +193,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -188,7 +238,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -221,9 +271,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"SLF4J: No SLF4J providers were found.\n",
"SLF4J: Defaulting to no-operation (NOP) logger implementation\n",
"SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"AiMessage { text = null toolExecutionRequests = [ToolExecutionRequest { id = \"call_Rl3APUhjZUXSd3M82rUfMAtt\", name = \"execQuery\", arguments = \"{\"query\":\"London weather forecast for tomorrow\"}\" }] }\n"
]
}
],
"source": [
"import dev.langchain4j.agent.tool.ToolSpecification;\n",
"import dev.langchain4j.agent.tool.ToolSpecifications;\n",
Expand Down Expand Up @@ -254,7 +321,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -328,6 +395,47 @@
"\n",
"var graph = workflow.compile();"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"__START__\n",
"{messages=[AiMessage { text = \"Hi I'm Bartolo, niced to meet you.\" toolExecutionRequests = null }, AiMessage { text = \"Hello Bartolo! Nice to meet you too. How can I assist you today?\" toolExecutionRequests = null }]}\n",
"agent\n",
"{messages=[AiMessage { text = \"Hi I'm Bartolo, niced to meet you.\" toolExecutionRequests = null }, AiMessage { text = \"Hello Bartolo! Nice to meet you too. How can I assist you today?\" toolExecutionRequests = null }]}\n",
"__END__\n",
"{messages=[AiMessage { text = \"Hi I'm Bartolo, niced to meet you.\" toolExecutionRequests = null }, AiMessage { text = \"Hello Bartolo! Nice to meet you too. How can I assist you today?\" toolExecutionRequests = null }]}\n"
]
}
],
"source": [
"import dev.langchain4j.data.message.AiMessage;\n",
"\n",
"Map<String,Object> inputs = Map.of( \"messages\", AiMessage.from(\"Hi I'm Bartolo, niced to meet you.\") );\n",
"\n",
"var result = graph.stream( inputs );\n",
"\n",
"for( var r : result ) {\n",
"\n",
"\n",
" System.out.println( r.node() );\n",
" System.out.println( r.state() );\n",
"// if (msg?.content) {\n",
"// console.log(msg.content);\n",
"// } else if (msg?.tool_calls?.length > 0) {\n",
"// console.log(msg.tool_calls);\n",
"// } else {\n",
"// console.log(msg);\n",
"// }\n",
"// console.log(\"-----\\n\");\n",
"}"
]
}
],
"metadata": {
Expand Down

0 comments on commit c4bf081

Please sign in to comment.