-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a722f61
commit f8ad19a
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Dependencies | ||
|
||
TODO: Write a docs for dependencies | ||
|
||
## Example: RAG | ||
|
||
```python | ||
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"}), | ||
) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters