mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-29 06:33:28 +00:00
Merge 7c8da00db3 into 159b5b2f72
This commit is contained in:
commit
76c8354951
2 changed files with 28 additions and 4 deletions
|
|
@ -301,8 +301,8 @@ def _save_conversation(console: Console, messages: list[dict[str, str]], command
|
|||
filename += ".json"
|
||||
|
||||
try:
|
||||
with open(filename, "w") as f:
|
||||
json.dump(messages, f, indent=2)
|
||||
with open(filename, "w", encoding="utf-8") as f:
|
||||
json.dump(messages, f, indent=2, ensure_ascii=False)
|
||||
console.print(f"[green]Conversation saved to {filename}[/green]")
|
||||
except Exception as e:
|
||||
console.print(f"[red]Error saving conversation: {e}[/red]")
|
||||
|
|
@ -320,7 +320,7 @@ def _load_conversation(console: Console, command: str, system: str | None) -> li
|
|||
filename += ".json"
|
||||
|
||||
try:
|
||||
with open(filename, "r") as f:
|
||||
with open(filename, "r", encoding="utf-8") as f:
|
||||
loaded: Final[_MessagesView] = {"messages": json.load(f)}
|
||||
console.print(f"[green]Conversation loaded from {filename}[/green]")
|
||||
return loaded["messages"]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import io
|
||||
from pathlib import Path
|
||||
from typing import Final
|
||||
|
||||
import pytest
|
||||
|
|
@ -7,7 +8,11 @@ from pydantic import JsonValue
|
|||
from rich.console import Console
|
||||
|
||||
from litellm.proxy.client.chat import ChatClient
|
||||
from litellm.proxy.client.cli.commands.chat import _stream_response
|
||||
from litellm.proxy.client.cli.commands.chat import (
|
||||
_load_conversation,
|
||||
_save_conversation,
|
||||
_stream_response,
|
||||
)
|
||||
|
||||
BASE_URL: Final = "http://localhost:8000"
|
||||
MESSAGE: Final = "blocked [/pii] :warning: content in [prompt_injection] after 42 tokens"
|
||||
|
|
@ -18,6 +23,25 @@ PARTIAL_THEN_ERROR: Final = (
|
|||
)
|
||||
|
||||
|
||||
def test_save_and_load_conversation_roundtrips_non_ascii(tmp_path: Path) -> None:
|
||||
"""/save writes readable UTF-8 (not \\uXXXX escapes) and /load reads it back on any locale."""
|
||||
console = Console()
|
||||
messages = [
|
||||
{"role": "user", "content": "Café ☕ 東京"},
|
||||
{"role": "assistant", "content": "日本語で返信します"},
|
||||
]
|
||||
target = tmp_path / "conversation.json"
|
||||
|
||||
_save_conversation(console, messages, f"/save {target}")
|
||||
|
||||
saved = target.read_text(encoding="utf-8")
|
||||
assert "東京" in saved
|
||||
assert "\\u" not in saved
|
||||
|
||||
loaded = _load_conversation(console, f"/load {target}", system=None)
|
||||
assert loaded == messages
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"status, body, json_body",
|
||||
[
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue