# pass wandb_callback to the service context callback_manager = CallbackManager([llama_debug, wandb_callback]) service_context = ServiceContext.from_defaults(llm=OpenAI(model="gpt-3.5-turbo-0613", temperature=0), chunk_size=1024, callback_manager=callback_manager)
llama-index-llms-openai
and llama-index-callbacks-wandb
as shown in the Wandb Callback Handler example ().WandbCallbackHandler
and LlamaDebugHandler
. You can refer to the Wandb Callback Handler example () for the correct setup.OpenAI
. The model name should be one of the supported models. In the examples provided, the model used is gpt-4
.ServiceContext
. You can refer to the Service Context Part 7 () for the correct setup.ValueError Traceback (most recent call last) <ipython-input-9-376bc39e3fae> in <cell line: 61>() 59 60 # pass wandb_callback to the service context ---> 61 callback_manager = CallbackManager([llama_debug, wandb_callback]) 62 service_context = ServiceContext.from_defaults(llm=OpenAI(model="gpt-3.5-turbo-0613", temperature=0), chunk_size=1024, callback_manager=callback_manager) /usr/local/lib/python3.10/dist-packages/llama_index/core/callbacks/base.py in __init__(self, handlers) 63 for existing_handler in handlers: 64 if isinstance(existing_handler, type(new_handler)): ---> 65 raise ValueError( 66 "Cannot add two handlers of the same type " 67 f"{type(new_handler)} to the callback manager." ValueError: Cannot add two handlers of the same type <class 'llama_index.callbacks.wandb.base.WandbCallbackHandler'> to the callback manager.
CallbackManager
. In this case, it seems you're trying to add two WandbCallbackHandler
instances.CallbackManager
in LlamaIndex is designed to manage different types of callback handlers. Each handler type can only be added once. This is why you're seeing a ValueError
when you try to add a second WandbCallbackHandler
.CallbackManager
is of a unique type. For example, you might have one WandbCallbackHandler
and one LlamaDebugHandler
, but not two WandbCallbackHandler
instances.CallbackManager
with a WandbCallbackHandler
and a LlamaDebugHandler
:llama_debug = LlamaDebugHandler(print_trace_on_end=True) # wandb.init args run_args = dict( project="llamaindex", ) wandb_callback = WandbCallbackHandler(run_args=run_args) callback_manager = CallbackManager([llama_debug, wandb_callback])
service_context = ServiceContext.from_defaults(llm=OpenAI(model="gpt-3.5-turbo-0613", temperature=0), chunk_size=1024, callback_manager=callback_manager)
lueError Traceback (most recent call last) <ipython-input-9-376bc39e3fae> in <cell line: 61>() 59 60 # pass wandb_callback to the service context ---> 61 callback_manager = CallbackManager([llama_debug, wandb_callback]) 62 service_context = ServiceContext.from_defaults(llm=OpenAI(model="gpt-3.5-turbo-0613", temperature=0), chunk_size=1024, callback_manager=callback_manager) /usr/local/lib/python3.10/dist-packages/llama_index/core/callbacks/base.py in __init__(self, handlers) 63 for existing_handler in handlers: 64 if isinstance(existing_handler, type(new_handler)): ---> 65 raise ValueError( 66 "Cannot add two handlers of the same type " 67 f"{type(new_handler)} to the callback manager." ValueError: Cannot add two handlers of the same type <class 'llama_index.callbacks.wandb.base.WandbCallbackHandler'> to the callback manager.
ServiceContext
in LlamaIndex has been deprecated. The preferred way of setting up the same options is now either globally in the Settings
object or locally in the APIs that use certain modules. from llama_index.embeddings.openai import OpenAIEmbedding from llama_index.core.node_parser import SentenceSplitter from llama_index.llms.openai import OpenAI from llama_index.core import Settings Settings.llm = OpenAI(model="gpt-3.5-turbo") Settings.embed_model = OpenAIEmbedding(model="text-embedding-3-small") Settings.node_parser = SentenceSplitter(chunk_size=512, chunk_overlap=20) Settings.num_output = 512 Settings.context_window = 3900
ServiceContext
. It's caused by trying to add two handlers of the same type to the CallbackManager
. You should ensure that each handler you add to the CallbackManager
is of a unique type.