but where i can use stored hystory?
- User
but where i can use stored hystory?
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
but where i can use stored hystory?
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
It looks like you're asking about "where I can use stored history?" – I assume you mean "stored history" as in maintaining and utilizing conversation history in your LLM prompt or system. This is a common challenge in building conversational AI, especially for systems like Retrieval-Augmented Generation (RAG) or chatbots, where context from previous interactions needs to be preserved.
Let me break this down step by step, explain where and how to use stored history, and provide an updated prompt example based on our previous discussion. This will help you integrate history effectively while keeping your system accurate and context-aware.
Stored history refers to the record of previous user messages and AI responses in a conversation. It's essential for:
In the prompt I shared earlier, we already have a way to include immediate context (context_on_user_query), but we can extend it to incorporate full stored history for more robust conversations.
You can use stored history in the following key places:
Within the Prompt Itself:
In the System Architecture:
context_on_user_query or as a separate variable.Output Generation:
Common Implementation Pitfalls:
Based on the prompt I provided earlier, I'll enhance it to incorporate stored history. Here's the modified version:
history_request = f"""
You are an advanced conversational AI assistant designed to process user queries within a specific context, while considering the conversation history.
Instructions:
1. Review the conversation history: {history} # This includes all previous exchanges
2. Carefully examine the user's current query: {input_text}
3. Review the provided context: {context_on_user_query} # This can include additional details or documents
4. Formulate a response in {dia_lang} that directly addresses the user's query, drawing from the conversation history and provided context.
5. If the provided context or history is insufficient to answer the query, clearly state so in {dia_lang}.
6. Prioritize information from the history to maintain conversation continuity, but base your answer exclusively on the given history and context.
Constraints:
- Response must be in {dia_lang}
- Only use the provided history and context for your answer
- If history provides relevant details, incorporate them seamlessly
- Keep the response concise and directly relevant
Output format:
- A direct response to the user's query
- Or a clear statement indicating insufficient context or history
Example:
If history is: "User: What are SAP roles? AI: SAP roles include authorizations for users."
And current query is: "Tell me more about roles for cost accounting."
Respond based on that history.
"""
# Example usage with stored history
input_text = "а роли какие" # Current user query
history = "Previous exchange: User: Специалист по расчету себестоимости. AI: А какие роли у специалиста по расчету себестоимости?" # Stored history as a string
context_on_user_query = "SAP roles related to cost accounting include transaction codes for calculations." # Additional context
dia_lang = "Russian"
# Construct the history request
request = history_request.format(input_text=input_text,
history=history,
context_on_user_query=context_on_user_query,
dia_lang=dia_lang)
print(request)
Key Changes and Explanation:
{history} as a new variable in the instructions. This allows you to pass the full stored history (e.g., a string of past messages) directly into the prompt.Here's a simple Python example using a library like OpenAI's API (or similar). Assume you're maintaining a list of conversation history:
import openai # Or your LLM library
# Simulated conversation history storage
conversation_history = [] # e.g., ["User: First query. AI: Response."]
def add_to_history(user_input, ai_response):
conversation_history.append(f"User: {user_input}. AI: {ai_response}")
def generate_response(input_text, context_on_user_query, dia_lang):
# Convert history to a string for the prompt
history_str = "\n".join(conversation_history) # Or summarize if too long
# Construct the prompt
prompt_template = f"""...""" # Use the updated history_request from above
full_prompt = prompt_template.format(
input_text=input_text,
history=history_str,
context_on_user_query=context_on_user_query,
dia_lang=dia_lang
)
# Call the LLM
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo", # Or your model
messages=[{"role": "system", "content": full_prompt}],
# Add more messages if needed for full context
)
ai_output = response['choices'][0]['message']['content']
add_to_history(input_text, ai_output) # Store the new exchange
return ai_output
# Example call
user_query = "а роли какие"
response = generate_response(user_query, "Специалист по расчету себестоимости", "Russian")
print(response)
Benefits of This Approach:
If you provide more details about your setup (e.g., the LLM library you're using or how you're storing history), I can refine this further!