From fcd324894951a0376a10a36094e813d103413d2d Mon Sep 17 00:00:00 2001 From: Sergey Gaynetdinov Date: Sun, 17 May 2026 16:02:34 +0500 Subject: [PATCH] docs/python: fix snippets and is_prime example --- 1_python/1_getting-started/project-setup.md | 8 ++++---- 1_python/1_getting-started/repl.md | 3 +-- 1_python/2_agent/act.md | 4 ++-- 1_python/2_agent/tools.md | 6 +++--- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/1_python/1_getting-started/project-setup.md b/1_python/1_getting-started/project-setup.md index 1baa661..f92f5e7 100644 --- a/1_python/1_getting-started/project-setup.md +++ b/1_python/1_getting-started/project-setup.md @@ -94,7 +94,7 @@ SERVER_API_HOST = "localhost:1234" if lms.Client.is_valid_api_host(SERVER_API_HOST): print(f"An LM Studio API server instance is available at {SERVER_API_HOST}") else: - print("No LM Studio API server instance found at {SERVER_API_HOST}") + print(f"No LM Studio API server instance found at {SERVER_API_HOST}") ``` ```python tab="Python (asynchronous API)" @@ -106,7 +106,7 @@ SERVER_API_HOST = "localhost:1234" if await lms.AsyncClient.is_valid_api_host(SERVER_API_HOST): print(f"An LM Studio API server instance is available at {SERVER_API_HOST}") else: - print("No LM Studio API server instance found at {SERVER_API_HOST}") + print(f"No LM Studio API server instance found at {SERVER_API_HOST}") ``` ### Determining the default local API server port @@ -124,7 +124,7 @@ import lmstudio as lms api_host = lms.Client.find_default_local_api_host() if api_host is not None: print(f"An LM Studio API server instance is available at {api_host}") - else: +else: print("No LM Studio API server instance found on any of the default local ports") ``` @@ -136,6 +136,6 @@ import lmstudio as lms api_host = await lms.AsyncClient.find_default_local_api_host() if api_host is not None: print(f"An LM Studio API server instance is available at {api_host}") - else: +else: print("No LM Studio API server instance found on any of the default local ports") ``` diff --git a/1_python/1_getting-started/repl.md b/1_python/1_getting-started/repl.md index f4c0fdc..b2ad49a 100644 --- a/1_python/1_getting-started/repl.md +++ b/1_python/1_getting-started/repl.md @@ -15,7 +15,7 @@ which use `with` statements to ensure deterministic cleanup of network communica resources). The convenience API allows the standard Python REPL, or more flexible alternatives like -Juypter Notebooks, to be used to interact with AI models loaded into LM Studio. For +Jupyter Notebooks, to be used to interact with AI models loaded into LM Studio. For example: ```python title="Python REPL" @@ -27,7 +27,6 @@ example: 0 LLM(identifier='qwen2.5-7b-instruct') >>> model = loaded_models[0] >>> chat = lms.Chat("You answer questions concisely") ->>> chat = lms.Chat("You answer questions concisely") >>> chat.add_user_message("Tell me three fruits") UserMessage(content=[TextData(text='Tell me three fruits')]) >>> print(model.respond(chat, on_message=chat.append)) diff --git a/1_python/2_agent/act.md b/1_python/2_agent/act.md index 24878b9..9ef0141 100644 --- a/1_python/2_agent/act.md +++ b/1_python/2_agent/act.md @@ -85,7 +85,7 @@ def is_prime(n: int) -> bool: if n < 2: return False sqrt = int(math.sqrt(n)) - for i in range(2, sqrt): + for i in range(2, sqrt + 1): if n % i == 0: return False return True @@ -116,7 +116,7 @@ def create_file(name: str, content: str): try: dest_path.write_text(content, encoding="utf-8") except Exception as exc: - return "Error: {exc!r}" + return f"Error: {exc!r}" return "File created." def print_fragment(fragment, round_index=0): diff --git a/1_python/2_agent/tools.md b/1_python/2_agent/tools.md index 70fa818..8228173 100644 --- a/1_python/2_agent/tools.md +++ b/1_python/2_agent/tools.md @@ -84,7 +84,7 @@ def create_file(name: str, content: str): try: dest_path.write_text(content, encoding="utf-8") except Exception as exc: - return "Error: {exc!r}" + return f"Error: {exc!r}" return "File created." ``` @@ -124,7 +124,7 @@ def divide(numerator: float, denominator: float) -> float: return numerator / denominator model = lms.llm("qwen2.5-7b-instruct") -chat = Chat() +chat = lms.Chat() chat.add_user_message( "Attempt to divide 1 by 0 using the tool. Explain the result." ) @@ -134,7 +134,7 @@ def _raise_exc_in_client( ) -> None: raise exc -act_result = llm.act( +act_result = model.act( chat, [divide], handle_invalid_tool_request=_raise_exc_in_client,