chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1 @@
|
||||
__pycache__
|
||||
@@ -0,0 +1,19 @@
|
||||
# Llama Index Agent Starter: Python
|
||||
|
||||
This package is a quick starter example for building AG-UI agents with Llama Index and CopilotKit.
|
||||
|
||||
## Running the Backend
|
||||
|
||||
```bash
|
||||
export OPENAI_API_KEY=...
|
||||
uv sync
|
||||
uv run dev
|
||||
```
|
||||
|
||||
## Running the Frontend
|
||||
|
||||
```bash
|
||||
cd ..
|
||||
npm install
|
||||
npm run dev
|
||||
```
|
||||
@@ -0,0 +1,24 @@
|
||||
import uvicorn
|
||||
from dotenv import load_dotenv
|
||||
from fastapi import FastAPI
|
||||
|
||||
from src.agent import agentic_chat_router
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
async def health():
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
app.include_router(agentic_chat_router)
|
||||
|
||||
|
||||
def main():
|
||||
load_dotenv()
|
||||
uvicorn.run("main:app", host="127.0.0.1", port=9000, reload=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,29 @@
|
||||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "agent"
|
||||
version = "0.1.0"
|
||||
description = "Add your description here"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.9, <3.14"
|
||||
dependencies = [
|
||||
"llama-index-core>=0.14,<0.15",
|
||||
"llama-index-llms-openai>=0.5.0,<0.6.0",
|
||||
"llama-index-protocols-ag-ui>=0.2.2",
|
||||
"jsonpatch>=1.33",
|
||||
"uvicorn>=0.27.0",
|
||||
"fastapi>=0.100.0",
|
||||
"python-dotenv>=1.0.0",
|
||||
]
|
||||
authors = [{ name = "Logan Markewich", email = "logan@runllama.ai" }]
|
||||
|
||||
[tool.hatch.build.targets.sdist]
|
||||
include = ["main.py", "src/"]
|
||||
|
||||
[tool.hatch.build.targets.wheel]
|
||||
include = ["main.py", "src/"]
|
||||
|
||||
[project.scripts]
|
||||
dev = "main:main"
|
||||
@@ -0,0 +1,48 @@
|
||||
from typing import Annotated
|
||||
|
||||
from llama_index.core.workflow import Context
|
||||
from llama_index.llms.openai import OpenAI
|
||||
from llama_index.protocols.ag_ui.events import StateSnapshotWorkflowEvent
|
||||
from llama_index.protocols.ag_ui.router import get_ag_ui_workflow_router
|
||||
|
||||
|
||||
# This tool has a client-side version that is actually called to change the background
|
||||
# These tools just need a response string to make it look like they are executing
|
||||
def change_theme_color(
|
||||
theme_color: Annotated[str, "The hex color value. i.e. '#123456''"],
|
||||
) -> str:
|
||||
"""Change the background color of the chat. Can be any hex color value."""
|
||||
return f"Changing background to {theme_color}"
|
||||
|
||||
|
||||
# This is another client-side tool that is actually called to add a proverb to the list
|
||||
# These tools just need a response string to make it look like they are executing
|
||||
async def add_proverb(
|
||||
proverb: Annotated[str, "The proverb to add. Make it witty, short and concise."],
|
||||
) -> str:
|
||||
"""Add a proverb to the list of proverbs."""
|
||||
return f"Added proverb: {proverb}"
|
||||
|
||||
|
||||
# This is a backend tool that executes code on the backend server
|
||||
# For now this is a dummy implementation, but it could very well call a weather API
|
||||
async def get_weather(
|
||||
location: Annotated[str, "The location to get the weather for."],
|
||||
) -> str:
|
||||
"""Get the weather for a given location."""
|
||||
return f"The weather in {location} is sunny and 70 degrees."
|
||||
|
||||
|
||||
agentic_chat_router = get_ag_ui_workflow_router(
|
||||
llm=OpenAI(model="gpt-4.1"),
|
||||
# Tools that are executed in the frontend client
|
||||
frontend_tools=[change_theme_color, add_proverb],
|
||||
# Tools that are executed in the backend server
|
||||
backend_tools=[get_weather],
|
||||
system_prompt="You are a helpful assistant that can add proverbs to a list, get the weather for a given location, and change the background color of the chat/app background.",
|
||||
initial_state={
|
||||
"proverbs": [
|
||||
"CopilotKit may be new, but its the best thing since sliced bread.",
|
||||
],
|
||||
},
|
||||
)
|
||||
+2255
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user