mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-12 12:06:04 +00:00
remove parsing as it's currently broken
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
This commit is contained in:
parent
5b41e0d65c
commit
21fe825090
8 changed files with 41 additions and 280 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -31,4 +31,3 @@ CLAUDE.md
|
||||||
.claude/
|
.claude/
|
||||||
docs/.docusaurus/
|
docs/.docusaurus/
|
||||||
docs/node_modules/
|
docs/node_modules/
|
||||||
docs/static/imported-files/
|
|
||||||
|
|
|
||||||
|
|
@ -13,19 +13,6 @@ npm run serve
|
||||||
```
|
```
|
||||||
You can open up the docs in your browser at http://localhost:3000
|
You can open up the docs in your browser at http://localhost:3000
|
||||||
|
|
||||||
## File Import System
|
|
||||||
|
|
||||||
This documentation uses a custom component to import files directly from the repository, eliminating copy-paste maintenance:
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
import CodeFromFile from '@site/src/components/CodeFromFile';
|
|
||||||
|
|
||||||
<CodeFromFile src="path/to/file.py" />
|
|
||||||
<CodeFromFile src="README.md" startLine={1} endLine={20} />
|
|
||||||
```
|
|
||||||
|
|
||||||
Files are automatically synced from the repo root when building. See the `CodeFromFile` component for syntax highlighting, line ranges, and multi-language support.
|
|
||||||
|
|
||||||
## Content
|
## Content
|
||||||
|
|
||||||
Try out Llama Stack's capabilities through our detailed Jupyter notebooks:
|
Try out Llama Stack's capabilities through our detailed Jupyter notebooks:
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ uploaded_file = client.files.create(file=(url, pseudo_file, "text/html"), purpos
|
||||||
client.vector_stores.files.create(vector_store_id=vs.id, file_id=uploaded_file.id)
|
client.vector_stores.files.create(vector_store_id=vs.id, file_id=uploaded_file.id)
|
||||||
|
|
||||||
resp = client.responses.create(
|
resp = client.responses.create(
|
||||||
model="gpt-4o",
|
model="openai/gpt-4o",
|
||||||
input="How do you do great work? Use the existing knowledge_search tool.",
|
input="How do you do great work? Use the existing knowledge_search tool.",
|
||||||
tools=[{"type": "file_search", "vector_store_ids": [vs.id]}],
|
tools=[{"type": "file_search", "vector_store_ids": [vs.id]}],
|
||||||
include=["file_search_call.results"],
|
include=["file_search_call.results"],
|
||||||
|
|
|
||||||
|
|
@ -32,36 +32,51 @@ OLLAMA_URL=http://localhost:11434 \
|
||||||
#### Step 3: Run the demo
|
#### Step 3: Run the demo
|
||||||
Now open up a new terminal and copy the following script into a file named `demo_script.py`.
|
Now open up a new terminal and copy the following script into a file named `demo_script.py`.
|
||||||
|
|
||||||
import CodeFromFile from '@site/src/components/CodeFromFile';
|
```python
|
||||||
|
import io, requests
|
||||||
|
from openai import OpenAI
|
||||||
|
|
||||||
|
url="https://www.paulgraham.com/greatwork.html"
|
||||||
|
client = OpenAI(base_url="http://localhost:8321/v1/", api_key="none")
|
||||||
|
|
||||||
|
vs = client.vector_stores.create()
|
||||||
|
response = requests.get(url)
|
||||||
|
pseudo_file = io.BytesIO(str(response.content).encode('utf-8'))
|
||||||
|
uploaded_file = client.files.create(file=(url, pseudo_file, "text/html"), purpose="assistants")
|
||||||
|
client.vector_stores.files.create(vector_store_id=vs.id, file_id=uploaded_file.id)
|
||||||
|
|
||||||
|
resp = client.responses.create(
|
||||||
|
model="openai/gpt-4o",
|
||||||
|
input="How do you do great work? Use the existing knowledge_search tool.",
|
||||||
|
tools=[{"type": "file_search", "vector_store_ids": [vs.id]}],
|
||||||
|
include=["file_search_call.results"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
<CodeFromFile src="docs/docs/getting_started/demo_script.py" title="demo_script.py" />
|
|
||||||
We will use `uv` to run the script
|
We will use `uv` to run the script
|
||||||
```
|
```
|
||||||
uv run --with llama-stack-client,fire,requests demo_script.py
|
uv run --with llama-stack-client,fire,requests demo_script.py
|
||||||
```
|
```
|
||||||
And you should see output like below.
|
And you should see output like below.
|
||||||
|
```python
|
||||||
|
>print(resp.output[1].content[0].text)
|
||||||
|
To do great work, consider the following principles:
|
||||||
|
|
||||||
|
1. **Follow Your Interests**: Engage in work that genuinely excites you. If you find an area intriguing, pursue it without being overly concerned about external pressures or norms. You should create things that you would want for yourself, as this often aligns with what others in your circle might want too.
|
||||||
|
|
||||||
|
2. **Work Hard on Ambitious Projects**: Ambition is vital, but it should be tempered by genuine interest. Instead of detailed planning for the future, focus on exciting projects that keep your options open. This approach, known as "staying upwind," allows for adaptability and can lead to unforeseen achievements.
|
||||||
|
|
||||||
|
3. **Choose Quality Colleagues**: Collaborating with talented colleagues can significantly affect your own work. Seek out individuals who offer surprising insights and whom you admire. The presence of good colleagues can elevate the quality of your work and inspire you.
|
||||||
|
|
||||||
|
4. **Maintain High Morale**: Your attitude towards work and life affects your performance. Cultivating optimism and viewing yourself as lucky rather than victimized can boost your productivity. It’s essential to care for your physical health as well since it directly impacts your mental faculties and morale.
|
||||||
|
|
||||||
|
5. **Be Consistent**: Great work often comes from cumulative effort. Daily progress, even in small amounts, can result in substantial achievements over time. Emphasize consistency and make the work engaging, as this reduces the perceived burden of hard labor.
|
||||||
|
|
||||||
|
6. **Embrace Curiosity**: Curiosity is a driving force that can guide you in selecting fields of interest, pushing you to explore uncharted territories. Allow it to shape your work and continually seek knowledge and insights.
|
||||||
|
|
||||||
|
By focusing on these aspects, you can create an environment conducive to great work and personal fulfillment.
|
||||||
```
|
```
|
||||||
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! 🎉🥳
|
Congratulations! You've successfully built your first RAG application using Llama Stack! 🎉🥳
|
||||||
|
|
||||||
:::tip HuggingFace access
|
:::tip HuggingFace access
|
||||||
|
|
|
||||||
|
|
@ -222,7 +222,6 @@ const config: Config = {
|
||||||
} satisfies Preset.ThemeConfig,
|
} satisfies Preset.ThemeConfig,
|
||||||
|
|
||||||
plugins: [
|
plugins: [
|
||||||
require.resolve('./plugins/file-sync-plugin'),
|
|
||||||
[
|
[
|
||||||
"docusaurus-plugin-openapi-docs",
|
"docusaurus-plugin-openapi-docs",
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"docusaurus": "docusaurus",
|
"docusaurus": "docusaurus",
|
||||||
"start": "npm run sync-files && docusaurus start",
|
"start": "docusaurus start",
|
||||||
"build": "npm run sync-files && docusaurus build",
|
"build": "docusaurus build",
|
||||||
"swizzle": "docusaurus swizzle",
|
"swizzle": "docusaurus swizzle",
|
||||||
"deploy": "docusaurus deploy",
|
"deploy": "docusaurus deploy",
|
||||||
"clear": "docusaurus clear",
|
"clear": "docusaurus clear",
|
||||||
|
|
@ -15,8 +15,7 @@
|
||||||
"gen-api-docs": "docusaurus gen-api-docs",
|
"gen-api-docs": "docusaurus gen-api-docs",
|
||||||
"clean-api-docs": "docusaurus clean-api-docs",
|
"clean-api-docs": "docusaurus clean-api-docs",
|
||||||
"gen-api-docs:version": "docusaurus gen-api-docs:version",
|
"gen-api-docs:version": "docusaurus gen-api-docs:version",
|
||||||
"clean-api-docs:version": "docusaurus clean-api-docs:version",
|
"clean-api-docs:version": "docusaurus clean-api-docs:version"
|
||||||
"sync-files": "node scripts/sync-files.js"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@docusaurus/core": "3.8.1",
|
"@docusaurus/core": "3.8.1",
|
||||||
|
|
|
||||||
|
|
@ -1,145 +0,0 @@
|
||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
// Repository root is always one level up from docs
|
|
||||||
const repoRoot = path.join(__dirname, '..', '..');
|
|
||||||
|
|
||||||
// Get all requested files from the usage tracking file
|
|
||||||
function getRequestedFiles() {
|
|
||||||
const usageFile = path.join(__dirname, '..', 'static', 'imported-files', 'usage.json');
|
|
||||||
if (!fs.existsSync(usageFile)) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const usage = JSON.parse(fs.readFileSync(usageFile, 'utf8'));
|
|
||||||
return usage.files || [];
|
|
||||||
} catch (error) {
|
|
||||||
console.warn('Could not read usage file:', error.message);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Track file usage
|
|
||||||
function trackFileUsage(filePath) {
|
|
||||||
const usageFile = path.join(__dirname, '..', 'static', 'imported-files', 'usage.json');
|
|
||||||
const usageDir = path.dirname(usageFile);
|
|
||||||
|
|
||||||
// Ensure directory exists
|
|
||||||
if (!fs.existsSync(usageDir)) {
|
|
||||||
fs.mkdirSync(usageDir, { recursive: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
let usage = { files: [] };
|
|
||||||
if (fs.existsSync(usageFile)) {
|
|
||||||
try {
|
|
||||||
usage = JSON.parse(fs.readFileSync(usageFile, 'utf8'));
|
|
||||||
} catch (error) {
|
|
||||||
console.warn('Could not read existing usage file, creating new one');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!usage.files.includes(filePath)) {
|
|
||||||
usage.files.push(filePath);
|
|
||||||
fs.writeFileSync(usageFile, JSON.stringify(usage, null, 2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter content based on file type and options
|
|
||||||
function filterContent(content, filePath) {
|
|
||||||
let lines = content.split('\n');
|
|
||||||
|
|
||||||
// Skip copyright header for Python files
|
|
||||||
if (filePath.endsWith('.py')) {
|
|
||||||
// Read the license header file
|
|
||||||
const licenseHeaderPath = path.join(repoRoot, 'docs', 'license_header.txt');
|
|
||||||
if (fs.existsSync(licenseHeaderPath)) {
|
|
||||||
try {
|
|
||||||
const licenseText = fs.readFileSync(licenseHeaderPath, 'utf8');
|
|
||||||
const licenseLines = licenseText.trim().split('\n');
|
|
||||||
|
|
||||||
// Check if file starts with the license header (accounting for # comments)
|
|
||||||
if (lines.length >= licenseLines.length) {
|
|
||||||
let matches = true;
|
|
||||||
for (let i = 0; i < licenseLines.length; i++) {
|
|
||||||
const codeLine = lines[i]?.replace(/^#\s*/, '').trim();
|
|
||||||
const licenseLine = licenseLines[i]?.trim();
|
|
||||||
if (codeLine !== licenseLine) {
|
|
||||||
matches = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (matches) {
|
|
||||||
// Skip the license header and any trailing empty lines
|
|
||||||
let skipTo = licenseLines.length;
|
|
||||||
while (skipTo < lines.length && lines[skipTo].trim() === '') {
|
|
||||||
skipTo++;
|
|
||||||
}
|
|
||||||
lines = lines.slice(skipTo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.warn(`Could not read license header, skipping filtering for ${filePath}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trim empty lines from start and end
|
|
||||||
while (lines.length > 0 && lines[0].trim() === '') {
|
|
||||||
lines.shift();
|
|
||||||
}
|
|
||||||
while (lines.length > 0 && lines[lines.length - 1].trim() === '') {
|
|
||||||
lines.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
return lines.join('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sync a file from repo root to static directory
|
|
||||||
function syncFile(filePath) {
|
|
||||||
const sourcePath = path.join(repoRoot, filePath);
|
|
||||||
const destPath = path.join(__dirname, '..', 'static', 'imported-files', filePath);
|
|
||||||
const destDir = path.dirname(destPath);
|
|
||||||
|
|
||||||
// Ensure destination directory exists
|
|
||||||
if (!fs.existsSync(destDir)) {
|
|
||||||
fs.mkdirSync(destDir, { recursive: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (fs.existsSync(sourcePath)) {
|
|
||||||
const content = fs.readFileSync(sourcePath, 'utf8');
|
|
||||||
const filteredContent = filterContent(content, filePath);
|
|
||||||
fs.writeFileSync(destPath, filteredContent);
|
|
||||||
console.log(`✅ Synced ${filePath}`);
|
|
||||||
trackFileUsage(filePath);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
console.warn(`⚠️ Source file not found: ${sourcePath}`);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`❌ Error syncing ${filePath}:`, error.message);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main execution
|
|
||||||
console.log(`📁 Repository root: ${path.resolve(repoRoot)}`);
|
|
||||||
|
|
||||||
// Get files that are being requested by the documentation
|
|
||||||
const requestedFiles = getRequestedFiles();
|
|
||||||
console.log(`📄 Syncing ${requestedFiles.length} requested files...`);
|
|
||||||
|
|
||||||
if (requestedFiles.length === 0) {
|
|
||||||
console.log('ℹ️ No files requested yet. Files will be synced when first referenced in documentation.');
|
|
||||||
} else {
|
|
||||||
requestedFiles.forEach(filePath => {
|
|
||||||
syncFile(filePath);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('✅ File sync complete!');
|
|
||||||
|
|
@ -1,93 +0,0 @@
|
||||||
import React, { useState, useEffect } from 'react';
|
|
||||||
import CodeBlock from '@theme/CodeBlock';
|
|
||||||
|
|
||||||
export default function CodeFromFile({
|
|
||||||
src,
|
|
||||||
language = 'python',
|
|
||||||
title,
|
|
||||||
startLine,
|
|
||||||
endLine,
|
|
||||||
highlightLines
|
|
||||||
}) {
|
|
||||||
const [content, setContent] = useState('');
|
|
||||||
const [error, setError] = useState(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
async function loadFile() {
|
|
||||||
try {
|
|
||||||
// File registration is now handled by the file-sync-plugin during build
|
|
||||||
|
|
||||||
// Load file from static/imported-files directory
|
|
||||||
const response = await fetch(`/imported-files/${src}`);
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Failed to fetch: ${response.status}`);
|
|
||||||
}
|
|
||||||
let text = await response.text();
|
|
||||||
|
|
||||||
// Handle line range if specified (filtering is done at build time)
|
|
||||||
if (startLine || endLine) {
|
|
||||||
const lines = text.split('\n');
|
|
||||||
const start = startLine ? Math.max(0, startLine - 1) : 0;
|
|
||||||
const end = endLine ? Math.min(lines.length, endLine) : lines.length;
|
|
||||||
text = lines.slice(start, end).join('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
setContent(text);
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Failed to load file:', err);
|
|
||||||
setError(`Failed to load ${src}: ${err.message}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
loadFile();
|
|
||||||
}, [src, startLine, endLine]);
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
return <div style={{ color: 'red', padding: '1rem', border: '1px solid red', borderRadius: '4px' }}>
|
|
||||||
Error: {error}
|
|
||||||
</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!content) {
|
|
||||||
return <div>Loading {src}...</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Auto-detect language from file extension if not provided
|
|
||||||
const detectedLanguage = language || getLanguageFromExtension(src);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<CodeBlock
|
|
||||||
language={detectedLanguage}
|
|
||||||
title={title || src}
|
|
||||||
metastring={highlightLines ? `{${highlightLines}}` : undefined}
|
|
||||||
>
|
|
||||||
{content}
|
|
||||||
</CodeBlock>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getLanguageFromExtension(filename) {
|
|
||||||
const ext = filename.split('.').pop();
|
|
||||||
const languageMap = {
|
|
||||||
'py': 'python',
|
|
||||||
'js': 'javascript',
|
|
||||||
'jsx': 'jsx',
|
|
||||||
'ts': 'typescript',
|
|
||||||
'tsx': 'tsx',
|
|
||||||
'md': 'markdown',
|
|
||||||
'sh': 'bash',
|
|
||||||
'yaml': 'yaml',
|
|
||||||
'yml': 'yaml',
|
|
||||||
'json': 'json',
|
|
||||||
'css': 'css',
|
|
||||||
'html': 'html',
|
|
||||||
'cpp': 'cpp',
|
|
||||||
'c': 'c',
|
|
||||||
'java': 'java',
|
|
||||||
'go': 'go',
|
|
||||||
'rs': 'rust',
|
|
||||||
'php': 'php',
|
|
||||||
'rb': 'ruby',
|
|
||||||
};
|
|
||||||
return languageMap[ext] || 'text';
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue