mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-10-03 19:57:35 +00:00
# What does this PR do? <!-- Provide a short summary of what this PR does and why. Link to relevant issues if applicable. --> <!-- If resolving an issue, uncomment and update the line below --> <!-- Closes #[issue-number] --> - Fixes broken links and Docusaurus search Closes #3518 ## Test Plan The following should produce a clean build with no warnings and search enabled: ``` npm install npm run gen-api-docs all npm run build npm run serve ``` <!-- Describe the tests you ran to verify your changes with result summaries. *Provide clear instructions so the plan can be easily re-executed.* -->
149 lines
7 KiB
Text
149 lines
7 KiB
Text
---
|
|
description: environments.
|
|
sidebar_label: Quickstart
|
|
sidebar_position: 1
|
|
title: Quickstart
|
|
---
|
|
|
|
Get started with Llama Stack in minutes!
|
|
|
|
Llama Stack is a stateful service with REST APIs to support the seamless transition of AI applications across different
|
|
environments. You can build and test using a local server first and deploy to a hosted endpoint for production.
|
|
|
|
In this guide, we'll walk through how to build a RAG application locally using Llama Stack with [Ollama](https://ollama.com/)
|
|
as the inference [provider](/docs/providers/inference) for a Llama Model.
|
|
|
|
**💡 Notebook Version:** You can also follow this quickstart guide in a Jupyter notebook format: [quick_start.ipynb](https://github.com/meta-llama/llama-stack/blob/main/docs/quick_start.ipynb)
|
|
|
|
#### Step 1: Install and setup
|
|
1. Install [uv](https://docs.astral.sh/uv/)
|
|
2. Run inference on a Llama model with [Ollama](https://ollama.com/download)
|
|
```bash
|
|
ollama run llama3.2:3b --keepalive 60m
|
|
```
|
|
|
|
#### Step 2: Run the Llama Stack server
|
|
|
|
We will use `uv` to run the Llama Stack server.
|
|
```bash
|
|
OLLAMA_URL=http://localhost:11434 \
|
|
uv run --with llama-stack llama stack build --distro starter --image-type venv --run
|
|
```
|
|
#### Step 3: Run the demo
|
|
Now open up a new terminal and copy the following script into a file named `demo_script.py`.
|
|
|
|
```python title="demo_script.py"
|
|
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
# All rights reserved.
|
|
#
|
|
# This source code is licensed under the terms described in the LICENSE file in
|
|
# the root directory of this source tree.
|
|
|
|
from llama_stack_client import Agent, AgentEventLogger, RAGDocument, LlamaStackClient
|
|
|
|
vector_db_id = "my_demo_vector_db"
|
|
client = LlamaStackClient(base_url="http://localhost:8321")
|
|
|
|
models = client.models.list()
|
|
|
|
# Select the first LLM and first embedding models
|
|
model_id = next(m for m in models if m.model_type == "llm").identifier
|
|
embedding_model_id = (
|
|
em := next(m for m in models if m.model_type == "embedding")
|
|
).identifier
|
|
embedding_dimension = em.metadata["embedding_dimension"]
|
|
|
|
vector_db = client.vector_dbs.register(
|
|
vector_db_id=vector_db_id,
|
|
embedding_model=embedding_model_id,
|
|
embedding_dimension=embedding_dimension,
|
|
provider_id="faiss",
|
|
)
|
|
vector_db_id = vector_db.identifier
|
|
source = "https://www.paulgraham.com/greatwork.html"
|
|
print("rag_tool> Ingesting document:", source)
|
|
document = RAGDocument(
|
|
document_id="document_1",
|
|
content=source,
|
|
mime_type="text/html",
|
|
metadata={},
|
|
)
|
|
client.tool_runtime.rag_tool.insert(
|
|
documents=[document],
|
|
vector_db_id=vector_db_id,
|
|
chunk_size_in_tokens=100,
|
|
)
|
|
agent = Agent(
|
|
client,
|
|
model=model_id,
|
|
instructions="You are a helpful assistant",
|
|
tools=[
|
|
{
|
|
"name": "builtin::rag/knowledge_search",
|
|
"args": {"vector_db_ids": [vector_db_id]},
|
|
}
|
|
],
|
|
)
|
|
|
|
prompt = "How do you do great work?"
|
|
print("prompt>", prompt)
|
|
|
|
use_stream = True
|
|
response = agent.create_turn(
|
|
messages=[{"role": "user", "content": prompt}],
|
|
session_id=agent.create_session("rag_session"),
|
|
stream=use_stream,
|
|
)
|
|
|
|
# Only call `AgentEventLogger().log(response)` for streaming responses.
|
|
if use_stream:
|
|
for log in AgentEventLogger().log(response):
|
|
log.print()
|
|
else:
|
|
print(response)
|
|
```
|
|
We will use `uv` to run the script
|
|
```
|
|
uv run --with llama-stack-client,fire,requests demo_script.py
|
|
```
|
|
And you should see output like below.
|
|
```
|
|
rag_tool> Ingesting document: https://www.paulgraham.com/greatwork.html
|
|
|
|
prompt> How do you do great work?
|
|
|
|
inference> [knowledge_search(query="What is the key to doing great work")]
|
|
|
|
tool_execution> Tool:knowledge_search Args:{'query': 'What is the key to doing great work'}
|
|
|
|
tool_execution> Tool:knowledge_search Response:[TextContentItem(text='knowledge_search tool found 5 chunks:\nBEGIN of knowledge_search tool results.\n', type='text'), TextContentItem(text="Result 1:\nDocument_id:docum\nContent: work. Doing great work means doing something important\nso well that you expand people's ideas of what's possible. But\nthere's no threshold for importance. It's a matter of degree, and\noften hard to judge at the time anyway.\n", type='text'), TextContentItem(text="Result 2:\nDocument_id:docum\nContent: work. Doing great work means doing something important\nso well that you expand people's ideas of what's possible. But\nthere's no threshold for importance. It's a matter of degree, and\noften hard to judge at the time anyway.\n", type='text'), TextContentItem(text="Result 3:\nDocument_id:docum\nContent: work. Doing great work means doing something important\nso well that you expand people's ideas of what's possible. But\nthere's no threshold for importance. It's a matter of degree, and\noften hard to judge at the time anyway.\n", type='text'), TextContentItem(text="Result 4:\nDocument_id:docum\nContent: work. Doing great work means doing something important\nso well that you expand people's ideas of what's possible. But\nthere's no threshold for importance. It's a matter of degree, and\noften hard to judge at the time anyway.\n", type='text'), TextContentItem(text="Result 5:\nDocument_id:docum\nContent: work. Doing great work means doing something important\nso well that you expand people's ideas of what's possible. But\nthere's no threshold for importance. It's a matter of degree, and\noften hard to judge at the time anyway.\n", type='text'), TextContentItem(text='END of knowledge_search tool results.\n', type='text')]
|
|
|
|
inference> Based on the search results, it seems that doing great work means doing something important so well that you expand people's ideas of what's possible. However, there is no clear threshold for importance, and it can be difficult to judge at the time.
|
|
|
|
To further clarify, I would suggest that doing great work involves:
|
|
|
|
* Completing tasks with high quality and attention to detail
|
|
* Expanding on existing knowledge or ideas
|
|
* Making a positive impact on others through your work
|
|
* Striving for excellence and continuous improvement
|
|
|
|
Ultimately, great work is about making a meaningful contribution and leaving a lasting impression.
|
|
```
|
|
Congratulations! You've successfully built your first RAG application using Llama Stack! 🎉🥳
|
|
|
|
:::tip HuggingFace access
|
|
|
|
If you are getting a **401 Client Error** from HuggingFace for the **all-MiniLM-L6-v2** model, try setting **HF_TOKEN** to a valid HuggingFace token in your environment
|
|
|
|
:::
|
|
|
|
### Next Steps
|
|
|
|
Now you're ready to dive deeper into Llama Stack!
|
|
- Explore the [Detailed Tutorial](./detailed_tutorial).
|
|
- Try the [Getting Started Notebook](https://github.com/meta-llama/llama-stack/blob/main/docs/getting_started.ipynb).
|
|
- Browse more [Notebooks on GitHub](https://github.com/meta-llama/llama-stack/tree/main/docs/notebooks).
|
|
- Learn about Llama Stack [Concepts](/docs/concepts).
|
|
- Discover how to [Build Llama Stacks](/docs/distributions).
|
|
- Refer to our [References](/docs/references) for details on the Llama CLI and Python SDK.
|
|
- Check out the [llama-stack-apps](https://github.com/meta-llama/llama-stack-apps/tree/main/examples) repository for example applications and tutorials.
|