Skip to content

Add DeepSeek API adapter, UTF-8 encoding fixes, and session timeline#2

Open
owlmeng wants to merge 4 commits into
electronistu:mainfrom
owlmeng:upstream-pr
Open

Add DeepSeek API adapter, UTF-8 encoding fixes, and session timeline#2
owlmeng wants to merge 4 commits into
electronistu:mainfrom
owlmeng:upstream-pr

Conversation

@owlmeng
Copy link
Copy Markdown

@owlmeng owlmeng commented Jun 2, 2026

Hey @electronistu — Project Infinity is amazing. The dice engine / AI DM separation is brilliant, and the campaign has been a blast.

Running on Chinese Windows, I added a few things:

play_with_deepseek.py — DeepSeek API adapter via OpenAI SDK, no proxy needed. Default deepseek-v4-flash.
UTF-8 encoding fix — Chinese Windows defaults to GBK, breaking YAML/JSON reads. Added encoding="utf-8" to all open() calls (12 places, 5 files).
Session timeline — Every 5 rounds, GM auto-summarizes into .timeline.md with same-name binding to .wwf. Persists across sessions, cache-friendly.
README — Updated with timeline + encoding note.
Tested: 15 rounds error-free, all tool calls (combat/healing/AoE), world forge, timeline checkpoints. Other backends untouched.

Happy to iterate!

owlmeng added 4 commits June 2, 2026 01:09
Since my AI agent environment cannot use Ollama to proxy DeepSeek
requests, I wrote a standalone adapter that connects to the official
DeepSeek API directly using the OpenAI SDK — no proxy needed.

- Add play_with_deepseek.py: DeepSeek API adapter.
  Default model: deepseek-v4-flash, supports --pro and --think.
  Uses extra_body for thinking mode, preserves reasoning_content.

- Fix game_engine.py: add encoding='utf-8' to all open() calls,
  preventing UnicodeDecodeError on Chinese Windows (GBK default).

- Fix game_engine.py: preserve thinking/reasoning_content in
  assistant messages, required by DeepSeek thinking mode.
- Add DeepSeek to prerequisites, backend table, and launch commands
- DeepSeek API is OpenAI-compatible, no proxy required
On Chinese Windows, Python defaults to GBK encoding, causing
UnicodeDecodeError when reading UTF-8 files (YAML configs,
JSON player data, spell database, world .wwf files).

Fix all open() calls in:
- forge/config_loader.py (5 YAML reads)
- forge/character_creator.py (spells.yml read)
- forge/formatter.py (JSON/WWF writes)
- dice_server.py (JSON/YAML reads)
- game_engine.py (text reads + JSON write)

Also add session timeline system to game_engine.py:
- Timeline auto-loaded from .wwf basename + .timeline.md
- Every 5 rounds, GM summarizes recent events into structured entries
- Cache-friendly: new entries appended as separate system messages
- Add session timeline to feature list and output file list
- Document .timeline.md auto-creation and cache-friendly injection
- Add GBK/UTF-8 encoding note for Chinese Windows users
@electronistu
Copy link
Copy Markdown
Owner

Thank you for your contribution to the project. The support for the UTF-8 encoding fix is a nice touch. I didn't have the time lately to look carefully on how the .timeline.md works, but I'm sure it works. It would be more precise in remembering the history of the game, than only the reputation system.
The only objection I would have is that the project is looking to be token efficient as much as possible. Already the .character file is large as you progress in the game, because of the inventory and reputation. So I think is a matter of flavour: either a bit more token efficient or more game history between sessions efficient.
One of these days I will play a long game with your fork to try it out to see exactly how it works. But please be patient with me; I played Project Infinity many times since I started about a year ago so my appetite for it is kind of low.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants