Closed lcneyc closed 4 months ago
@thinkall for awareness
Hi @lcneyc , I see you were running the code in debug mode with vscode. Did you set the default python in launch.json under .vscode? It's possible that the default python in debug is different from the one in conda.
Hi @thinkall , it's same running in the default mode. Thanks
Hi @thinkall , it's same running in the default mode. Thanks
Could you please share the code? Thanks.
For some problems about proxy in jupyter notebook, I converted the code into ".py" file to run in the terminal. Code:
import autogen
config_list = [
{
'model': 'gpt-4',
'api_key': 'sk-xxxx',
},
]
assert len(config_list) > 0
print("models to use: ", [config_list[i]["model"] for i in range(len(config_list))])
# It first looks for environment variable "OAI_CONFIG_LIST" which needs to be a valid json string. If that variable is not found, it then looks for a json file named "OAI_CONFIG_LIST". It filters the configs by models (you can filter by other keys as well). Only the gpt-4 and gpt-3.5-turbo models are kept in the list based on the filter condition.
#
# The config list looks like the following:
# ```python
# config_list = [
# {
# 'model': 'gpt-4',
# 'api_key': '<your OpenAI API key here>',
# },
# {
# 'model': 'gpt-4',
# 'api_key': '<your Azure OpenAI API key here>',
# 'api_base': '<your Azure OpenAI API base here>',
# 'api_type': 'azure',
# 'api_version': '2023-06-01-preview',
# },
# {
# 'model': 'gpt-3.5-turbo',
# 'api_key': '<your Azure OpenAI API key here>',
# 'api_base': '<your Azure OpenAI API base here>',
# 'api_type': 'azure',
# 'api_version': '2023-06-01-preview',
# },
# ]
# ```
#
# If you open this notebook in colab, you can upload your files by clicking the file icon on the left panel and then choose "upload file" icon.
#
# You can set the value of config_list in other ways you prefer, e.g., loading from a YAML file.
# ## Construct agents for RetrieveChat
#
# We start by initialzing the `RetrieveAssistantAgent` and `RetrieveUserProxyAgent`. The system message needs to be set to "You are a helpful assistant." for RetrieveAssistantAgent. The detailed instructions are given in the user message. Later we will use the `RetrieveUserProxyAgent.generate_init_prompt` to combine the instructions and a retrieval augmented generation task for an initial prompt to be sent to the LLM assistant.
# In[13]:
# Accepted file formats for that can be stored in
# a vector database instance
from autogen.retrieve_utils import TEXT_FORMATS
print("Accepted file formats for `docs_path`:")
print(TEXT_FORMATS)
# In[14]:
from autogen.agentchat.contrib.retrieve_assistant_agent import RetrieveAssistantAgent
from autogen.agentchat.contrib.retrieve_user_proxy_agent import RetrieveUserProxyAgent
import chromadb
autogen.ChatCompletion.start_logging()
# 1. create an RetrieveAssistantAgent instance named "assistant"
assistant = RetrieveAssistantAgent(
name="assistant",
system_message="You are a helpful assistant.",
llm_config={
"request_timeout": 600,
"seed": 62,
"config_list": config_list,
},
)
# 2. create the RetrieveUserProxyAgent instance named "ragproxyagent"
# By default, the human_input_mode is "ALWAYS", which means the agent will ask for human input at every step. We set it to "NEVER" here.
# `docs_path` is the path to the docs directory. By default, it is set to "./docs". Here we generated the documentations from FLAML's docstrings.
# Navigate to the website folder and run `pydoc-markdown` and it will generate folder `reference` under `website/docs`.
# `task` indicates the kind of task we're working on. In this example, it's a `code` task.
# `chunk_token_size` is the chunk token size for the retrieve chat. By default, it is set to `max_tokens * 0.6`, here we set it to 2000.
ragproxyagent = RetrieveUserProxyAgent(
name="ragproxyagent",
human_input_mode="NEVER",
max_consecutive_auto_reply=10,
retrieve_config={
"task": "code",
"docs_path": "./autogen/website/docs/reference",
"chunk_token_size": 2000,
"model": config_list[0]["model"],
"client": chromadb.PersistentClient(path="/tmp/chromadb"),
"embedding_model": "all-mpnet-base-v2",
},
)
# <a id="example-1"></a>
# ### Example 1
#
# [back to top](#toc)
#
# Use RetrieveChat to help generate sample code and automatically run the code and fix errors if there is any.
#
# Problem: Which API should I use if I want to use FLAML for a classification task and I want to train the model in 30 seconds. Use spark to parallel the training. Force cancel jobs if time limit is reached.
# In[6]:
# reset the assistant. Always reset the assistant before starting a new conversation.
assistant.reset()
# given a problem, we use the ragproxyagent to generate a prompt to be sent to the assistant as the initial message.
# the assistant receives the message and generates a response. The response will be sent back to the ragproxyagent for processing.
# The conversation continues until the termination condition is met, in RetrieveChat, the termination condition when no human-in-loop is no code block detected.
# With human-in-loop, the conversation will continue until the user says "exit".
code_problem = "How can I use FLAML to perform a classification task and use spark to do parallel training. Train 30 seconds and force cancel jobs if time limit is reached."
ragproxyagent.initiate_chat(assistant, problem=code_problem, search_string="spark") # search_string is used as an extra filter for the embeddings search, in this case, we only want to search documents that contain "spark".
Thanks. @thinkall
Hi, I encountered the same issue today. Fix it by change line 385 in query_vector_db from:
collection = client.get_collection(collection_name)
To:
collection = client.get_or_create_collection(collection_name)
Hope it helps!
Hi, @Melo96 @thinkall Now it works well. Here is the solution summary: Q1:Sentence_transformers already exists in my environment, autogen still print “The sentence_transformers python package is not installed. Please install it with pip install sentence_transformers“. A1:It occurs when executing the code in embedding_fuction.py [Line 38]
try:
from sentence_transformers import SentenceTransformer
except ImportError:
raise ValueError(
"The sentence_transformers python package is not installed. Please install it with `pip install sentence_transformers`"
)
The reason is somthing wrong with CUDA12.0 and pytorch2.1.0, and it occurs ImportError.
Here's the solution:https://github.com/pytorch/pytorch/issues/111469#issuecomment-1773937884
Q2:ValueError: Collection autogen-docs does not exist.
A2: @Melo96 's comment help a lot!
Q3:No more context, will terminate.
A3:rm -rf /tmp/chromadb
for each retry.
Hi @Melo96 , @lcneyc , I've updated the notebook which has more clear comments on how to generate the documentations, please check it out.
And for recreating the collection, you just need to set get_or_create
to be True in the retrieve_config.
For no more context issue, make sure you have set the docs path correctly and updated the question accordingly. For instance, you may don't have any doc contains "spark", then search string should be unsetted.
@thinkall BTW, this is still an issue and I was sure that the "get_or_create" argument was set to "True". I downloaded and used the Autogen from Github as of December 22nd, 2023, so at least from that date what @Melo96 states is still valid because when I made the change in the "retrieve_utils.py" file for the collection as per the suggestion listed here, I reran it and it worked fine.
Also, I was using LM Studio as my LLM config. I hope this helps.
Hi,
This still happens in main
.
I changed this line locally to use get_or_create_collection
:
https://github.com/microsoft/autogen/blob/main/autogen/retrieve_utils.py#L470C1-L471C1
Is there a plan to fix this? @thinkall
Hi, This still happens in
main
. I changed this line locally to useget_or_create_collection
: https://github.com/microsoft/autogen/blob/main/autogen/retrieve_utils.py#L470C1-L471C1Is there a plan to fix this? @thinkall
Hi @AsafEitani , could you create a new issue and describe the steps for reproducing? Thanks.
Also, please upgrade AutoGen to the latest version if possible.
pip install sentence_transformers
“.ragproxyagent.initiate_chat(assistant, problem=code_problem, search_string="spark")