mirror of
https://github.com/neuml/txtai.git
synced 2026-10-11 21:39:55 +00:00
30 KiB
30 KiB
In [ ]:
%%capture
!pip install git+https://github.com/neuml/txtai#egg=txtai[agent,graph]In [ ]:
from txtai import Agent
agent = Agent(
tools=[{
"name": "wikipedia",
"description": "Searches a Wikipedia database",
"provider": "huggingface-hub",
"container": "neuml/txtai-wikipedia"
}],
llm="Qwen/Qwen3-4B-Instruct-2507",
max_iterations=10,
)In [ ]:
from IPython.display import display, Markdown
answer = agent("""
I'm bored 🥱. Think about 2-3 disparate topics and use those to search wikipedia to generate something fascinating.
Write a report summarizing each article. Include a section with a list of article hyperlinks.
Write the text as Markdown.
""", maxlength=16000)
display(Markdown(answer))[32;20;1m======== New task ========[0m
[37;1m
I'm bored 🥱. Think about 2-3 disparate topics and use those to search wikipedia to generate something fascinating.
Write a report summarizing each article. Include a section with a list of article hyperlinks.
Write the text as Markdown.
[0m
[33;1m=== Agent thoughts:[0m
[0mThought: I will use Wikipedia to search for articles related to three disparate topics. The first topic will be the "Great Barrier Reef", the second topic will be "Dark Matter", and the third topic will be "The Voynich Manuscript".[0m
[33;1m>>> Calling tool: 'wikipedia' with arguments: {'query': 'Great Barrier Reef'}[0m
[33;1m=== Agent thoughts:[0m
[0mThought: The results from the Wikipedia search show that the Great Barrier Reef is a vast and diverse ecosystem that supports a wide variety of life. However, it is also facing many threats, including climate change, pollution, and overfishing.[0m
[33;1m>>> Calling tool: 'wikipedia' with arguments: {'query': 'Dark Matter'}[0m
[33;1m=== Agent thoughts:[0m
[0mThought: The results from the Wikipedia search show that Dark Matter is a hypothetical form of matter that does not interact with light or other electromagnetic radiation, and is implied by gravitational effects that cannot be explained by general relativity.[0m
[33;1m>>> Calling tool: 'wikipedia' with arguments: {'query': 'The Voynich Manuscript'}[0m
[33;1m=== Agent thoughts:[0m
[0mThought: The results from the Wikipedia search show that the Voynich Manuscript is an illustrated codex that has been carbon-dated to the early 15th century, and its origins, authorship, and purpose are still debated.[0m
[33;1m>>> Calling tool: 'final_answer' with arguments: {'answer': "### Report on Fascinating Topics\n\n#### The Great Barrier Reef\n\nThe Great Barrier Reef is the world's largest coral reef system, composed of over 2,900 individual reefs and 900 islands stretching for over 2,300 kilometers off the coast of Queensland, Australia. It is a vast and diverse ecosystem that supports a wide variety of life, including coral and other invertebrate species, bony fish, sharks, rays, marine mammals, marine turtles, sea snakes, and algae. However, it is also facing many threats, including climate change, pollution, and overfishing.\n\n#### Dark Matter\n\nDark Matter is a hypothetical form of matter that does not interact with light or other electromagnetic radiation. It is implied by gravitational effects that cannot be explained by general relativity, and is a topic of ongoing research in astrophysics and cosmology.\n\n#### The Voynich Manuscript\n\nThe Voynich Manuscript is an illustrated codex that has been carbon-dated to the early 15th century. Its origins, authorship, and purpose are still debated, and it is considered one of the most mysterious and enigmatic manuscripts in the world.\n\n### Article Hyperlinks\n\n* [Great Barrier Reef](https://en.wikipedia.org/wiki/Great_Barrier_Reef)\n* [Dark Matter](https://en.wikipedia.org/wiki/Dark_matter)\n* [Voynich Manuscript](https://en.wikipedia.org/wiki/Voynich_manuscript)"}[0m
<IPython.core.display.Markdown object>
In [ ]:
agent = Agent(
tools=[{
"name": "hfposts",
"description": "Searches a database of technical posts on Hugging Face",
"provider": "huggingface-hub",
"container": "neuml/txtai-hfposts"
}],
llm="Qwen/Qwen3-4B-Instruct-2507",
max_iterations=10,
)In [ ]:
answer = agent("""
Read posts about medicine and write a report on what you learned.
The report should be a Markdown table with the following columns.
- Name
- Description
- Link to content
Only include rows that have a valid web url.
""", maxlength=16000)
display(Markdown(answer))[32;20;1m======== New task ========[0m
[37;1m
Read posts about medicine and write a report on what you learned.
The report should be a Markdown table with the following columns.
- Name
- Description
- Link to content
Only include rows that have a valid web url.
[0m
[33;1m=== Agent thoughts:[0m
[0mThought: First, I need to search for posts related to medicine using the `hfposts` tool.[0m
[33;1m>>> Calling tool: 'hfposts' with arguments: {'query': 'medicine'}[0m
[33;1m=== Agent thoughts:[0m
[0mThought: Now that I have the posts related to medicine, I need to filter out the ones that have a valid web URL. I will go through each post and check if it contains a URL.[0m
[33;1m>>> Calling tool: 'hfposts' with arguments: {'query': 'medicine url'}[0m
[33;1m=== Agent thoughts:[0m
[0mThought: Now that I have the posts with URLs, I need to extract the relevant information such as the name, description, and link to content. I will create a Markdown table with these details.[0m
[33;1m>>> Calling tool: 'hfposts' with arguments: {'query': 'medicine url'}[0m
[33;1m=== Agent thoughts:[0m
[0mThought: Now that I have the posts with URLs, I can extract the relevant information and create a Markdown table. I will format the data into the required structure.[0m
[33;1m>>> Calling tool: 'final_answer' with arguments: {'answer': '| Name | Description | Link to content |\n| --- | --- | --- |\n| OpenBioLLM Release | Introducing OpenBioLLM-Llama3-70B & 8B: The most capable openly available Medical-domain LLMs to date! | [https://huggingface.co/blog/aaditya/openbiollm](https://huggingface.co/blog/aaditya/openbiollm) |\n| Last Week in Medical AI: Top Research Papers/Models (September 1 - September 7, 2024) | Outperforms industry giants like GPT-4, Gemini, Meditron-70B, Med-PaLM-1, and Med-PaLM-2 in the biomedical domain. | [https://x.com/OpenlifesciAI/status/1832476252260712788](https://x.com/OpenlifesciAI/status/1832476252260712788) |\n| Last Week in Medical AI: Top Research Papers/Models (August 25 - August 31, 2024) | Includes MultiMed, a Multimodal Medical Benchmark, and A Foundation model for generating chest X-ray images. | [https://x.com/OpenlifesciAI/status/1829984701324448051](https://x.com/OpenlifesciAI/status/1829984701324448051) |\n| Last Week in Medical AI: Top Research Papers/Models (October 5 - October 12, 2024) | Introduces MMedAgent: Learning to Use Medical Tools with Multi-modal Agent. | [https://youtu.be/OD3C5jirszw](https://youtu.be/OD3C5jirszw) |\n| Last Week in Medical AI: Top Research Papers/Models (October 26 - November 2, 2024) | Google Presents MDAgents: An Adaptive Collaboration of LLMs for Medical Decision-Making. | [https://x.com/OpenlifesciAI/status/1852685220912464066](https://x.com/OpenlifesciAI/status/1852685220912464066) '}[0m
<IPython.core.display.Markdown object>
In [ ]:
from txtai import Agent, Embeddings
from txtai.pipeline import Textractor
from txtai.workflow import Workflow, Task
# Empty embeddings database
embeddings = Embeddings(
path="intfloat/e5-large",
instructions={"query": "query: ", "data": "passage: "},
content=True
)
# Textractor instance
textractor = Textractor(sections=True, headers={"user-agent": "Mozilla/5.0"})
def insert(elements):
"""
Inserts elements into the embeddings database.
Args:
elements: list of strings to insert
"""
def upsert(elements):
embeddings.upsert(elements)
return elements
# Upsert workflow
workflow = Workflow([Task(textractor), Task(upsert)])
list(workflow(elements))
return f"{elements} inserted successfully"
agent = Agent(
tools=[insert, embeddings.search, "websearch"],
llm="Qwen/Qwen3-4B-Instruct-2507",
max_iterations=10
)In [ ]:
prompt = """
Run the following process:
1. Search your internal knowledge for {topic}
2. If not found, find relevant urls and insert those as a list of strings ONLY. Then rerun the search for {topic}.
3. Write a detailed report about {topic} with Markdown sections covering the major topics. Include a section with hyperlink references.
"""
answer = agent(prompt.format(topic="txtai"))
display(Markdown(answer))[32;20;1m======== New task ========[0m
[37;1m
Run the following process:
1. Search your internal knowledge for txtai
2. If not found, find relevant urls and insert those as a list of strings ONLY. Then rerun the search for txtai.
3. Write a detailed report about txtai with Markdown sections covering the major topics. Include a section with hyperlink references.
[0m
[33;1m=== Agent thoughts:[0m
[0mThought: First, I will attempt to search for "txtai" in my internal knowledge base.[0m
[33;1m>>> Calling tool: 'search' with arguments: {'query': 'txtai'}[0m
[33;1m=== Agent thoughts:[0m
[0mThought: Since the search for "txtai" did not yield any results, I will proceed to find relevant URLs and insert them as a list of strings.[0m
[33;1m>>> Calling tool: 'web_search' with arguments: {'query': 'txtai'}[0m
[33;1m=== Agent thoughts:[0m
[0mThought: Now that I have found relevant URLs, I will insert them into the database as a list of strings.[0m
[33;1m>>> Calling tool: 'insert' with arguments: {'elements': ['https://github.com/neuml/txtai', 'https://pypi.org/project/txtai/', 'https://neuml.github.io/txtai/', 'https://neuml.com/', 'https://medium.com/neuml/introducing-txtai-the-all-in-one-embeddings-database-c721f4ff91ad', 'https://neuml.github.io/txtai/embeddings/', 'https://neuml.github.io/txtai/examples/']}[0m
[33;1m=== Agent thoughts:[0m
[0mThought: Now that the relevant URLs have been inserted, I will rerun the search for "txtai".[0m
[33;1m>>> Calling tool: 'search' with arguments: {'query': 'txtai'}[0m
[33;1m=== Agent thoughts:[0m
[33;1m>>> Calling tool: 'final_answer' with arguments: {'answer': '# txtai Overview\n\ntxtai is an all-in-one open-source embeddings database designed for semantic search, LLM orchestration, and language model workflows. It combines vector indexes (both sparse and dense), graph networks, and relational databases to offer a comprehensive solution for various tasks.\n\n## Semantic Search\n\ntxtai supports semantic search, enabling users to find relevant information based on the meaning of the text rather than just keywords. This makes it suitable for applications such as recommendation systems, content retrieval, and more.\n\n## LLM Orchestration\n\ntxtai includes support for Large Language Models (LLMs) orchestration, which allows users to integrate and manage different LLMs within their workflows. This feature is particularly useful for tasks such as prompt chaining, summarization, transcription, translation, and more.\n\n## Embeddings Databases\n\ntxtai provides a unified interface for embedding, indexing, searching, and processing text and multimedia data. Users can create, index, and search embeddings using code snippets and examples provided in the documentation.\n\n## Hyperlink References\n\n- [txtai on GitHub](https://github.com/neuml/txtai)\n- [PyPI - txtai](https://pypi.org/project/txtai/)\n- [txtai Documentation](https://neuml.github.io/txtai/)\n- [txtai Examples](https://neuml.github.io/txtai/examples/)\n- [txtai Embeddings](https://neuml.github.io/txtai/embeddings/)'}[0m
<IPython.core.display.Markdown object>
In [ ]:
answer = agent(prompt.format(topic="openscholar"))
display(Markdown(answer))[32;20;1m======== New task ========[0m
[37;1m
Run the following process:
1. Search your internal knowledge for openscholar
2. If not found, find relevant urls and insert those as a list of strings ONLY. Then rerun the search for openscholar.
3. Write a detailed report about openscholar with Markdown sections covering the major topics. Include a section with hyperlink references.
[0m
[33;1m=== Agent thoughts:[0m
[0mThought: First, I will search my internal knowledge for "openscholar".[0m
[33;1m>>> Calling tool: 'search' with arguments: {'query': 'openscholar'}[0m
[33;1m=== Agent thoughts:[0m
[0mThought: Since the search did not return any relevant information about "openscholar", I will find relevant URLs and insert them as a list of strings. Then, I will rerun the search for "openscholar".[0m
[33;1m>>> Calling tool: 'web_search' with arguments: {'query': 'openscholar'}[0m
[33;1m=== Agent thoughts:[0m
[0mThought: Now that I have found relevant URLs about "openscholar", I will insert these URLs into the database.[0m
[33;1m>>> Calling tool: 'insert' with arguments: {'elements': ['https://openscholar.allen.ai/', 'https://allenai.org/blog/openscholar', 'https://arxiv.org/abs/2411.14199', 'https://github.com/AkariAsai/OpenScholar', 'https://www.marktechpost.com/2024/11/22/the-allen-institute-for-ai-ai2-introduces-openscholar-an-open-ecosystem-for-literature-synthesis-featuring-advanced-datastores-and-expert-level-results/', 'https://venturebeat.com/ai/openscholar-the-open-source-a-i-thats-outperforming-gpt-4o-in-scientific-research/']}[0m
[33;1m=== Agent thoughts:[0m
[0mThought: Now that the relevant URLs have been inserted, I will rerun the search for "openscholar" to gather more detailed information.[0m
[33;1m>>> Calling tool: 'search' with arguments: {'query': 'openscholar'}[0m
[33;1m=== Agent thoughts:[0m
[0mThought: The search has returned relevant information about OpenScholar. I will now compile a detailed report about OpenScholar with Markdown sections covering the major topics.[0m
[33;1m>>> Calling tool: 'final_answer' with arguments: {'answer': "# OpenScholar Report\n\n## Introduction\nOpenScholar is an advanced AI system developed by the Allen Institute for AI and the University of Washington. It aims to revolutionize scientific research by processing millions of research papers and providing citation-backed answers to complex research questions.\n\n## Key Features\n- **Data Processing**: Capable of handling 45 million research papers instantly.\n- **Citation Accuracy**: Achieves high citation accuracy, challenging proprietary AI systems.\n- **Customizable Tools**: Offers specialized tools and built-in features for creating impactful websites.\n\n## Research Impact\n- **Data Utilization**: Integrates a vast corpus of scientific literature, making it the largest open-access corpus for scientific literature synthesis.\n- **Expert-Level Results**: Provides answers that match or exceed those of human experts in various scientific domains.\n\n## Future Directions\n- **Continued Development**: Ongoing efforts to improve the system's capabilities and expand its applications.\n- **Community Engagement**: Plans for expanding the user base and fostering a community around OpenScholar.\n\n## References\n- [OpenScholar](https://openscholar.allen.ai/)\n- [VentureBeat Article](https://venturebeat.com/ai/openscholar-the-open-source-a-i-thats-outperforming-gpt-4o-in-scientific-research/)\n- [Allen Institute for AI](https://allenai.org/blog/openscholar)"}[0m
<IPython.core.display.Markdown object>