Skip to content

Commit

Permalink
chore: move all Llama Stack types from llama-models to llama-stack (m…
Browse files Browse the repository at this point in the history
…eta-llama#1098)

llama-models should have extremely minimal cruft. Its sole purpose
should be didactic -- show the simplest implementation of the llama
models and document the prompt formats, etc.

This PR is the complement to
meta-llama/llama-models#279

## Test Plan

Ensure all `llama` CLI `model` sub-commands work:

```bash
llama model list
llama model download --model-id ...
llama model prompt-format -m ...
```

Ran tests:
```bash
cd tests/client-sdk
LLAMA_STACK_CONFIG=fireworks pytest -s -v inference/
LLAMA_STACK_CONFIG=fireworks pytest -s -v vector_io/
LLAMA_STACK_CONFIG=fireworks pytest -s -v agents/
```

Create a fresh venv `uv venv && source .venv/bin/activate` and run
`llama stack build --template fireworks --image-type venv` followed by
`llama stack run together --image-type venv` <-- the server runs

Also checked that the OpenAPI generator can run and there is no change
in the generated files as a result.

```bash
cd docs/openapi_generator
sh run_openapi_generator.sh
```
  • Loading branch information
ashwinb authored and srikanthbachala20 committed Feb 27, 2025
1 parent 2c24566 commit 15d4604
Show file tree
Hide file tree
Showing 138 changed files with 8,491 additions and 465 deletions.
9 changes: 8 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ repos:
rev: v0.9.4
hooks:
- id: ruff
exclude: ^llama_stack/strong_typing/.*$
- id: ruff-format

- repo: https://github.com/adamchainz/blacken-docs
Expand All @@ -43,7 +44,13 @@ repos:
rev: 0.5.26
hooks:
- id: uv-export
args: ["--frozen", "--no-hashes", "--no-emit-project"]
args: [
"--frozen",
"--no-hashes",
"--no-emit-project",
"--output-file=requirements.txt"
]
files: ^pyproject\.toml$
- id: uv-sync

# - repo: https://github.com/pre-commit/mirrors-mypy
Expand Down
12 changes: 0 additions & 12 deletions docs/openapi_generator/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@
import fire
import ruamel.yaml as yaml

from llama_models import schema_utils

# We do some monkey-patching to ensure our definitions only use the minimal
# (json_schema_type, webmethod) definitions from the llama_models package. For
# generation though, we need the full definitions and implementations from the
# (json-strong-typing) package.

from .strong_typing.schema import json_schema_type, register_schema

schema_utils.json_schema_type = json_schema_type
schema_utils.register_schema = register_schema

from llama_stack.apis.version import LLAMA_STACK_API_VERSION # noqa: E402
from llama_stack.distribution.stack import LlamaStack # noqa: E402

Expand Down
12 changes: 6 additions & 6 deletions docs/openapi_generator/pyopenapi/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@
from dataclasses import make_dataclass
from typing import Any, Dict, Set, Union

from ..strong_typing.core import JsonType
from ..strong_typing.docstring import Docstring, parse_type
from ..strong_typing.inspection import (
from llama_stack.strong_typing.core import JsonType
from llama_stack.strong_typing.docstring import Docstring, parse_type
from llama_stack.strong_typing.inspection import (
is_generic_list,
is_type_optional,
is_type_union,
unwrap_generic_list,
unwrap_optional_type,
unwrap_union_types,
)
from ..strong_typing.name import python_type_to_name
from ..strong_typing.schema import (
from llama_stack.strong_typing.name import python_type_to_name
from llama_stack.strong_typing.schema import (
get_schema_identifier,
JsonSchemaGenerator,
register_schema,
Schema,
SchemaOptions,
)
from ..strong_typing.serialization import json_dump_string, object_to_json
from llama_stack.strong_typing.serialization import json_dump_string, object_to_json

from .operations import (
EndpointOperation,
Expand Down
2 changes: 1 addition & 1 deletion docs/openapi_generator/pyopenapi/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from termcolor import colored

from ..strong_typing.inspection import get_signature
from llama_stack.strong_typing.inspection import get_signature


def split_prefix(
Expand Down
2 changes: 1 addition & 1 deletion docs/openapi_generator/pyopenapi/specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from dataclasses import dataclass
from typing import Any, ClassVar, Dict, List, Optional, Union

from ..strong_typing.schema import JsonType, Schema, StrictJsonType
from llama_stack.strong_typing.schema import JsonType, Schema, StrictJsonType

URL = str

Expand Down
2 changes: 1 addition & 1 deletion docs/openapi_generator/pyopenapi/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pathlib import Path
from typing import TextIO

from ..strong_typing.schema import object_to_json, StrictJsonType
from llama_stack.strong_typing.schema import object_to_json, StrictJsonType

from .generator import Generator
from .options import Options
Expand Down
2 changes: 1 addition & 1 deletion llama_stack/apis/agents/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
runtime_checkable,
)

from llama_models.schema_utils import json_schema_type, register_schema, webmethod
from pydantic import BaseModel, ConfigDict, Field

from llama_stack.apis.common.content_types import URL, ContentDelta, InterleavedContent
Expand All @@ -38,6 +37,7 @@
from llama_stack.apis.safety import SafetyViolation
from llama_stack.apis.tools import ToolDef
from llama_stack.providers.utils.telemetry.trace_protocol import trace_protocol
from llama_stack.schema_utils import json_schema_type, register_schema, webmethod


class Attachment(BaseModel):
Expand Down
206 changes: 0 additions & 206 deletions llama_stack/apis/agents/event_logger.py

This file was deleted.

2 changes: 1 addition & 1 deletion llama_stack/apis/batch_inference/batch_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from typing import List, Optional, Protocol, runtime_checkable

from llama_models.schema_utils import json_schema_type, webmethod
from pydantic import BaseModel

from llama_stack.apis.inference import (
Expand All @@ -21,6 +20,7 @@
ToolDefinition,
ToolPromptFormat,
)
from llama_stack.schema_utils import json_schema_type, webmethod


@json_schema_type
Expand Down
2 changes: 1 addition & 1 deletion llama_stack/apis/benchmarks/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
# the root directory of this source tree.
from typing import Any, Dict, List, Literal, Optional, Protocol, runtime_checkable

from llama_models.schema_utils import json_schema_type, webmethod
from pydantic import BaseModel, Field

from llama_stack.apis.resource import Resource, ResourceType
from llama_stack.schema_utils import json_schema_type, webmethod


class CommonBenchmarkFields(BaseModel):
Expand Down
5 changes: 3 additions & 2 deletions llama_stack/apis/common/content_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
from enum import Enum
from typing import Annotated, List, Literal, Optional, Union

from llama_models.llama3.api.datatypes import ToolCall
from llama_models.schema_utils import json_schema_type, register_schema
from pydantic import BaseModel, Field, model_validator

from llama_stack.models.llama.datatypes import ToolCall
from llama_stack.schema_utils import json_schema_type, register_schema


@json_schema_type
class URL(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion llama_stack/apis/common/deployment_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from enum import Enum
from typing import Any, Dict, Optional

from llama_models.schema_utils import json_schema_type
from pydantic import BaseModel

from llama_stack.apis.common.content_types import URL
from llama_stack.schema_utils import json_schema_type


@json_schema_type
Expand Down
3 changes: 2 additions & 1 deletion llama_stack/apis/common/job_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
# the root directory of this source tree.
from enum import Enum

from llama_models.schema_utils import json_schema_type
from pydantic import BaseModel

from llama_stack.schema_utils import json_schema_type


@json_schema_type
class Job(BaseModel):
Expand Down
Loading

0 comments on commit 15d4604

Please sign in to comment.