Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions asciidoc/courses/genai-workshop/course.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
:usecase: recommendations
:key-points: A comma, separated, list of learnings
:repository: neo4j-graphacademy/genai-workshop
:allow-llm-calls: true
:llm-call-limit: 0

== Course Description

In this GenAI and Neo4j workshop, you will learn how Neo4j can support your GenAI projects.
In this GenAI and Neo4j workshop, you will learn how Neo4j can support your GenAI projects.

You will:
You will:

* Use Vector indexes and embeddings in Neo4j to perform similarity and keyword search
* Use Python and LangChain to integrate with Neo4j and OpenAI
Expand All @@ -34,7 +36,7 @@ While not essential, we completing the GraphAcademy link:/courses/neo4j-fundamen

== What you need

To complete the practical tasks within this workshop, you will need:
To complete the practical tasks within this workshop, you will need:

* Access to gitpod.io (you will need a github, gitpod, or bitbucket account) or a local Python environment
* An OpenAI billing account and API key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:disable-cache: true

We have created a link:https://github.com/neo4j-graphacademy/genai-workshop[repository^] for this workshop.
It contains the starter code and resources you need.
It contains the starter code and resources you need.

A blank Neo4j Sandbox instance has also been created for you to use during this course.

Expand Down Expand Up @@ -48,7 +48,7 @@ pip install -r requirements.txt

== Setup the environment

Create a copy of the `.env.example` file and name it `.env`.
Create a copy of the `.env.example` file and name it `.env`.
Fill in the required values.

[source]
Expand All @@ -57,7 +57,7 @@ Fill in the required values.
include::{repository-raw}/main/.env.example[]
----

Add your Open AI API key (`OPENAI_API_KEY`), which you can get from link:https://platform.openai.com[platformn.openai.com].
Add your Open AI API key (`OPENAI_API_KEY`), which you can get from link:https://platform.openai.com[platform.openai.com].

Update the Neo4j sandbox connection details:

Expand Down
6 changes: 5 additions & 1 deletion asciidoc/courses/llm-chatbot-python/course.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
// :video: https://www.youtube.com/embed/vVCHJFa01gA
:key-points: Building a Neo4j-backed Chatbot, Neo4j & Langchain, Neo4j & Streamlit
:repository: neo4j-graphacademy/llm-chatbot-python
:allow-llm-calls: true
:llm-call-limit: 50
:llm-call-limit-period: PT2M


== Course Description

In this hands-on course, you will use the knowledge obtained from the link:/courses/llm-fundamentals[Neo4j & LLM Fundamentals course^] to create a Movie Recommendation Chatbot backed by a Neo4j database.
In this hands-on course, you will use the knowledge from the link:/courses/llm-fundamentals[Neo4j & LLM Fundamentals course^] to create a Movie Recommendation Chatbot backed by a Neo4j database.

You will take a simple chat interface that repeats the user's input and modify it to answer questions about movies via the Neo4j Recommendations Dataset using _GPT 3.5 Turbo_, complete with conversational history.

Expand Down
5 changes: 4 additions & 1 deletion asciidoc/courses/llm-chatbot-typescript/course.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
:reward-form: https://graphacademy.neo4j.com/account/rewards/llm-chatbot-typescript/
:reward-provider: printful
:reward-product-id: @65f874e831d488,@65f875094279d1
:allow-llm-calls: true
:llm-call-limit: 20
:llm-call-limit-period: PT2M

== Course Description
at

In this hands-on course, you will use the knowledge obtained from the link:/courses/llm-fundamentals[Neo4j & LLM Fundamentals course^] to create a Movie Recommendation Chatbot backed by a Neo4j database.

You will take a simple chat interface that repeats the user's input and modify it to answer questions about movies via the Neo4j Recommendations Dataset using GPT-4, complete with conversation history.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,30 @@ NEO4J_USERNAME="{sandbox_username}"
NEO4J_PASSWORD="{sandbox_password}"
----

You must also set your OpenAI API key.
You can find link:https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key[instructions on generating an API key on openai.com^].
You will also need an API Key to generate LLM responses using OpenAI.

We have generated an OpenAI API key for you to use through our OpenAI Proxy for the duration of this course using a proxy.
The API key will be limited to 5 requests every two minutes.


Replace the `OPENAI_API_KEY` value with your OpenAI API key.

.env.local
[source,env]
[source,env,subs="attributes+"]
----
OPENAI_API_KEY="sk-..."
OPENAI_API_KEY="{llm-api-key}"
OPENAI_API_BASE="{llm-api-base}"
----

If you find the rate limits restricting, you can always use an OpenAI API Key.
In this case, you would omit the Base URL.
You can find link:https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key[instructions on generating an API key on openai.com^].

This course's challenges do not require you use OpenAI LLMs, so feel free to use an alternative LLM provider.
We also like link:https://ollama.com/[Ollama^].



[WARNING]
.Keep your secrets safe
====
Expand Down Expand Up @@ -151,6 +164,6 @@ include::questions/1-server.adoc[leveloffset=+1]
[.summary]
== Summary

In this lesson, you obtained a copy of the course code, installed the dependency and used the `npm run dev` command to start the app.
In this lesson, you obtained a copy of the course code, installed the dependency, and used the `npm run dev` command to start the app.

In the next lesson, you will set the scope for the project.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ You can link:https://js.langchain.com/docs/expression_language/[read more about
In the link:https://graphacademy.neo4j.com/courses/llm-fundamentals/3-intro-to-langchain/2.5-chains/[Chains lesson in Neo4j & LLM Fundamentals^], you learned about the `LLMChain`.
The link:https://api.python.langchain.com/en/latest/_modules/langchain/chains/llm.html#LLMChain[`LLMChain`^] is an example of a simple chain that, when invoked, takes a user input, replaces the value inside the prompt and passes the prompt to an LLM and specifies the result.

image::./images/chain.png[Prompt → LLM → Response]

// [source]
// ----
// // TODO: Diagram
Expand Down Expand Up @@ -60,6 +62,16 @@ The prompt will be passed to an LLM, in this case, the `ChatOpenAI` model.
include::{repository-raw}/main/examples/chain.mjs[tag=llm]
----

=== The Response Parser

You will then pass the LLM's response to an output parser.
The most straightforward parser is a `StringOutputParser`.

[source,typescript]
----
include::{repository-raw}/main/examples/chain.mjs[tag=parser]
----


=== Creating the Chain

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ The retrieval tool requires an embedding model.
include::{repository-raw}/main/{lab-solution}[tag="embeddings", indent=0]
----

[IMPORTANT]
.Defining a `baseURL`
The `baseURL` configuration option uses the `OPENAI_API_BASE` key to use the GraphAcademy OpenAI Proxy as mentioned in link:../../1-project-setup/2-setup/[the Project Setup lesson^].
If you are using an OpenAI API key (starting with `sk-`), you can omit the `configuration` options.


To interact with the graph, the agent should use link:/courses/llm-chatbot-typescript/3-conversation-history/2-neo4j-graph/[the singleton instance created in the Initializing Neo4j lesson^].

.Embeddings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The agent currently uses a pre-written prompt from LangChain Hub.
You can link:https://smith.langchain.com/hub/hwchase17/openai-functions-agent[view this prompt in LangChain Hub^].

The prompt is relatively basic.
It consists of an array of messages consisting of a role definition, human input, and placeholders.
It consists of an array of messages, including a role definition, human input, and placeholders.

[source]
.The prompt
Expand Down Expand Up @@ -47,7 +47,7 @@ For example, the following prompt instructs the LLM to refuse to answer question
.Modified Prompt
[source]
----
include::{repository-raw}/main/src/{lab-solution}[tag="scoped", indent=0]
include::{repository-raw}/main/{lab-solution}[tag="scoped", indent=0]
----

[NOTE]
Expand All @@ -65,7 +65,7 @@ The link:{repository-blob}/main/{test-file}[unit test^] will verify whether the
== Experiment

You can extend the prompt to instruct the agent to act in specific ways.
Experiment with different prompts to see how the agent responds to various types of questions.
Experiment with different prompts to see how the agent responds to various questions.

When you are ready, click Continue.

Expand Down
3 changes: 2 additions & 1 deletion asciidoc/courses/llm-fundamentals/course.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
:usecase: recommendations
// :video: https://www.youtube.com/embed/vVCHJFa01gA
:key-points: Neo4j and Generative AI, Grounding LLMs with Neo4j, Using Neo4j with Langchain
:allow-llm-calls: true

== Course Description

Expand Down Expand Up @@ -38,7 +39,7 @@ To complete the practical tasks within this course, you will need an link:https:
=== What you will learn

* Retrieval Augmented Generation (RAG) and its role in grounding LLM generated content
* Using Vector and full text indexes in Neo4j to perform similarity and keyword search
* Using Vector and full-text indexes in Neo4j to perform similarity and keyword search
* Coordinating your LLM interactions with Langchain chains, agents and tools

[.includes]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pip install openai langchain-openai

== Create a Langchain application

Create a new Python program and copy this code into a new Python file.
Create a new Python program and copy this code into it.

[source,python]
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain

llm = OpenAI(openai_api_key="sk-...")
llm = OpenAI(
openai_api_key="sk-..."
)

template = PromptTemplate.from_template("""
You are a cockney fruit and vegetable seller.
Expand All @@ -13,8 +15,8 @@
""")

llm_chain = LLMChain(
llm=llm,
prompt=template
llm=llm,
prompt=template
)

response = llm_chain.invoke({"fruit": "apple"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from langchain.schema import StrOutputParser

llm = OpenAI(
openai_api_key="sk-...")
openai_api_key="sk-..."
)

template = PromptTemplate.from_template("""
You are a cockney fruit and vegetable seller.
Expand All @@ -15,9 +16,9 @@
""")

llm_chain = LLMChain(
llm=llm,
prompt=template,
output_parser=StrOutputParser()
llm=llm,
prompt=template,
output_parser=StrOutputParser()
)

response = llm_chain.invoke({"fruit": "apple"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from langchain.output_parsers.json import SimpleJsonOutputParser

llm = OpenAI(
openai_api_key="sk-...")
openai_api_key="sk-..."
)

template = PromptTemplate.from_template("""
You are a cockney fruit and vegetable seller.
Expand All @@ -17,9 +18,9 @@
""")

llm_chain = LLMChain(
llm=llm,
prompt=template,
output_parser=SimpleJsonOutputParser()
llm=llm,
prompt=template,
output_parser=SimpleJsonOutputParser()
)

response = llm_chain.invoke({"fruit": "apple"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ Chains allows you to combine language models with different data sources and thi

== Using LLMChain

The simplest chain is an `LLMChain`. An `LLMChain` combines a prompt template with an LLM and returns a response.
The most straightforward chain is an `LLMChain`. An `LLMChain` combines a prompt template with an LLM and returns a response.

Previously, you created a program that used a prompt template and an LLM to generate a response about fruit.


[%collapsible]
.Click to reveal the code for the program.
====
[source,python]
[source,python,subs="attributes+"]
----
include::../2-initialising-the-llm/code/llm_prompt.py[]
----
====

You can combine this program into a chain and create a reusable component.

[source,python]
[source,python,subs="attributes+"]
----
include::code/llm_chain.py[]
----
Expand Down
Loading