Find answers from the community

Updated 2 months ago

From the help docs https gpt index

From the help docs https://gpt-index.readthedocs.io/en/v0.7.16/examples/chat_engine/chat_engine_context.html can someone point me to an example of updating memory = ChatMemoryBuffer.from_defaults(token_limit=1500) with a custom interaction?
L
e
11 comments
What do you mean by custom interaction? Like adding a message to the memory?
@Logan M Yes, I'm inserting a custom interaction along with the actual chat messages. I use this format with 'react' and it works, but fails with 'context'
Plain Text
for element in incoming_chat_history:
        custom_chat_history.append(ChatMessage(role=MessageRole.USER, content=element[0]))
        custom_chat_history.append(ChatMessage(role=MessageRole.ASSISTANT, content=element[1]))
Example:
Plain Text
chat_engine = index.as_chat_engine(
                    chat_mode="context",
                    memory=custom_chat_history,
                    system_prompt="Please only answer questions relevant to the context.",
    )
True this instead

Plain Text
chat_engine = index.as_chat_engine(
              chat_mode="context",
              chat_history=custom_chat_history,
              system_prompt="Please only answer questions relevant to the context.",
    )
Got it! One last question on a related note πŸ˜‰ Are there any custom {variables} I should use in the system_prompt to instruct the AI to only answers questions from data retrieved from the index? I was using "context" but didn't see if there was a specific reference like there is with custom prompts?
And once again THANK YOU
Yea not really any custom variables i can think of. If you know the content of the underlying index ahead of time, you can set the system prompt to be more specific

i.e. You are a chatbot with access to extra context information about X. Only answer questions if you can find the answer in the context, otherwise, kindly inform the user that you cannot find the answer."
I wrote that on the spot, but it sounds like it should work haha
Yep that should do it
Add a reply
Sign up and join the conversation on Discord