rajrakeshdr commited on
Commit
d17c60a
·
1 Parent(s): 1476c30
Files changed (5) hide show
  1. .gitignore +3 -0
  2. Dockerfile +1 -0
  3. app.py +42 -3
  4. requirements.txt +5 -1
  5. vercel.json +1 -0
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ .env
2
+ __pycache__/
3
+ *.pyc
Dockerfile CHANGED
@@ -7,6 +7,7 @@ ENV PATH="/home/user/.local/bin:$PATH"
7
  WORKDIR /app
8
 
9
  COPY --chown=user ./requirements.txt requirements.txt
 
10
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
 
12
  COPY --chown=user . /app
 
7
  WORKDIR /app
8
 
9
  COPY --chown=user ./requirements.txt requirements.txt
10
+ COPY --chown=user ./.env .env
11
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
12
 
13
  COPY --chown=user . /app
app.py CHANGED
@@ -1,7 +1,46 @@
1
- from fastapi import FastAPI
 
 
 
 
 
 
2
 
 
 
 
 
3
  app = FastAPI()
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  @app.get("/")
6
- def greet_json():
7
- return {"Hello": "World!"}
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from pydantic import BaseModel
3
+ from langchain_groq import ChatGroq
4
+ from langchain.chains import LLMChain
5
+ from langchain.prompts import PromptTemplate
6
+ from dotenv import load_dotenv
7
+ import os
8
 
9
+ # Load environment variables
10
+ load_dotenv()
11
+
12
+ # Initialize FastAPI app
13
  app = FastAPI()
14
 
15
+ # Create a request model
16
+ class SearchQuery(BaseModel):
17
+ query: str
18
+
19
+ # Initialize LangChain with Groq
20
+ llm = ChatGroq(
21
+ temperature=0.7,
22
+ model_name="mixtral-8x7b-32768", # You can also use "llama2-70b-4096"
23
+ )
24
+
25
+ prompt_template = PromptTemplate(
26
+ input_variables=["query"],
27
+ template="Please provide a detailed response to the following query: {query}"
28
+ )
29
+ chain = LLMChain(llm=llm, prompt=prompt_template)
30
+
31
+ @app.post("/search")
32
+ async def process_search(search_query: SearchQuery):
33
+ try:
34
+ # Process the query using LangChain
35
+ response = chain.run(query=search_query.query)
36
+
37
+ return {
38
+ "status": "success",
39
+ "response": response
40
+ }
41
+ except Exception as e:
42
+ raise HTTPException(status_code=500, detail=str(e))
43
+
44
  @app.get("/")
45
+ async def root():
46
+ return {"message": "Search API is running"}
requirements.txt CHANGED
@@ -1,2 +1,6 @@
1
  fastapi
2
- uvicorn[standard]
 
 
 
 
 
1
  fastapi
2
+ uvicorn
3
+ python-dotenv
4
+ langchain
5
+ openai
6
+ pydantic
vercel.json ADDED
@@ -0,0 +1 @@
 
 
1
+