Skip to content

Commit

Permalink
Example/cleaning (#196)
Browse files Browse the repository at this point in the history
* Remove 'old' folder - add example for Ollama LLM

* Update examples' README

* Explicitly set 'return_context' to prevent warnings in examples
  • Loading branch information
stellasia authored Oct 23, 2024
1 parent ad6424a commit 4580d5f
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 96 deletions.
3 changes: 2 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ are listed in [the last section of this file](#customize).
- [MistralAI](./customize/llms/mistalai_llm.py)
- [Cohere](./customize/llms/cohere_llm.py)
- [Anthropic (Claude)](./customize/llms/anthropic_llm.py)
- [Ollama]()
- [Ollama](./customize/llms/ollama_llm.py)
- [Custom LLM](./customize/llms/custom_llm.py)


Expand All @@ -91,6 +91,7 @@ are listed in [the last section of this file](#customize).

- [End to end example with explicit components and text input](./customize/build_graph/pipeline/kg_builder_from_text.py)
- [End to end example with explicit components and PDF input](./customize/build_graph/pipeline/kg_builder_from_pdf.py)
- [Process multiple documents](./customize/build_graph/pipeline/kg_builder_two_documents_entity_resolution.py)

#### Components

Expand Down
5 changes: 4 additions & 1 deletion examples/customize/answer/custom_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@

rag = GraphRAG(retriever=retriever, llm=llm, prompt_template=template)

result = rag.search("Tell me more about Avatar movies")
result = rag.search(
"Tell me more about Avatar movies",
return_context=True,
)
print(result.answer)

driver.close()
5 changes: 4 additions & 1 deletion examples/customize/answer/langchain_compatiblity.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
llm=llm, # type: ignore[arg-type, unused-ignore]
)

result = rag.search("Tell me more about Avatar movies")
result = rag.search(
"Tell me more about Avatar movies",
return_context=False,
)
print(result.answer)

driver.close()
12 changes: 12 additions & 0 deletions examples/customize/llms/ollama_llm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from neo4j_graphrag.llm import LLMResponse, OpenAILLM

# not used but needs to be provided
api_key = "ollama"

llm = OpenAILLM(
base_url="http://localhost:11434/v1",
model_name="<model_name>",
api_key=api_key,
)
res: LLMResponse = llm.invoke("What is the additive color model?")
print(res.content)
Empty file removed examples/old/pipeline/__init__.py
Empty file.
92 changes: 0 additions & 92 deletions examples/old/pipeline/kg_builder_example.py

This file was deleted.

6 changes: 5 additions & 1 deletion examples/question_answering/graphrag.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ def formatter(record: neo4j.Record) -> RetrieverResultItem:

rag = GraphRAG(retriever=retriever, llm=llm)

result = rag.search("Tell me more about Avatar movies")
result = rag.search(
"Tell me more about Avatar movies",
return_context=True,
)
print(result.answer)
# print(result.retriever_result)

driver.close()

0 comments on commit 4580d5f

Please sign in to comment.