This is my code and i want to add the SYSTEM_PROMPT to my RAG code.
from langchain_chroma import Chroma
from langchain_openai import OpenAIEmbeddings, ChatOpenAI
from langchain.chains import RetrievalQA
from langchain_core.messages import SystemMessage, HumanMessage
openai_api_key = "sk-"
K_RESULTS = 3
SIMILARITY_THRESHOLD = 0.5
SYSTEM_PROMPT = "I have an AI informational website. You should check the user's prompt and recommend the best tool as per it. suggest only the tools from the Rag database and only Reply with the tool names in a python list."
def ask_question(query):
embeddings = OpenAIEmbeddings(api_key=openai_api_key)
vector_store = Chroma(persist_directory="./chroma_db", embedding_function=embeddings)
llm = ChatOpenAI(api_key=openai_api_key, model_name="gpt-4o-mini",)
retriever = vector_store.as_retriever(
search_type="similarity_score_threshold",
search_kwargs={"k": K_RESULTS, "score_threshold": SIMILARITY_THRESHOLD}
)
chain = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever)
response = chain.invoke({"query": query})
if 'source_documents' in response:
for doc in response['source_documents']:
print(f"Source Document: {doc.metadata['source']}, Section: {doc.metadata.get('section', 'N/A')}\nContent: {doc.page_content}\n")
return response.get("result", "No result found.")```
This i tried this code but still doesn't seem to work properly. My model does not work properly asper the system prompt.
```py
llm = ChatOpenAI(api_key=openai_api_key, model_name="gpt-4o-mini",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": query}])```
The user will enter a prompt like "I need a tool for coding suggestions" and the model to analyse the RAG file and give the name of the tool in a python list which matches the requirement the need of the user.