Merge branch 'main' of https://github.com/Aws-killer/Trasnscription
Browse files
App/Embedding/utils/Initialize.py
CHANGED
@@ -4,7 +4,11 @@ from langchain.vectorstores import MongoDBAtlasVectorSearch
|
|
4 |
from langchain.vectorstores import FAISS
|
5 |
from pymongo import MongoClient
|
6 |
from motor.motor_asyncio import AsyncIOMotorClient
|
|
|
7 |
|
|
|
|
|
|
|
8 |
template = """### Given the following context
|
9 |
### Context
|
10 |
{context}
|
@@ -14,7 +18,7 @@ template = """### Given the following context
|
|
14 |
|
15 |
|
16 |
async def fetch_data(question, context):
|
17 |
-
url =
|
18 |
|
19 |
payload = json.dumps(
|
20 |
{
|
@@ -39,7 +43,7 @@ async def fetch_data(question, context):
|
|
39 |
|
40 |
headers = {
|
41 |
"Content-Type": "application/json",
|
42 |
-
"Authorization": "Bearer
|
43 |
}
|
44 |
|
45 |
async with aiohttp.ClientSession() as session:
|
@@ -50,7 +54,7 @@ async def fetch_data(question, context):
|
|
50 |
|
51 |
async def delete_documents(task_id):
|
52 |
client = AsyncIOMotorClient(
|
53 |
-
|
54 |
)
|
55 |
db = client["transcriptions"]
|
56 |
collection = db["videos"]
|
@@ -60,7 +64,7 @@ async def delete_documents(task_id):
|
|
60 |
|
61 |
|
62 |
# mongo_client = MongoClient(
|
63 |
-
#
|
64 |
# )
|
65 |
# model_name = "BAAI/bge-base-en"
|
66 |
# collection = mongo_client["transcriptions"]["videos"]
|
@@ -91,7 +95,7 @@ def generateChunks(chunks, task_id, n=100):
|
|
91 |
|
92 |
def search(query: str, task_id: str):
|
93 |
mongo_client = MongoClient(
|
94 |
-
|
95 |
)
|
96 |
model_name = "BAAI/bge-base-en"
|
97 |
collection = mongo_client["transcriptions"]["videos"]
|
@@ -124,7 +128,7 @@ def search(query: str, task_id: str):
|
|
124 |
|
125 |
def encode(temp: list[Document]):
|
126 |
mongo_client = MongoClient(
|
127 |
-
|
128 |
)
|
129 |
model_name = "BAAI/bge-base-en"
|
130 |
collection = mongo_client["transcriptions"]["videos"]
|
|
|
4 |
from langchain.vectorstores import FAISS
|
5 |
from pymongo import MongoClient
|
6 |
from motor.motor_asyncio import AsyncIOMotorClient
|
7 |
+
import os
|
8 |
|
9 |
+
|
10 |
+
completion_base=os.environ.get("completion_base")
|
11 |
+
openai_api_key=os.environ.get("openai_api_key")
|
12 |
template = """### Given the following context
|
13 |
### Context
|
14 |
{context}
|
|
|
18 |
|
19 |
|
20 |
async def fetch_data(question, context):
|
21 |
+
url = completion_base
|
22 |
|
23 |
payload = json.dumps(
|
24 |
{
|
|
|
43 |
|
44 |
headers = {
|
45 |
"Content-Type": "application/json",
|
46 |
+
"Authorization": f"Bearer {openai_api_key}",
|
47 |
}
|
48 |
|
49 |
async with aiohttp.ClientSession() as session:
|
|
|
54 |
|
55 |
async def delete_documents(task_id):
|
56 |
client = AsyncIOMotorClient(
|
57 |
+
mongoDB
|
58 |
)
|
59 |
db = client["transcriptions"]
|
60 |
collection = db["videos"]
|
|
|
64 |
|
65 |
|
66 |
# mongo_client = MongoClient(
|
67 |
+
# mongoDB
|
68 |
# )
|
69 |
# model_name = "BAAI/bge-base-en"
|
70 |
# collection = mongo_client["transcriptions"]["videos"]
|
|
|
95 |
|
96 |
def search(query: str, task_id: str):
|
97 |
mongo_client = MongoClient(
|
98 |
+
mongoDB
|
99 |
)
|
100 |
model_name = "BAAI/bge-base-en"
|
101 |
collection = mongo_client["transcriptions"]["videos"]
|
|
|
128 |
|
129 |
def encode(temp: list[Document]):
|
130 |
mongo_client = MongoClient(
|
131 |
+
mongoDB
|
132 |
)
|
133 |
model_name = "BAAI/bge-base-en"
|
134 |
collection = mongo_client["transcriptions"]["videos"]
|