-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathdecorator.py
33 lines (25 loc) · 912 Bytes
/
decorator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from operator import itemgetter
from langchain_community.embeddings import OpenAIEmbeddings
from langchain_community.vectorstores.faiss import FAISS
from langchain_core.runnables import Runnable, RunnablePassthrough
from funcchain.syntax import chain, runnable
@runnable
def generate_poem(topic: str, context: str) -> str:
"""
Generate a poem about the topic with the given context.
"""
return chain()
vectorstore = 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(),
)
retriever = vectorstore.as_retriever(search_kwargs={"k": 1})
retrieval_chain: Runnable = {
"context": itemgetter("topic") | retriever,
"topic": RunnablePassthrough(),
} | generate_poem
print(retrieval_chain.invoke({"topic": "love"}))