File size: 1,328 Bytes
76c5345
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
from langchain.agents import tool
from langchain_openai import OpenAIEmbeddings
from langchain_community.vectorstores.faiss import FAISS
from langchain.chains import RetrievalQA
from langchain_openai import OpenAI


@tool
def FAQ(input: str):
    """Provides answers to questions that students might have about Rise and Futureme. Please add ### to the beginning of your answer"""

    # Load from local storage
    embeddings = OpenAIEmbeddings()
    persisted_vectorstore = FAISS.load_local("_rise_faq_db", embeddings)

    # Use RetrievalQA chain for orchestration
    qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff", retriever=persisted_vectorstore.as_retriever())
    result = qa.invoke(input)
    return result 

@tool
def recommend_activity(question: str):
    """Recommends an activity from Rise catalogue."""

    # Load from local storage
    embeddings = OpenAIEmbeddings()
    persisted_vectorstore = FAISS.load_local("_rise_product_db", embeddings)

    # Use RetrievalQA chain for orchestration
    qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff", retriever=persisted_vectorstore.as_retriever())
    result = qa.invoke(input)
    return result 

@tool
def placeholder_tool():
    """This is just a placeholder function"""
    return "placeholder"

tools = [placeholder_tool, FAQ]