Skip to main content

llama-index fastapi server

Project description

LlamaIndex Server

LlamaIndexServer is a FastAPI application that allows you to quickly launch your workflow as an API server.

Installation

pip install llama-index-server

Usage

# main.py
from llama_index.core.agent.workflow import AgentWorkflow
from llama_index.core.workflow import Workflow
from llama_index.core.tools import FunctionTool
from llama_index.server import LlamaIndexServer


# Define a factory function that returns a Workflow or AgentWorkflow
def create_workflow() -> Workflow:
    def fetch_weather(city: str) -> str:
        return f"The weather in {city} is sunny"

    return AgentWorkflow.from_tools(
        tools=[
            FunctionTool.from_defaults(
                fn=fetch_weather,
            )
        ]
    )


# Create an API server the workflow
app = LlamaIndexServer(
    workflow_factory=create_workflow  # Supports Workflow or AgentWorkflow
)

Running the server

  • In the same directory as main.py, run the following command to start the server:

    fastapi dev
    
  • Making a request to the server

    curl -X POST "http://localhost:8000/api/chat" -H "Content-Type: application/json" -d '{"message": "What is the weather in Tokyo?"}'
    
  • See the API documentation at http://localhost:8000/docs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_server-0.1.5.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llama_index_server-0.1.5-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_server-0.1.5.tar.gz.

File metadata

  • Download URL: llama_index_server-0.1.5.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.11.11 Linux/6.8.0-1021-azure

File hashes

Hashes for llama_index_server-0.1.5.tar.gz
Algorithm Hash digest
SHA256 69c036ec652b901f437b2b67a81dab0c82325d22050ef76b3da8b4c49f5e9461
MD5 9f3277ce0ddbc55c04557ba4c902cb45
BLAKE2b-256 de5fcd33b42c483fd04a6639707ae5e6a471f42c2030ab5b41c5cad4b1424514

See more details on using hashes here.

File details

Details for the file llama_index_server-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: llama_index_server-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.11.11 Linux/6.8.0-1021-azure

File hashes

Hashes for llama_index_server-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1e1e5a2621e5f1ed050554f758fd7d3db41d57780df765527390fe5608962f88
MD5 04635af50197a24122e353a13920ee1f
BLAKE2b-256 ea10eb4f48d8db70057c1cf8b18ad4a51dd66ca88a743a5faf76ce10d72491ee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page