From d528b9115461ace01a1b5d7c4cf3b89e757385fc Mon Sep 17 00:00:00 2001 From: Alistair Rogers Date: Thu, 4 Jan 2024 10:50:54 +0000 Subject: [PATCH] add example of OllamaGenerator --- integrations/ollama/example/example.py | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 integrations/ollama/example/example.py diff --git a/integrations/ollama/example/example.py b/integrations/ollama/example/example.py new file mode 100644 index 000000000..672dd86ad --- /dev/null +++ b/integrations/ollama/example/example.py @@ -0,0 +1,27 @@ +from haystack import Pipeline +from haystack.components.retrievers import InMemoryBM25Retriever +from haystack.document_stores import InMemoryDocumentStore +from haystack.components.builders.prompt_builder import PromptBuilder + +from ollama_haystack import OllamaGenerator + +template = """ +Given the following information, answer the question. + +Context: +{% for document in documents %} + {{ document.content }} +{% endfor %} + +Question: What's the official language of {{ country }}? +""" +pipe = Pipeline() +document_store = InMemoryDocumentStore() + +pipe.add_component("retriever", InMemoryBM25Retriever(document_store=document_store)) +pipe.add_component("prompt_builder", PromptBuilder(template=template)) +pipe.add_component("llm", OllamaGenerator(model='orca-mini')) +pipe.connect("retriever", "prompt_builder.documents") +pipe.connect("prompt_builder", "llm") + +pipe.run({"prompt_builder": {"country": "Ghana"}})