Skip to content

Commit

Permalink
[examples] Finalise the Ollama example application (#713)
Browse files Browse the repository at this point in the history
  • Loading branch information
eolivelli authored Nov 10, 2023
1 parent b03f6d5 commit 09b8ef3
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 19 deletions.
1 change: 1 addition & 0 deletions examples/applications/docker-chatbot/chatbot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ errors:
on-failure: "skip"
pipeline:
- name: "convert-to-structure"
id: "chatbot"
type: "document-to-json"
input: "questions-topic"
configuration:
Expand Down
1 change: 0 additions & 1 deletion examples/applications/docker-chatbot/crawler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ pipeline:
- name: "Detect language"
type: "language-detector"
configuration:
allowedLanguages: ["en", "fr"]
property: "language"
- name: "Split into chunks"
type: "text-splitter"
Expand Down
30 changes: 26 additions & 4 deletions examples/applications/ollama-chatbot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,36 @@ In this example we are using [HerdDB](ps://github.com/diennea/herddb) as a vecto
but you can use any Vector databases.

As LLM we are using [Ollama](https://ollama.ai), that is a service that runs on your machine.

We are using OpenAI to compute the embeddings of the texts.

## Install Ollama


Follow the instructions on the Ollama.ai website to install Ollama.

Then start Ollama with the llama2 model
Then start Ollama with the llama2:13b model

```
ollama run llama2
ollama run llama2:13b
```

If you want to use another model export this variable before starting the application.

```bash
export OLLAMA_MODEL=llama2:13b
```

## Configure you OpenAI API Key

At the moment it the embeddings computed by Ollama models are not performing well, so we are using OpenAI to compute them.

Export to the ENV the access key to OpenAI

```
export OPEN_AI_ACCESS_KEY=...
```

The default [secrets file](../../secrets/secrets.yaml) reads from the ENV. Check out the file to learn more about
the default settings, you can change them by exporting other ENV variables.

## Deploy the LangStream application in docker

Expand All @@ -37,3 +54,8 @@ Since the application opens a gateway, we can use the gateway API to send and co
```
./bin/langstream gateway chat test -cg bot-output -pg user-input -p sessionId=$(uuidgen)
```


## Testing Ollama embeddings
If you want to use Ollama for the embeddings you can change the "ai-service" to "ollama" in the pipeline files and set the
model for the embeddings.
27 changes: 16 additions & 11 deletions examples/applications/ollama-chatbot/chatbot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ pipeline:
- name: "compute-embeddings"
type: "compute-ai-embeddings"
configuration:
model: "${secrets.ollama.model}"
ai-service: "openai"
model: "${secrets.open-ai.embeddings-model}"
embeddings-field: "value.question_embeddings"
text: "{{ value.question }}"
flush-interval: 0
Expand All @@ -47,7 +48,7 @@ pipeline:
- name: "re-rank documents with MMR"
type: "re-rank"
configuration:
max: 5 # keep only the top 5 documents, because we have an hard limit on the prompt size
max: 10 # keep only the top 5 documents, because we have and hard limit on the prompt size
field: "value.related_documents"
query-text: "value.question"
query-embeddings: "value.question_embeddings"
Expand All @@ -58,10 +59,13 @@ pipeline:
lambda: 0.5
k1: 1.2
b: 0.75
- name: "log documents"
type: "log-event"
- name: "ai-chat-completions"
type: "ai-chat-completions"

configuration:
ai-service: "ollama"
model: "${secrets.ollama.model}"
# on the log-topic we add a field with the answer
completion-field: "value.answer"
Expand All @@ -79,20 +83,21 @@ pipeline:
# eventually we want to send bigger messages to reduce the overhead of each message on the topic
min-chunks-per-message: 20
messages:
- role: system
content: |
An user is going to perform a questions, The documents below may help you in answering to their questions.
Please try to leverage them in your answer as much as possible.
Take into consideration that the user is always asking questions about the LangStream project.
If you provide code or YAML snippets, please explicitly state that they are examples.
Do not provide information that is not related to the LangStream project.
- content: |
I have this list of documents that may help you in answering to my question below.
Documents:
{{# value.related_documents}}
{{ text}}
{{/ value.related_documents}}
- role: user
content: "{{ value.question}}"
Please try to leverage the content above in your answer as much as possible.
Take into consideration that I am always asking questions about the LangStream project.
Do not provide information that is not related to the LangStream project.
This is my question:
{{ value.question}}
- name: "cleanup-response"
type: "drop-fields"
output: "log-topic"
Expand Down
8 changes: 8 additions & 0 deletions examples/applications/ollama-chatbot/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,16 @@ configuration:
password: "${secrets.herddb.password}"
- type: "ollama-configuration"
name: "ollama"
id: "ollama"
configuration:
url: "${secrets.ollama.url}"
- type: "open-ai-configuration"
name: "OpenAI Azure configuration"
id: "openai"
configuration:
url: "${secrets.open-ai.url}"
access-key: "${secrets.open-ai.access-key}"
provider: "${secrets.open-ai.provider}"
dependencies:
- name: "HerdDB.org JDBC Driver"
url: "https://repo1.maven.org/maven2/org/herddb/herddb-jdbc/0.28.0/herddb-jdbc-0.28.0-thin.jar"
Expand Down
4 changes: 2 additions & 2 deletions examples/applications/ollama-chatbot/crawler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pipeline:
- name: "Detect language"
type: "language-detector"
configuration:
allowedLanguages: ["en", "fr"]
property: "language"
- name: "Split into chunks"
type: "text-splitter"
Expand Down Expand Up @@ -77,7 +76,8 @@ pipeline:
id: "step1"
type: "compute-ai-embeddings"
configuration:
model: "${secrets.ollama.model}"
ai-service: "openai"
model: "${secrets.open-ai.embeddings-model}"
embeddings-field: "value.embeddings_vector"
text: "{{ value.text }}"
batch-size: 10
Expand Down
2 changes: 1 addition & 1 deletion examples/secrets/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ secrets:
id: ollama
data:
url: "${OLLAMA_URL:-http://host.docker.internal:11434}"
model: "${OLLAMA_MODEL:-mistral}"
model: "${OLLAMA_MODEL:-llama2:13b}"
- name: camel-github-source
id: camel-github-source
data:
Expand Down

0 comments on commit 09b8ef3

Please sign in to comment.