Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "sdk-schema/lmstudio.js"]
path = sdk-schema/lmstudio.js
url = https://github.com/lmstudio-ai/lmstudio.js.git
[submodule "sdk-schema/lmstudio-js"]
path = sdk-schema/lmstudio-js
url = https://github.com/lmstudio-ai/lmstudio-js.git
14 changes: 7 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ First off, thank you for considering contributing to our open source projects!

`lmstudio-python` is the Python SDK for LM Studio. It is an open-source project under the MIT license. We welcome community contributions.

There are many ways to help, from writing tutorials or blog posts, improving the documentation, submitting bug reports and feature requests or contributing code which can be incorporated into the SDK itself.
There are many ways to help, from writing tutorials or blog posts, submitting bug reports and feature requests or contributing code which can be incorporated into the SDK itself.

Note: the SDK documentation is currently maintained in combination with the [`lmstudio-js`](https://github.com/lmstudio-ai/lmstudio-js) documentation in a private repository.

Note: the SDK documentation is maintained in combination with the [`lmstudio.js`](https://github.com/lmstudio-ai/lmstudio.js)
in a dedicated [documentation repo](https://github.com/lmstudio-ai/docs).

## Communication

Expand Down Expand Up @@ -75,11 +75,11 @@ on working with the `lmstudio-python` code and test suite.

`lmstudio-python` communicates with LM Studio through its native dedicated websocket API, rather than via its Open AI compatibility layer.

- **How does `lmstudio-python` relate to `lmstudio.js`?**
- **How does `lmstudio-python` relate to `lmstudio-js`?**

`lmstudio-python` communicates with LM Studio based on JSON interface types defined in `lmstudio.js`.
The `lmstudio-python` repository includes `lmstudio.js` as a submodule in order to support generating
the Python API interface classes from the JSON schema definitions exported by `lmstudio.js`.
`lmstudio-python` communicates with LM Studio based on JSON interface types defined in `lmstudio-js`.
The `lmstudio-python` repository includes `lmstudio-js` as a submodule in order to support generating
the Python API interface classes from the JSON schema definitions exported by `lmstudio-js`.

## Questions

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ $ cd lmstudio-python
```

To be able to run `tox -e sync-sdk-schema`, it is also
necessary to ensure the `lmstudio.js` submodule is updated:
necessary to ensure the `lmstudio-js` submodule is updated:

```console
$ git submodule update --init --recursive
Expand Down Expand Up @@ -193,10 +193,10 @@ Additional notes on running and updating the tests can be found in the
- the content of `src/lmstudio/_sdk_models` is automatically generated by the
`sync-sdk-schema.py` script in `sdk-schema` and should not be modified directly.
Run `tox -e sync-sdk-schema` to regenerate the Python submodule from the existing
export of the `lmstudio.js` schema (for example, after modifying the data model
export of the `lmstudio-js` schema (for example, after modifying the data model
template). Run `tox -e sync-sdk-schema -- --regen-schema` after updating the
`sdk-schema/lmstudio.js` submodule itself to a newer iteration of the
`lmstudio.js` JSON API.
`sdk-schema/lmstudio-js` submodule itself to a newer iteration of the
`lmstudio-js` JSON API.
- as support for new API namespaces is added to the SDK, each should get a dedicated
session type (similar to those for the already supported namespaces), even if it
is only used privately by the client implementation.
Expand Down
4 changes: 2 additions & 2 deletions sdk-schema/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
lmstudio.js JSON Schema export
lmstudio-js JSON Schema export
==============================

`tox -e sync-sdk-schema` runs `sync-sdk-schema.py` in
a suitably configured Python environment.

The generated models are written to `../src/lmstudio.js/_sdk_models/*.py`.
The generated models are written to `../src/lmstudio/_sdk_models/*.py`.
1 change: 1 addition & 0 deletions sdk-schema/lmstudio-js
Submodule lmstudio-js added at 12af43
1 change: 0 additions & 1 deletion sdk-schema/lmstudio.js
Submodule lmstudio.js deleted from 0a90e9
18 changes: 9 additions & 9 deletions sdk-schema/sync-sdk-schema.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
"""Generate Python data model classes from lmstudio.js zod schema.
"""Generate Python data model classes from lmstudio-js zod schema.

Recreates the Python data model classes from the exported JSON schema
(generating the JSON schema only if necessary).
Expand All @@ -13,9 +13,9 @@


# * invokes `npm run build` and `npm run make-schemas` in the
# `lmstudio.js` submodule's `packages/lms-json-schema` project
# `lmstudio-js` submodule's `packages/lms-json-schema` project
# to create JSON schema files in
# `./lmstudio.js/packages/lms-json-schema/schemas/lms.json`
# `./lmstudio-js/packages/lms-json-schema/schemas/lms.json`
# * uses `datamodel-code-generator` to produce Python data model
# classes from the exported JSON schema files

Expand All @@ -41,7 +41,7 @@
)

_THIS_DIR = Path(__file__).parent
_LMSJS_DIR = _THIS_DIR / "lmstudio.js"
_LMSJS_DIR = _THIS_DIR / "lmstudio-js"
_EXPORTER_DIR = _LMSJS_DIR / "packages/lms-json-schema"
_SCHEMA_DIR = _EXPORTER_DIR / "schemas"
_SCHEMA_PATH = _SCHEMA_DIR / "lms.json"
Expand All @@ -64,15 +64,15 @@

# TODO:
# * Figure out a way to avoid the full clean-and-build
# cycle when regenerating the lmstudio.js JSON schemas
# cycle when regenerating the lmstudio-js JSON schemas
#
# * Potentially include models for the websocket channel,
# rpc, and signal message formats:
# https://github.com/lmstudio-ai/lmstudio.js/blob/main/packages/lms-communication/src/Transport.ts
# https://github.com/lmstudio-ai/lmstudio-js/blob/main/packages/lms-communication/src/Transport.ts


def _export_zod_schemas_to_json_schema() -> None:
"""Run the lmstudio.js JSON schema export in the submodule."""
"""Run the lmstudio-js JSON schema export in the submodule."""
_SCHEMA_PATH.unlink(missing_ok=True)
_CACHED_SCHEMA_PATH.unlink(missing_ok=True)
with chdir(_LMSJS_DIR):
Expand Down Expand Up @@ -123,7 +123,7 @@ def _check_discriminator(tag_field: str, union_array: _SchemaList) -> bool:
# Can only be a discriminated union on this tag if all variants have it
return False
if field_def["type"] != "string":
# Only string based unions are defined in lmstudio.js
# Only string based unions are defined in lmstudio-js
return False
tag_value = field_def.get("const", None)
if tag_value is None:
Expand Down Expand Up @@ -251,7 +251,7 @@ def _extract_union_variants(
def _is_void_union(union_members: _SchemaList) -> _SchemaObject | None:
if len(union_members) != 2:
return None
# Note: the "void spec" definition is actually an error in the lmstudio.js
# Note: the "void spec" definition is actually an error in the lmstudio-js
# schema exporter, since it is defined as meaning "may be anything" in JSON
# schema, but the exporter is wanting to specify "may be omitted entirely".
# That "may be omitted" aspect would be specified by declaring the "result"
Expand Down
6 changes: 3 additions & 3 deletions src/lmstudio/_kv_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Conversion between dicts/public config structs and server KVConfig(Stack)s."""

# Known KV config settings are defined in
# https://github.com/lmstudio-ai/lmstudio.js/blob/main/packages/lms-kv-config/src/schema.ts
# https://github.com/lmstudio-ai/lmstudio-js/blob/main/packages/lms-kv-config/src/schema.ts
from typing import Any, Sequence, Type, TypeVar

from .sdk_api import LMStudioValueError
Expand All @@ -19,7 +19,7 @@
LlmPredictionConfigDict,
)

# TODO we can reasonably add unit tests for this module: compare against lmstudio.js?
# TODO we can reasonably add unit tests for this module: compare against lmstudio-js?


TLoadConfig = TypeVar("TLoadConfig", LlmLoadModelConfig, EmbeddingLoadModelConfig)
Expand Down Expand Up @@ -113,7 +113,7 @@ def _to_kv_config_stack_base(
fields: list[KvConfigFieldDict] = []
# TODO: Define a JSON or TOML data file for mapping prediction config
# fields to config stack entries (preferably JSON exported by
# lmstudio.js rather than something maintained in the Python SDK)
# lmstudio-js rather than something maintained in the Python SDK)

for client_key in checkbox_keys:
if client_key in config:
Expand Down
10 changes: 5 additions & 5 deletions src/lmstudio/_sdk_models/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
lmstudio.js Pydantic Models
===========================
lmstudio-js SDK Data Model
==========================

The Pydantic model files in this folder are generated from the
lmstudio.js zod schema files rather than being maintained directly.
The Python data model class definitions in this folder are generated from
the lmstudio-js zod schema files rather than being maintained directly.

These files should NOT be modified: if the messaging protocol details
change, updates should be made in lmstudio.js first, and then exported
change, updates should be made in lmstudio-js first, and then exported
to the Python SDK via the automated code generation.

See the `sdk-schema` exporter folder for additional details.
2 changes: 1 addition & 1 deletion src/lmstudio/_sdk_models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: lms-with-inferred-unions.json
# timestamp: 2025-02-26T14:13:24+00:00
# timestamp: 2025-02-27T03:57:00+00:00

from __future__ import annotations

Expand Down
Loading