Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,9 +8,10 @@ import os
|
|
8 |
# Initialize FastAPI app
|
9 |
app = FastAPI()
|
10 |
|
11 |
-
# Create a request model
|
12 |
class SearchQuery(BaseModel):
|
13 |
query: str
|
|
|
14 |
|
15 |
# Initialize LangChain with Groq
|
16 |
llm = ChatGroq(
|
@@ -19,17 +20,25 @@ llm = ChatGroq(
|
|
19 |
groq_api_key="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" # Replace with your actual Groq API key
|
20 |
)
|
21 |
|
|
|
22 |
prompt_template = PromptTemplate(
|
23 |
-
input_variables=["query"],
|
24 |
-
template="
|
|
|
|
|
|
|
|
|
25 |
)
|
26 |
chain = LLMChain(llm=llm, prompt=prompt_template)
|
27 |
|
28 |
@app.post("/search")
|
29 |
async def process_search(search_query: SearchQuery):
|
30 |
try:
|
31 |
-
#
|
32 |
-
|
|
|
|
|
|
|
33 |
|
34 |
return {
|
35 |
"status": "success",
|
@@ -40,4 +49,4 @@ async def process_search(search_query: SearchQuery):
|
|
40 |
|
41 |
@app.get("/")
|
42 |
async def root():
|
43 |
-
return {"message": "Search API is running"}
|
|
|
8 |
# Initialize FastAPI app
|
9 |
app = FastAPI()
|
10 |
|
11 |
+
# Create a request model with context
|
12 |
class SearchQuery(BaseModel):
|
13 |
query: str
|
14 |
+
context: str = None # Optional context field
|
15 |
|
16 |
# Initialize LangChain with Groq
|
17 |
llm = ChatGroq(
|
|
|
20 |
groq_api_key="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" # Replace with your actual Groq API key
|
21 |
)
|
22 |
|
23 |
+
# Define the prompt template with cybersecurity expertise
|
24 |
prompt_template = PromptTemplate(
|
25 |
+
input_variables=["query", "context"],
|
26 |
+
template="""
|
27 |
+
Context: You are a cybersecurity expert with extensive experience in all sub-streams of the industry, including but not limited to network security, application security, cloud security, threat intelligence, penetration testing, and incident response. {context}
|
28 |
+
Query: {query}
|
29 |
+
Please provide a detailed and professional response to the query based on your expertise in cybersecurity and the provided context.
|
30 |
+
"""
|
31 |
)
|
32 |
chain = LLMChain(llm=llm, prompt=prompt_template)
|
33 |
|
34 |
@app.post("/search")
|
35 |
async def process_search(search_query: SearchQuery):
|
36 |
try:
|
37 |
+
# Set default context if not provided
|
38 |
+
context = search_query.context or "You are a cybersecurity expert."
|
39 |
+
|
40 |
+
# Process the query using LangChain with context
|
41 |
+
response = chain.run(query=search_query.query, context=context)
|
42 |
|
43 |
return {
|
44 |
"status": "success",
|
|
|
49 |
|
50 |
@app.get("/")
|
51 |
async def root():
|
52 |
+
return {"message": "Search API is running"}
|