query_engine = index.as_chat_engine(chat_mode='condense_plus_context', similarity_top_k=similarity_top_k, llm=llm_engine, system_prompt=prepared_system_prompt) query_tool = QueryEngineTool( query_engine=query_engine, metadata=ToolMetadata( name="query_tool", description=self.query_description, ), ) tools.append(query_tool) agent = OpenAIAgent.from_tools( tools, llm=llm_engine, verbose=True, system_prompt=self.system_prompt ) response = agent.chat(query_text, chat_history=chat_history) # <====== Exception
vector_store = storage_service.get_vector_store(collection_name, db_name) embed_model = OpenAIEmbedding(mode='similarity', embed_batch_size=2000, api_key=api_Key) service_context = ServiceContext.from_defaults(chunk_size=project_chunk_size, embed_model=embed_model, llm=None, callback_manager=token_counter_callback_manager) node_parser = SimpleNodeParser.from_defaults(chunk_size=project_chunk_size, chunk_overlap=20) index = VectorStoreIndex.from_vector_store(vector_store=vector_store, service_context=service_context)
from llama_index.agent.openai import OpenAIAgentWorker, OpenAIAgent # Import and initialize our tool spec from .image_tool_spec import TextToImageToolSpec text_to_image_spec = TextToImageToolSpec() tools = text_to_image_spec.to_tool_list() # Create the Agent with our tools agent = OpenAIAgent.from_tools(tools, verbose=False) print(agent.chat("show an of a beautiful beach with a palm tree at sunset"))
# My current approach chatmemory = ChatMemoryBuffer.from_defaults(token_limit=(history_limit + context_limit)) retriever = index.as_retriever(verbose=True, chat_mode="context", similarity_top_k=similarity_top_k) custom_chat_engine = CustomContext.from_defaults( # Inherits ContextChatEngine and slightly changes it retriever=retriever, memory=chatmemory, context_template=generate_context_template(), system_prompt=prepared_system_prompt, node_postprocessors=[CustomPostprocessor( context_limit, query_text + prepared_system_prompt, project.db_name, include_threshold)], service_context=service_context) response = custom_chat_engine.chat(query_text, chat_history=chat_history)
OpenAIAgent.from_tools(??)
token_counter = TokenCountingHandler( tokenizer=tiktoken.encoding_for_model(model_name).encode, verbose=False ) callback_manager = CallbackManager([token_counter]) service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, chunk_size=project_chunk_size, callback_manager=callback_manager) index = VectorStoreIndex.from_vector_store(vector_store, service_context) retriever = index.as_retriever(verbose=True, chat_mode="context", similarity_top_k=similarity_top_k) custom_chat_engine = CustomContext.from_defaults( retriever=retriever, memory=chatmemory, context_template=generate_context_template(), system_prompt=prepared_system_prompt, node_postprocessors=[CustomPostprocessor( context_limit, query_text + prepared_system_prompt, project.db_name, None)]) response = custom_chat_engine.chat(query_text, chat_history=chat_history) tokens_used = token_counter.total_llm_token_count # <----- ALWAYS ZERO
vector_store = storage_service.get_vector_store(collection_name, db_name) storage_context = StorageContext.from_defaults(vector_store=vector_store) embed_model = OpenAIEmbedding(mode='similarity', embed_batch_size=2000, api_key=user_settings_data.item.get('openai_key')) service_context = ServiceContext.from_defaults(chunk_size=chunk_size, embed_model=embed_model, llm=None, callback_manager=token_counter_callback_manager) node_parser = SimpleNodeParser.from_defaults(chunk_size=chunk_size, chunk_overlap=20) VectorStoreIndex(nodes, storage_context=storage_context, service_context=service_context) # <== THIS
index = VectorStoreIndex.from_vector_store(vector_store=vector_store, service_context=service_context) index._add_nodes_to_index(nodes=content_nodes) # <== EXCEPTION: index structure is not provided
retriever = index.as_retriever(verbose=True, chat_mode="context", similarity_top_k=similarity_top_k) # CustomContext inherits the ContextChatEngine, and just has a small changes for the best results. custom_chat_engine = CustomContext.from_defaults( retriever=retriever, memory=chatmemory, context_template=generate_context_template(), system_prompt=prepared_system_prompt, node_postprocessors=[CustomPostprocessor( context_limit, query_text + prepared_system_prompt, project.db_name, None)]) response = custom_chat_engine.chat(query_text, chat_history=chat_history)
node_parser = SimpleNodeParser.from_defaults(chunk_size=chunk_size, chunk_overlap=20) content_nodes = node_parser.get_nodes_from_documents([document]) index = VectorStoreIndex(content_nodes, storage_context=storage_context, service_context=service_context)
embed_model = OpenAIEmbedding(mode='similarity', embed_batch_size=2000) service_context = ServiceContext.from_defaults(chunk_size=chunk_size, embed_model=embed_model, callback_manager=token_counter_callback_manager) node_parser = SimpleNodeParser.from_defaults(chunk_size=chunk_size, chunk_overlap=20) index = VectorStoreIndex(nodes, storage_context=storage_context, service_context=service_context)
query_engine = index.as_chat_engine(verbose=True,chat_mode="context", system_prompt=system_prompt) response = query_engine.chat(query_text, chat_history=chat_history)
document = Document(text) document.doc_id = data_source_id service_context = ServiceContext.from_defaults(chunk_size=chunk_size)#1024) vector_store = QdrantVectorStore(client=get_qrant_client(), collection_name=project_id) storage_context = StorageContext.from_defaults(vector_store=vector_store) index = VectorStoreIndex.from_documents( [document], storage_context=storage_context, service_context=service_context )
return cls( nodes=nodes, storage_context=storage_context, service_context=service_context, **kwargs, )