Skip to content

Commit

Permalink
change example to reference the greatest politician of all time - Sup…
Browse files Browse the repository at this point in the history
…er Mario
  • Loading branch information
AlistairLR112 committed Jan 4, 2024
1 parent 046cb08 commit 58ffa56
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
28 changes: 22 additions & 6 deletions integrations/ollama/example/example.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
from haystack import Pipeline
from haystack import Document, Pipeline
from haystack.components.builders.prompt_builder import PromptBuilder
from haystack.components.retrievers import InMemoryBM25Retriever
from haystack.document_stores import InMemoryDocumentStore
from haystack.document_stores.in_memory import InMemoryDocumentStore

from ollama_haystack import OllamaGenerator

document_store = InMemoryDocumentStore()
document_store.write_documents(
[
Document(content="Super Mario was an important politician"),
Document(content="Mario owns several castles and uses them to conduct important political business"),
Document(
content="Super Mario was a successful military leader who fought off several invasion attempts by "
"his arch rival - Bowser"
),
]
)

query = "Who is Super Mario?"

template = """
Given the following information, answer the question.
Given only the following information, answer the question.
Ignore your own knowledge.
Context:
{% for document in documents %}
{{ document.content }}
{% endfor %}
Question: What's the official language of {{ country }}?
Question: {{ query }}?
"""
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"}})
response = pipe.run({"prompt_builder": {"query": query}, "retriever": {"query": query}})

print(response["llm"]["replies"])
2 changes: 2 additions & 0 deletions integrations/ollama/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ ban-relative-imports = "all"
[tool.ruff.per-file-ignores]
# Tests can use magic values, assertions, and relative imports
"tests/**/*" = ["PLR2004", "S101", "TID252"]
# Examples can print their output
"example/**" = ["T201"]


[tool.coverage.run]
Expand Down

0 comments on commit 58ffa56

Please sign in to comment.