Update main.py
Browse files
main.py
CHANGED
@@ -12,6 +12,7 @@ from operator import itemgetter
|
|
12 |
from pinecone import Pinecone
|
13 |
from langchain_pinecone import PineconeVectorStore
|
14 |
from langchain_community.chat_message_histories import ChatMessageHistory
|
|
|
15 |
from langchain.memory import ConversationBufferMemory
|
16 |
from langchain.schema.runnable import Runnable, RunnablePassthrough, RunnableConfig, RunnableLambda
|
17 |
from langchain.callbacks.base import BaseCallbackHandler
|
@@ -19,6 +20,7 @@ from langchain.chains import (
|
|
19 |
StuffDocumentsChain, ConversationalRetrievalChain
|
20 |
)
|
21 |
from langchain_core.tracers.context import tracing_v2_enabled
|
|
|
22 |
|
23 |
import chainlit as cl
|
24 |
from chainlit.input_widget import TextInput, Select, Switch, Slider
|
@@ -213,6 +215,21 @@ async def on_message(message: cl.Message):
|
|
213 |
cl.Text(name="Sources", content=search[0], display="inline")
|
214 |
]
|
215 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
await cl.Message(
|
217 |
content="Sources : ",
|
218 |
elements=sources,
|
|
|
12 |
from pinecone import Pinecone
|
13 |
from langchain_pinecone import PineconeVectorStore
|
14 |
from langchain_community.chat_message_histories import ChatMessageHistory
|
15 |
+
from langchain_community.utilities import GoogleSearchAPIWrapper
|
16 |
from langchain.memory import ConversationBufferMemory
|
17 |
from langchain.schema.runnable import Runnable, RunnablePassthrough, RunnableConfig, RunnableLambda
|
18 |
from langchain.callbacks.base import BaseCallbackHandler
|
|
|
20 |
StuffDocumentsChain, ConversationalRetrievalChain
|
21 |
)
|
22 |
from langchain_core.tracers.context import tracing_v2_enabled
|
23 |
+
from langchain_core.tools import Tool
|
24 |
|
25 |
import chainlit as cl
|
26 |
from chainlit.input_widget import TextInput, Select, Switch, Slider
|
|
|
215 |
cl.Text(name="Sources", content=search[0], display="inline")
|
216 |
]
|
217 |
|
218 |
+
os.environ["GOOGLE_CSE_ID"] = os.getenv('GOOGLE_CSE_ID')
|
219 |
+
os.environ["GOOGLE_API_KEY"] = os.getenv('GOOGLE_API_KEY')
|
220 |
+
search = GoogleSearchAPIWrapper()
|
221 |
+
|
222 |
+
def top5_results(query):
|
223 |
+
return search.results(query, 5)
|
224 |
+
|
225 |
+
tool = Tool(
|
226 |
+
name="Google Search Snippets",
|
227 |
+
description="Search Google for recent results.",
|
228 |
+
func=top5_results,
|
229 |
+
)
|
230 |
+
print(tool.run(str(message.content)))
|
231 |
+
|
232 |
+
|
233 |
await cl.Message(
|
234 |
content="Sources : ",
|
235 |
elements=sources,
|