Spaces:
Sleeping
Sleeping
Update utils/llm.py
Browse files- utils/llm.py +34 -34
utils/llm.py
CHANGED
|
@@ -1,34 +1,34 @@
|
|
| 1 |
-
import os
|
| 2 |
-
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 3 |
-
from langchain_core.prompts import ChatPromptTemplate
|
| 4 |
-
from config import GOOGLE_API_KEY
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
# Load Gemini LLM
|
| 8 |
-
llm = ChatGoogleGenerativeAI(model="gemini-1.5-pro", google_api_key=GOOGLE_API_KEY)
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
-
|
| 22 |
-
-
|
| 23 |
-
- Do NOT
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
prompt_template = ChatPromptTemplate.from_template(PROMPT_TEMPLATE)
|
| 29 |
-
|
| 30 |
-
def generate_answer(query: str, context: str):
|
| 31 |
-
"""Generate AI response based on retrieved context."""
|
| 32 |
-
prompt = prompt_template.format(context=context, question=query)
|
| 33 |
-
response = llm.invoke(prompt)
|
| 34 |
-
return response.content
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 3 |
+
from langchain_core.prompts import ChatPromptTemplate
|
| 4 |
+
from config import GOOGLE_API_KEY
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
# Load Gemini LLM
|
| 8 |
+
llm = ChatGoogleGenerativeAI(model="gemini-1.5-pro", google_api_key=GOOGLE_API_KEY)
|
| 9 |
+
|
| 10 |
+
PROMPT_TEMPLATE = """
|
| 11 |
+
You are an AI assistant that answers user queries based on the given context.
|
| 12 |
+
|
| 13 |
+
CONTEXT INFORMATION:
|
| 14 |
+
{context}
|
| 15 |
+
|
| 16 |
+
QUESTION:
|
| 17 |
+
{question}
|
| 18 |
+
|
| 19 |
+
INSTRUCTIONS:
|
| 20 |
+
- Provide a detailed answer based on the context.
|
| 21 |
+
- If multiple relevant points exist, include them.
|
| 22 |
+
- Keep the response informative but concise.
|
| 23 |
+
- Do NOT add external information beyond the given context.
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
prompt_template = ChatPromptTemplate.from_template(PROMPT_TEMPLATE)
|
| 29 |
+
|
| 30 |
+
def generate_answer(query: str, context: str):
|
| 31 |
+
"""Generate AI response based on retrieved context."""
|
| 32 |
+
prompt = prompt_template.format(context=context, question=query)
|
| 33 |
+
response = llm.invoke(prompt)
|
| 34 |
+
return response.content
|