Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LlamaIndex instrumentation #128

Merged
merged 7 commits into from
Sep 30, 2024
Merged

LlamaIndex instrumentation #128

merged 7 commits into from
Sep 30, 2024

Conversation

desaxce
Copy link
Contributor

@desaxce desaxce commented Sep 26, 2024

Changes:

  • added support to llm.chat and llm.stream_chat, llm.predict, llm.predict_and_call, OpenAIAgent.chat and FunctionCallingAgent.chat.

To test:

  • validate that a call to the following methods creates a single Generation
    • llm.chat
    • llm.stream_chat
    • llm.predict

For the specific case of llm.predict_and_call, LlamaIndex does not fire an event for the tool calls that take place. Hence:

  • either you decorate your tools with Literal AI step tools, in which case you should also wrap the call to llm.predict_and_call in a step or a thread (so that the tool steps have a parent, they cannot be standalone)
  • or you do not decorate the tools and the llm.predict_and_call simply shows a Generation log

Ticket for LlamaIndex to add ToolCallStartEvent and ToolCallEndEvent: run-llama/llama_index#16231

  • validate that a call to query engine shows the same thread as we used to have (user message + RAG agent (retrieval + embedding + synthesise) + assistant message)
  • validate that a call to agent.chat shows:
image

Again, tool calls don't show. However, in the specific case of agents, LlamaIndex fires a AgentToolCallEvent prior to calling the tool. It's not enough to create a full tool step, and I decided it was best to let users decorate their own FunctionTool if they needed logs at that level.

There is an option to refactor the span handler logic to catch the FunctionTool spans that are fired. There are a couple issues related to duplicate firing (nested) and a small revamp of the logic to allow the span handler to open/end steps.

@desaxce desaxce added the bug Something isn't working label Sep 26, 2024
@@ -0,0 +1,166 @@
from typing_extensions import TypedDict
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Untouched, just moved.

@desaxce desaxce linked an issue Sep 26, 2024 that may be closed by this pull request

def instrument_llamaindex(client: "LiteralClient"):
global is_llamaindex_instrumented
if is_llamaindex_instrumented:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple instrumentations of llamaindex lead to steps with cycles.

@desaxce desaxce merged commit 0dbb7c4 into main Sep 30, 2024
2 checks passed
@desaxce desaxce deleted the tmp_instrument_llamaindex branch September 30, 2024 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Instrumentation LlamaIndex
3 participants