#๐Ÿ”’ How to add a system prompt in Langchian RAG model

156 messages ยท Page 1 of 1 (latest)

azure jewel
#

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.
heavy oreBOT
#

@azure jewel

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

mental tide
#

oh, it's the parameter for ask_question

#

@azure jewel when you do llm = ChatOpenAI(api_key=openai_api_key, model_name="gpt-4o-mini",), you are not having a conversation with the LLM. that line is for establishing a connection with the LLM. So you should not put any interaction information in that constructor.

response = chain.invoke({"query": query}) appears to be the part where you actually interact with the LLM.

azure jewel
mental tide
azure jewel
#

so what do u want me to put there?

mental tide
#
[
    {"role": "system", "content": SYSTEM_PROMPT},
    {"role": "user", "content": query},
]

this is what I would expect to see for the beginning of an interaction with an LLM.

mental tide
azure jewel
#
    message = [
        {"role": "system", "content": SYSTEM_PROMPT},
        {"role": "user", "content": query},
    ]
    
    llm = ChatOpenAI(api_key=openai_api_key, model_name="gpt-4o-mini",
                     messages=message)```
#

smth like that?

azure jewel
mental tide
#

Do not put anything in ChatOpenAI( ) that is intended to "talk to" the llm. Like I said, that part is only for establishing a connection to the LLM.

azure jewel
mental tide
#

From what I can tell, response = chain.invoke({"query": query}) is the part where you "talk to" the LLM.

[
    {"role": "system", "content": SYSTEM_PROMPT},
    {"role": "user", "content": query},
]

I have never used langchain, but this looks like the kind of code I've written to prompt LLMs with system prompts.

#

@azure jewel be sure to fully read everything I have said. it should be enough information for you to make progress.

azure jewel
#

ur right toh

#

tahst talks and gives info to the llm

mental tide
azure jewel
#

but my model is not using the rag db and answering asper it

azure jewel
mental tide
azure jewel
#
TypeError: argument 'text': 'list' object cannot be converted to 'PyString'

Traceback (most recent call last)
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/venv/lib/python3.10/site-packages/flask/app.py", line 1498, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/venv/lib/python3.10/site-packages/flask/app.py", line 1476, in wsgi_app
response = self.handle_exception(e)
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/venv/lib/python3.10/site-packages/flask/app.py", line 1473, in wsgi_app
response = self.full_dispatch_request()
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/venv/lib/python3.10/site-packages/flask/app.py", line 882, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/venv/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/venv/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/web.py", line 12, in index
result = ask_question(query)
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/input.py", line 34, in ask_question
response = chain.invoke(message)
#
message = [
        {"role": "system", "content": SYSTEM_PROMPT},
        {"role": "user", "content": query},
    ]

    llm = ChatOpenAI()

    retriever = vector_store.as_retriever(
        search_type="similarity_score_threshold",
        search_kwargs={"k": K_RESULTS, "score_threshold": SIMILARITY_THRESHOLD},
        model_name="gpt-4o-mini"
    )

    chain = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever)
    response = chain.invoke(message)```
mental tide
#

look at the documentation for chain.invoke to see what type message needs to be.

#

llm = ChatOpenAI() you removed everything from ChatOpenAI( )?

azure jewel
mental tide
#

@azure jewel ChatOpenAI( ) is for establishing a connection to an LLM at OpenAI. It is not for talking to an LLM. You still need to provide it with information relevant to establishing a connection.

azure jewel
#

so its fine ig

#

bc there is no error related to it

mental tide
#

it's probably erroring before you get to a part where that would cause an error.

azure jewel
#

llm = ChatOpenAI(model="gpt-4o-mini", api_key=openai_api_key)

mental tide
#

notice this part

    (
        "system",
        "You are a helpful assistant that translates English to French. Translate the user sentence.",
    ),
    ("human", "I love programming."),
]
ai_msg = llm.invoke(messages)
azure jewel
#

yes yes got it

mental tide
#

note how the system and human prompts are structured.

azure jewel
#

still same toh

#

TypeError: argument 'text': 'list' object cannot be converted to 'PyString'

mental tide
azure jewel
#
message = [
        ("system", SYSTEM_PROMPT,),
        ("human", query),
    ]

    llm = ChatOpenAI(model="gpt-4o-mini", api_key=openai_api_key)

    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(message)```
mental tide
#

try doing llm.invoke(message), just to see if that works when you bypass the retriever

azure jewel
#

AttributeError: 'AIMessage' object has no attribute 'get'

mental tide
azure jewel
#

ya sorry my bad

#
from langchain_chroma import Chroma
from langchain_openai import OpenAIEmbeddings, ChatOpenAI
from langchain.chains import RetrievalQA
import os
from dotenv import load_dotenv

load_dotenv()
openai_api_key = os.getenv("OPENAI_API_KEY")

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)

    message = [
        ("system", SYSTEM_PROMPT,),
        ("human", query),
    ]

    llm = ChatOpenAI(model="gpt-4o-mini", api_key=openai_api_key)

    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 = llm.invoke(message)
    print(response.content)

    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.")
#
AttributeError: 'AIMessage' object has no attribute 'get'

Traceback (most recent call last)
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/venv/lib/python3.10/site-packages/flask/app.py", line 1498, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/venv/lib/python3.10/site-packages/flask/app.py", line 1476, in wsgi_app
response = self.handle_exception(e)
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/venv/lib/python3.10/site-packages/flask/app.py", line 1473, in wsgi_app
response = self.full_dispatch_request()
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/venv/lib/python3.10/site-packages/flask/app.py", line 882, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/venv/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/venv/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/web.py", line 12, in index
result = ask_question(query)
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/input.py", line 40, in ask_question
return response.get("result", "No result found.")
AttributeError: 'AIMessage' object has no attribute 'get'```
mental tide
#

@azure jewel the error happens in the last line of the function, which means that print(response.content) completed without error. what did it print?

azure jewel
#
["Descript", "Murf AI", "Speechelo"]
mental tide
#

interesting

azure jewel
#

this is not the proper ans

mental tide
#
from langchain_core.prompts import ChatPromptTemplate

prompt = ChatPromptTemplate.from_messages(
    [
        (
            "system",
            "You are a helpful assistant that translates {input_language} to {output_language}.",
        ),
        ("human", "{input}"),
    ]
)

chain = prompt | llm
chain.invoke(
    {
        "input_language": "English",
        "output_language": "German",
        "input": "I love programming.",
    }
)

This might be helpful for you.

azure jewel
#

bc in my rag there is only one file 11labs

#

and it should suggest that

#

what shoulf be in chain.invoke?

#

{
"input_language": "English",
"output_language": "German",
"input": "I love programming.",
}

mental tide
azure jewel
#

yes that i did

#

but what should be in the invoke function

mental tide
#

you did what?

#

how about: rewrite this part to use your system prompt

prompt = ChatPromptTemplate.from_messages(
    [
        (
            "system",
            "You are a helpful assistant that translates {input_language} to {output_language}.",
        ),
        ("human", "{input}"),
    ]
)
azure jewel
#

yes i did

mental tide
#

please show me.

azure jewel
#

but

#
embeddings = OpenAIEmbeddings(api_key=openai_api_key)
    vector_store = Chroma(persist_directory="./chroma_db", embedding_function=embeddings)

    llm = ChatOpenAI(model="gpt-4o-mini", api_key=openai_api_key)

    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)

    prompt = ChatPromptTemplate.from_messages(
        [
            ("system", SYSTEM_PROMPT,),
            ("human", query),
        ]
    )

    chain = prompt | llm

    response = chain.invoke()```
#

what to put in the invoke fun

mental tide
#
    prompt = ChatPromptTemplate.from_messages(
        [
            ("system", SYSTEM_PROMPT,),
            ("human", "{user_input}"),
        ]
    )
azure jewel
#

brother

#

response = chain.invoke()

#

in the code

mental tide
#

yes, what do you think needs to go there, given the code I just provided?

azure jewel
#

prompt

#

but

mental tide
#

No

azure jewel
#

qhat

mental tide
#

Look at this again


prompt = ChatPromptTemplate.from_messages(
    [
        (
            "system",
            "You are a helpful assistant that translates {input_language} to {output_language}.",
        ),
        ("human", "{input}"),
    ]
)

chain = prompt | llm
chain.invoke(
    {
        "input_language": "English",
        "output_language": "German",
        "input": "I love programming.",
    }
)

in chain.invoke, you're giving a dict of values to put in the "slots" of prompt.

#
    prompt = ChatPromptTemplate.from_messages(
        [
            ("system", SYSTEM_PROMPT,),
            ("human", "{user_input}"),
        ]
    )

what are the slots, and what variable that you already have fills the slot?

azure jewel
#
prompt = ChatPromptTemplate.from_messages(
        [
            ("system", SYSTEM_PROMPT,),
            ("human", query),
        ]
    )

    chain = prompt | llm

    response = chain.invoke(
        {
            "human": query,
            "system": SYSTEM_PROMPT
        }
    )```
mental tide
#
    prompt = ChatPromptTemplate.from_messages(
        [
            ("system", SYSTEM_PROMPT,),
            ("human", "{user_input}"),
        ]
    )

Please use exactly this for prompt.

#

@azure jewel using the exact value for prompt that I provided only, what are the slots?

azure jewel
#

wdym slots?

mental tide
#
# DO NOT PUT THIS IN YOUR CODE
prompt = ChatPromptTemplate.from_messages(
    [
        (
            "system",
            "You are a helpful assistant that translates {input_language} to {output_language}.",
        ),
        ("human", "{input}"),
    ]
)

This code has three slots.

#

then they do this

chain.invoke(
    {
        "input_language": "English",
        "output_language": "German",
        "input": "I love programming.",
    }
)

where they fill the three slots

#
# this is your code
    prompt = ChatPromptTemplate.from_messages(
        [
            ("system", SYSTEM_PROMPT,),
            ("human", "{user_input}"),
        ]
    )

what slots are there?

azure jewel
#

2 slots

#

system and human

mental tide
#

what are they?

#

No

azure jewel
#

value

mental tide
#

Those are not the slots.

azure jewel
#

SYSTEM_PROMPT and user_input

mental tide
#

Those are not the slots.

#
# DO NOT PUT THIS IN YOUR CODE
prompt = ChatPromptTemplate.from_messages(
    [
        (
            "system",
            "You are a helpful assistant that translates {input_language} to {output_language}.",
        ),
        ("human", "{input}"),
    ]
)

The three slots are input_language, output_language, and input

#

do you see?

azure jewel
#

yes

#

right

mental tide
azure jewel
#

i thought

#

but when i said 2

#

u told what are they

#

tahst why got confunsed

#

my bad

mental tide
#

I wanted to see what you thought they were

azure jewel
#

i was gonna put

mental tide
#
chain.invoke(
    {
        "input_language": "English",
        "output_language": "German",
        "input": "I love programming.",
    }
)

this is how they invoke the chain with their values for the slots

azure jewel
#

{SYSTEM_PROMPT}

azure jewel
#

ill do mine then

#
    prompt = ChatPromptTemplate.from_messages(
        [
            ("system", SYSTEM_PROMPT,),
            ("human", "{query}"),
        ]
    )

    chain = prompt | llm

    response = chain.invoke(
        {
            "query": query
        }
    )```
mental tide
#

try it.

azure jewel
#

Traceback (most recent call last)
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/venv/lib/python3.10/site-packages/flask/app.py", line 1498, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/venv/lib/python3.10/site-packages/flask/app.py", line 1476, in wsgi_app
response = self.handle_exception(e)
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/venv/lib/python3.10/site-packages/flask/app.py", line 1473, in wsgi_app
response = self.full_dispatch_request()
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/venv/lib/python3.10/site-packages/flask/app.py", line 882, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/venv/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/venv/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/web.py", line 12, in index
result = ask_question(query)
File "/Users/ryanbijoy/Documents/Main/tests/testing_site/input.py", line 51, in ask_question
return response.get("result", "No result found.")
AttributeError: 'AIMessage' object has no attribute 'get'```
#

printed = ["Descript", "Murf AI", "Voicemod", "Speechelo"]

#

but brother

#

the llm is not getting my rag file

mental tide
#

I know

#

you're now interacting with the llm in a way that uses your system prompt
now we just need to work RetrievalQA back into the chain

#

or, work retriever back into the chain, I should say

#

can you show your whole current code, @azure jewel?

azure jewel
#
from langchain_chroma import Chroma
from langchain_openai import OpenAIEmbeddings, ChatOpenAI
from langchain.chains import RetrievalQA
from langchain_core.prompts import ChatPromptTemplate
import os
from dotenv import load_dotenv

load_dotenv()
openai_api_key = os.getenv("OPENAI_API_KEY")

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(model="gpt-4o-mini", api_key=openai_api_key)

    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)

    prompt = ChatPromptTemplate.from_messages(
        [
            ("system", SYSTEM_PROMPT,),
            ("human", "{query}"),
        ]
    )

    chain = prompt | llm

    response = chain.invoke(
        {
            "query": query
        }
    )

    print(response.content)

    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.")
mental tide
#

@azure jewel

    retriever = vector_store.as_retriever(
        search_type="similarity_score_threshold",
        search_kwargs={"k": K_RESULTS, "score_threshold": SIMILARITY_THRESHOLD},
    )
    prompt = ChatPromptTemplate.from_messages(
        [
            ("system", SYSTEM_PROMPT),
            ("human", "{query}"),
        ]
    )
    chain = RetrievalQA.from_chain_type(
        llm=llm,
        chain_type="stuff",
        retriever=retriever,
        prompt=prompt
    )
    response = chain.invoke(
        {
            "query": query
        }
    )

put this in the right spot in your code

azure jewel
#

okayy

mental tide
#

!paste

heavy oreBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

azure jewel
mental tide
#

please show the whole updated code also

azure jewel
#
from langchain_chroma import Chroma
from langchain_openai import OpenAIEmbeddings, ChatOpenAI
from langchain.chains import RetrievalQA
from langchain_core.prompts import ChatPromptTemplate
import os
from dotenv import load_dotenv

load_dotenv()
openai_api_key = os.getenv("OPENAI_API_KEY")

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(model="gpt-4o-mini", api_key=openai_api_key)

    retriever = vector_store.as_retriever(
        search_type="similarity_score_threshold",
        search_kwargs={"k": K_RESULTS, "score_threshold": SIMILARITY_THRESHOLD},
    )
    prompt = ChatPromptTemplate.from_messages(
        [
            ("system", SYSTEM_PROMPT),
            ("human", "{query}"),
        ]
    )
    chain = RetrievalQA.from_chain_type(
        llm=llm,
        chain_type="stuff",
        retriever=retriever,
        prompt=prompt
    )
    response = chain.invoke(
        {
            "query": query
        }
    )
    
    print(response.content)

    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.")
mental tide
#

(the page shows how to not use the deprecated class.)

azure jewel
#

btw @mental tide thanks you so much for your help

#

i apperatiate it

#

once ill make chnages and if it works ill let uk

#

hey done

#
from langchain_chroma import Chroma
from langchain_openai import OpenAIEmbeddings, ChatOpenAI
from langchain.chains import RetrievalQA
from langchain_core.prompts import ChatPromptTemplate
from langchain.chains import create_retrieval_chain
import os
from langchain.chains.combine_documents import create_stuff_documents_chain
from dotenv import load_dotenv

load_dotenv()
openai_api_key = os.getenv("OPENAI_API_KEY")

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(model="gpt-4o-mini", api_key=openai_api_key)

    retriever = vector_store.as_retriever(
        search_type="similarity_score_threshold",
        search_kwargs={"k": K_RESULTS, "score_threshold": SIMILARITY_THRESHOLD},
    )
    prompt = ChatPromptTemplate.from_messages(
        [
            ("system", SYSTEM_PROMPT),
            ("human", "{query}"),
        ]
    )
    question_answer_chain = create_stuff_documents_chain(llm, prompt)
    chain = create_retrieval_chain(retriever, question_answer_chain)

    response = chain.invoke(
        {
            "query": query
        }
    )

    print(response.content)

    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.")
#

!paste

#

@mental tide i send u okay

mental tide
#

@azure jewel I had to do a horrible work thing
does it work now?

azure jewel
mental tide
azure jewel
#

okay man np ill check it

#

thanks for help toh

#

@mental tide ill tell u if it works, wont disturb u much. will just ask u some suggestions or advice

heavy oreBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.