Skip to content

Commit

Permalink
add example of OllamaGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
AlistairLR112 committed Jan 4, 2024
1 parent b80138e commit d528b91
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions integrations/ollama/example/example.py
Original file line number Diff line number Diff line change
@@ -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"}})

0 comments on commit d528b91

Please sign in to comment.