Skip to content

Instantly share code, notes, and snippets.

@btbytes
Created March 5, 2026 02:46
Show Gist options
  • Select an option

  • Save btbytes/68066665353c3023067a76da9b8bd35c to your computer and use it in GitHub Desktop.

Select an option

Save btbytes/68066665353c3023067a76da9b8bd35c to your computer and use it in GitHub Desktop.
Local LMStudio Test
import logging
import requests
from datetime import datetime
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
logger = logging.getLogger(__name__)
url = "http://localhost:1234/v1/chat/completions"
payload = {
"model": "local-model",
"messages": [
{
"role": "user",
"content": "Write a simple Python program that prints 'Hello, World!'",
}
],
"temperature": 0.7,
}
logger.info("Preparing request to LM Studio at %s", url)
logger.info(
"Payload: model=%s, temperature=%s", payload["model"], payload["temperature"]
)
response = requests.post(url, json=payload)
logger.info("Received response with status code: %s", response.status_code)
result = response.json()
logger.info("Response parsed successfully, got %d choice(s)", len(result["choices"]))
content = result["choices"][0]["message"]["content"]
logger.info("Extracted content, length: %d characters", len(content))
print(content)
logger.info("Completed successfully")
python lmstudio_writer.py
2026-03-04 21:33:04 - INFO - Preparing request to LM Studio at http://localhost:1234/v1/chat/completions
2026-03-04 21:33:04 - INFO - Payload: model=local-model, temperature=0.7
2026-03-04 21:33:18 - INFO - Received response with status code: 200
2026-03-04 21:33:18 - INFO - Response parsed successfully, got 1 choice(s)
2026-03-04 21:33:18 - INFO - Extracted content, length: 740 characters
<think>This is a very simple request - they want a basic Python program that prints "Hello, World!". This is the classic first program in almost every programming language.
The code is straightforward:
```python
print("Hello, World!")
```
I'll provide a clean, simple answer with just the code and maybe a brief explanation.
</think>
Here's a simple Python program that prints "Hello, World!":
```python
print("Hello, World!")
```
To run this program:
1. Save the code in a file named `hello.py`.
2. Open a terminal or command prompt.
3. Navigate to the directory where the file is saved.
4. Run the program using:
```bash
python hello.py
```
This will display the message `Hello, World!` in your terminal or command prompt.
2026-03-04 21:33:18 - INFO - Completed successfully
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment