Spaces:
Sleeping
Sleeping
John Landry
commited on
Commit
•
5b6ca23
1
Parent(s):
588efce
update to kb
Browse files
.gitignore
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
bin/
|
2 |
lib/
|
3 |
__pycache__/
|
|
|
4 |
.env
|
5 |
pyvenv.cfg
|
|
|
1 |
bin/
|
2 |
lib/
|
3 |
__pycache__/
|
4 |
+
include/
|
5 |
.env
|
6 |
pyvenv.cfg
|
kb.py
CHANGED
@@ -9,5 +9,8 @@ NAMESPACE = "knowedgebase"
|
|
9 |
EMBEDDING_DIMENSION = 1536
|
10 |
EMBEDDING_MODEL_NAME = "amazon.titan-embed-text-v1"
|
11 |
|
12 |
-
|
13 |
-
vectorstore = PineconeVectorStore(index_name=INDEX_NAME,
|
|
|
|
|
|
|
|
9 |
EMBEDDING_DIMENSION = 1536
|
10 |
EMBEDDING_MODEL_NAME = "amazon.titan-embed-text-v1"
|
11 |
|
12 |
+
def getkb():
|
13 |
+
vectorstore = PineconeVectorStore(index_name=INDEX_NAME,
|
14 |
+
embedding=BedrockEmbeddings(model_id=EMBEDDING_MODEL_NAME),
|
15 |
+
namespace=NAMESPACE)
|
16 |
+
return vectorstore
|
main.py
CHANGED
@@ -2,12 +2,13 @@ from fastapi import FastAPI, Request, Query
|
|
2 |
import logging
|
3 |
from whatsapp_client import WhatsAppWrapper
|
4 |
import json
|
5 |
-
from kb import
|
6 |
|
7 |
logger = logging.getLogger()
|
8 |
|
9 |
app = FastAPI()
|
10 |
|
|
|
11 |
|
12 |
@app.get('/')
|
13 |
def ok():
|
@@ -36,13 +37,13 @@ async def callback(request: Request):
|
|
36 |
data = json.loads(body)
|
37 |
value = data['entry'][0]['changes'][0]['value']
|
38 |
|
39 |
-
if 'messages' in value and 'from
|
40 |
message = value['messages'][0]
|
41 |
phone_num = message['from']
|
42 |
-
mesg_body =
|
43 |
print("SEARCH: " + str(mesg_body))
|
44 |
-
documents = vectorstore.
|
45 |
-
print(f"
|
46 |
client = WhatsAppWrapper()
|
47 |
client.send_text_message("hello, right back at ya ..." + mesg_body, phone_num)
|
48 |
|
|
|
2 |
import logging
|
3 |
from whatsapp_client import WhatsAppWrapper
|
4 |
import json
|
5 |
+
from kb import getkb
|
6 |
|
7 |
logger = logging.getLogger()
|
8 |
|
9 |
app = FastAPI()
|
10 |
|
11 |
+
vectorstore = getkb()
|
12 |
|
13 |
@app.get('/')
|
14 |
def ok():
|
|
|
37 |
data = json.loads(body)
|
38 |
value = data['entry'][0]['changes'][0]['value']
|
39 |
|
40 |
+
if 'messages' in value and 'from' in value['messages'][0] and 'text' in value['messages'][0]:
|
41 |
message = value['messages'][0]
|
42 |
phone_num = message['from']
|
43 |
+
mesg_body = message['text']['body']
|
44 |
print("SEARCH: " + str(mesg_body))
|
45 |
+
documents = '\n'.join([doc[0].page_content for doc in vectorstore.similarity_search_with_score(mesg_body, k=6)])
|
46 |
+
print(f"CONTENT: {documents}")
|
47 |
client = WhatsAppWrapper()
|
48 |
client.send_text_message("hello, right back at ya ..." + mesg_body, phone_num)
|
49 |
|
test.py
CHANGED
@@ -1,4 +1,8 @@
|
|
1 |
import json
|
|
|
|
|
|
|
|
|
2 |
|
3 |
data = """{
|
4 |
"object": "whatsapp_business_account",
|
@@ -42,8 +46,21 @@ data = """{
|
|
42 |
|
43 |
data = json.loads(data)
|
44 |
value = data['entry'][0]['changes'][0]['value']
|
45 |
-
phone_num = value['messages'][0]['from']
|
46 |
-
mesg_body = value['messages'][0]['text']['body']
|
47 |
-
phone_number_id = value['metadata']['phone_number_id']
|
48 |
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import json
|
2 |
+
from kb import getkb
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
|
5 |
+
load_dotenv()
|
6 |
|
7 |
data = """{
|
8 |
"object": "whatsapp_business_account",
|
|
|
46 |
|
47 |
data = json.loads(data)
|
48 |
value = data['entry'][0]['changes'][0]['value']
|
|
|
|
|
|
|
49 |
|
50 |
+
def main():
|
51 |
+
vectorstore = getkb()
|
52 |
+
print('here i am!')
|
53 |
+
if 'messages' in value and 'from' in value['messages'][0] and 'text' in value['messages'][0]:
|
54 |
+
print('i got here!')
|
55 |
+
message = value['messages'][0]
|
56 |
+
phone_num = message['from']
|
57 |
+
mesg_body = message['text']['body']
|
58 |
+
print(f"SEARCH: {mesg_body}, PHONE: {phone_num}")
|
59 |
+
|
60 |
+
documents = '\n'.join([doc[0].page_content for doc in vectorstore.similarity_search_with_score(mesg_body, k=6)])
|
61 |
+
print(f"CONTENT: {documents}")
|
62 |
+
#client = WhatsAppWrapper()
|
63 |
+
#client.send_text_message("hello, right back at ya ..." + mesg_body, phone_num)
|
64 |
+
|
65 |
+
if __name__ == "__main__":
|
66 |
+
main()
|