Skip to content

Commit

Permalink
Mem0 fix in embedchain (#1506)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev-Khant authored Jul 19, 2024
1 parent e9136c1 commit 51fd7db
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
10 changes: 5 additions & 5 deletions embedchain/embedchain/config/llm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@
""" # noqa:E501

DEFAULT_PROMPT_WITH_MEM0_MEMORY = """
You are a Q&A expert system. Your responses must always be rooted in the context provided for each query. You are also provided with the conversation history and memories with the user. Make sure to use relevant context from conversation history and memories as needed.
You are an expert at answering questions based on provided memories. You are also provided with the context and conversation history of the user. Make sure to use relevant context from conversation history and context as needed.
Here are some guidelines to follow:
1. Refrain from explicitly mentioning the context provided in your response.
2. Take into consideration the conversation history and memories provided.
3. The context should silently guide your answers without being directly acknowledged.
4. Do not use phrases such as 'According to the context provided', 'Based on the context, ...' etc.
2. Take into consideration the conversation history and context provided.
3. Do not use phrases such as 'According to the context provided', 'Based on the context, ...' etc.
Striclty return the query exactly as it is if it is not a question or if no relevant information is found.
Context information:
----------------------
Expand Down
7 changes: 3 additions & 4 deletions embedchain/embedchain/embedchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ def chat(
memories = None
if self.mem0_memory:
memories = self.mem0_memory.search(
query=input_query, agent_id=self.config.id, session_id=session_id, limit=self.memory_config.top_k
query=input_query, agent_id=self.config.id, user_id=session_id, limit=self.memory_config.top_k
)

# Update the history beforehand so that we can handle multiple chat sessions in the same python session
Expand Down Expand Up @@ -639,10 +639,9 @@ def chat(
)

# Add to Mem0 memory if enabled
# TODO: Might need to prepend with some text like:
# "Remember user preferences from following user query: {input_query}"
# Adding answer here because it would be much useful than input question itself
if self.mem0_memory:
self.mem0_memory.add(data=input_query, agent_id=self.config.id, session_id=session_id)
self.mem0_memory.add(data=answer, agent_id=self.config.id, user_id=session_id)

# add conversation in memory
self.llm.add_history(self.config.id, input_query, answer, session_id=session_id)
Expand Down
2 changes: 1 addition & 1 deletion embedchain/embedchain/llm/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _get_answer(self, prompt: str, config: BaseLlmConfig) -> str:
api_key = config.api_key or os.environ["OPENAI_API_KEY"]
base_url = config.base_url or os.environ.get("OPENAI_API_BASE", None)
if config.top_p:
kwargs["model_kwargs"]["top_p"] = config.top_p
kwargs["top_p"] = config.top_p
if config.default_headers:
kwargs["default_headers"] = config.default_headers
if config.stream:
Expand Down
1 change: 0 additions & 1 deletion embedchain/embedchain/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,6 @@ def validate_config(config_data):
},
},
Optional("memory"): {
"api_key": str,
Optional("top_k"): int,
},
}
Expand Down
2 changes: 1 addition & 1 deletion embedchain/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "embedchain"
version = "0.1.117"
version = "0.1.118"
description = "Simplest open source retrieval (RAG) framework"
authors = [
"Taranjeet Singh <taranjeet@embedchain.ai>",
Expand Down

0 comments on commit 51fd7db

Please sign in to comment.