additional_kwargs
attribute of CompletionResponse
object returned by the complete()
method of the LLM integration when this LLM is used in a simple RAG pipeline.response
is of type llama_index.core.base.response.schema.Response
which only stores the text
attribute of CompletionResponse
.Settings.llm = llm Settings.embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5") documents = SimpleDirectoryReader("data").load_data() index = VectorStoreIndex.from_documents(documents) query_engine = index.as_query_engine() response = query_engine.query("A random question")
additional_kwargs
?additional_kwargs
of CompletionResponse
to store in https://github.com/run-llama/llama_index/blob/main/llama-index-core/llama_index/core/base/response/schema.py#L27 ?log_prob
or token_count
or other metadata.from typing import Dict, List from treelib import Tree from llama_index.core.instrumentation.events import BaseEvent from llama_index.core.instrumentation.event_handlers import BaseEventHandler from llama_index.core.instrumentation.events.llm import ( LLMCompletionEndEvent, LLMChatEndEvent, ) class ExampleEventHandler(BaseEventHandler): events: List[BaseEvent] = [] @classmethod def class_name(cls) -> str: """Class name.""" return "ExampleEventHandler" def handle(self, event: BaseEvent) -> None: """Logic for handling event.""" print("-----------------------") # all events have these attributes print(event.id_) print(event.timestamp) print(event.span_id) # event specific attributes print(f"Event type: {event.class_name()}") if isinstance(event, LLMCompletionEndEvent): print(event.response) print(event.prompt) if isinstance(event, LLMChatEndEvent): print(event.messages) print(event.response) self.events.append(event) print("-----------------------") from llama_index.core.instrumentation import get_dispatcher from llama_index.core.instrumentation.span_handlers import SimpleSpanHandler # root dispatcher root_dispatcher = get_dispatcher() # register span handler event_handler = ExampleEventHandler() root_dispatcher.add_event_handler(event_handler)
trustworthiness_score
which is saved in additional_kwargs
of CompletionResponse
. CompletionResponse
and when the query_engine.query()
returns a Response
object, it decodes the string attribute back into dictionary to get the trustworthiness_score
.base.py
or another python file)?