Skip to content

Commit

Permalink
✨ Add RAG example script
Browse files Browse the repository at this point in the history
  • Loading branch information
shroominic committed Feb 15, 2024
1 parent dae1a38 commit 37b6b14
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions examples/rag_with_deps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from operator import itemgetter
from typing import Annotated

from funcchain.syntax import chain, runnable
from funcchain.syntax.params import Depends
from langchain_community.vectorstores.faiss import FAISS
from langchain_openai.embeddings import OpenAIEmbeddings

retriever = FAISS.from_texts(
[
"cold showers are good for your immune system",
"i dont like when people are mean to me",
"japanese tea is full of heart warming flavors",
],
embedding=OpenAIEmbeddings(),
).as_retriever(
search_kwargs={"k": 1},
)


@runnable
def poem_with_retrieval(
topic: str,
context: Annotated[str, Depends(itemgetter("topic") | retriever)] = "N/A",
) -> str:
"""
Generate a poem about the topic with the given context.
"""
return chain()


print(
poem_with_retrieval.invoke({"topic": "love"}),
)

0 comments on commit 37b6b14

Please sign in to comment.