Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,9 @@ from fastapi.encoders import jsonable_encoder
|
|
11 |
from fastapi.templating import Jinja2Templates
|
12 |
from fastapi import FastAPI, Request, Form, Response
|
13 |
from langchain_community.embeddings import SentenceTransformerEmbeddings
|
|
|
14 |
|
|
|
15 |
os.environ["TRANSFORMERS_FORCE_CPU"] = "true"
|
16 |
|
17 |
app = FastAPI()
|
@@ -28,11 +30,11 @@ config = {
|
|
28 |
'threads': int(os.cpu_count() / 2)
|
29 |
}
|
30 |
|
31 |
-
|
32 |
|
33 |
llm = ChatGroq(
|
34 |
model="llama-3.1-8b-instant",
|
35 |
-
api_key=
|
36 |
)
|
37 |
|
38 |
print("LLM Initialized....")
|
@@ -47,13 +49,13 @@ Helpful answer:
|
|
47 |
|
48 |
embeddings = SentenceTransformerEmbeddings(model_name="BAAI/bge-large-en")
|
49 |
|
50 |
-
url = os.environ.get("
|
51 |
-
|
52 |
client = QdrantClient(
|
53 |
-
url=url, prefer_grpc=False
|
|
|
54 |
)
|
55 |
|
56 |
-
qdrant_api_key = os.environ.get("QDRANT_API_KEY")
|
57 |
db = Qdrant(client=client, embeddings=embeddings, collection_name="patent_database")
|
58 |
|
59 |
prompt = PromptTemplate(template=prompt_template, input_variables=['context', 'question'])
|
|
|
11 |
from fastapi.templating import Jinja2Templates
|
12 |
from fastapi import FastAPI, Request, Form, Response
|
13 |
from langchain_community.embeddings import SentenceTransformerEmbeddings
|
14 |
+
from dotenv import load_dotenv
|
15 |
|
16 |
+
load_dotenv()
|
17 |
os.environ["TRANSFORMERS_FORCE_CPU"] = "true"
|
18 |
|
19 |
app = FastAPI()
|
|
|
30 |
'threads': int(os.cpu_count() / 2)
|
31 |
}
|
32 |
|
33 |
+
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
|
34 |
|
35 |
llm = ChatGroq(
|
36 |
model="llama-3.1-8b-instant",
|
37 |
+
api_key=GROQ_API_KEY,
|
38 |
)
|
39 |
|
40 |
print("LLM Initialized....")
|
|
|
49 |
|
50 |
embeddings = SentenceTransformerEmbeddings(model_name="BAAI/bge-large-en")
|
51 |
|
52 |
+
url = os.environ.get("QDRANT_URL")
|
53 |
+
qdrant_api_key = os.environ.get("QDRANT_API_KEY")
|
54 |
client = QdrantClient(
|
55 |
+
url=url, prefer_grpc=False,
|
56 |
+
api_key=qdrant_api_key
|
57 |
)
|
58 |
|
|
|
59 |
db = Qdrant(client=client, embeddings=embeddings, collection_name="patent_database")
|
60 |
|
61 |
prompt = PromptTemplate(template=prompt_template, input_variables=['context', 'question'])
|