Connection
Base URL, credentials and a reachable server.
Review replace_utf8.py around the point where a closed temporary file replaces the previous UTF-8 contents.
Base URL, credentials and a reachable server.
A model available through the configured endpoint.
Context limits and tool support are determined by the model and server.
import os
from pathlib import Path
from tempfile import NamedTemporaryFile
def replace_utf8(path, text):
if not isinstance(path, (str, Path)) or type(text) is not str:
raise ValueError("replace.input")
target, data = Path(path), text.encode("utf-8")
temporary = None
try:
with NamedTemporaryFile(dir=target.parent, prefix=".swap-", delete=False) as out:
temporary = Path(out.name)
out.write(data)
os.replace(temporary, target)
finally:
if temporary is not None:
temporary.unlink(missing_ok=True)