run-llama / llama-hub

A library of data loaders for LLMs made by the community -- to be used with LlamaIndex and/or LangChain
https://llamahub.ai/
MIT License
3.44k stars 731 forks source link

Wikipedia tools should return text, not documents (Tools aren't DataLoaders!) #828

Closed tslmy closed 8 months ago

tslmy commented 8 months ago

Description

IMO, a tool should work differently from a Data Loader. A tool should return the content, and just the content, if possible. It should not expose to the LLM the fact that it is a Python program. The original implementation gives off the lower-level details to the LLM by emitting characters like these in the Observation:

[Document(id_='ea46abda-4165-4ba1-8cc6-36b0e681c0c5', embedding=None, metadata={}, excluded_embed_metadata_keys=[], excluded_llm_metadata_keys=[], relationships={}, hash='735a0b01227b2ff21ece7f97445fbb9816668aee7922123966d16e057b0a1268', text='

This PR thrives to fix that. Here's a demo:

Before:

    {
      "role": "user",
      "content": "Look up cheesecakes on Wikipedia."
    },
    {
      "role": "assistant",
      "content": "Thought: I need to use a tool to help me find information about cheesecakes.\nAction: load_data\nAction Input: {'pages': ['Cheesecake']}"
    },
    {
      "role": "user",
      "content": "Observation: [Document(id_='ea46abda-4165-4ba1-8cc6-36b0e681c0c5', embedding=None, metadata={}, excluded_embed_metadata_keys=[], excluded_llm_metadata_keys=[], relationships={}, hash='735a0b01227b2ff21ece7f97445fbb9816668aee7922123966d16e057b0a1268', text='Cheesecake is a dessert made with a soft fresh cheese

After:

    {
      "role": "user",
      "content": "Summarize Wikipedia page on Wellerism."
    },
    {
      "role": "assistant",
      "content": "Thought: I need to use a tool to help me answer the question.\nAction: load_data\nAction Input: {'page': 'Wellerism', 'lang': 'en'}"
    },
    {
      "role": "user",
      "content": "Observation: Wellerisms, named after sayings of Sam Weller in Charles Dickens's novel

I also don't think it's wise to load multiple pages with this tool, because each Wikipedia page alone is prone to exceed the context window of the LLM. Plus, the document separators would be too tiny for the LLM to notice. Most importantly, the multi-page support just doesn't match the README!

Type of Change

Please delete options that are not relevant.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Suggested Checklist:

nerdai commented 8 months ago

Fair arguments @tslmy. I can get behind this.

Can you fix so that it passes lint checks?

tslmy commented 8 months ago

Done. Thanks for the review, @nerdai :D

nerdai commented 8 months ago

looks like format check not passing still. Did you run make format and make lint?

tslmy commented 8 months ago

@nerdai , not yet, sorry. I was at work and no access to my personal dev machine. Doing it now.