Thu, Oct 09, 25, Korean Backend Hotfix for kor2Unity

Context: Restoring the kor2Unity Korean learning stack so the model returns culturally accurate responses instead of generic GAN essays. All work performed inside the minigpt4 conda environment on the kor2fix repo.

๐Ÿงญ Summary

  • Confirmed Ollama (Mistral) was unreachable while the self-hosted FastAPI fallback still answered requests.
  • Replaced the backend with the โ€œImmediate Korean Knowledgeโ€ variant generated by fix_korean_immediate.py and synced the TUI client.
  • Rebuilt and restarted the Docker backend, then validated conversational outputs through curls, the TUI, and automated demo tests.

๐Ÿ•’ Timeline

Time (KST) Step Notes
10:02 kt startup Auto-activated minigpt4, banner showed Ollama connection failures and fallback to legacy API.
10:04 Conversation probe Prompted ์•ˆ๋…•; transformer still produced off-topic GAN essay.
10:10 Script review Grepped kor2unity_tui.py to verify fallback order and payload shape.
10:15 Hotfix generation Ran python fix_korean_immediate.py; copied patched backend and TUI into place.
10:18 Docker restart docker-compose restart backend then cold restart to ensure clean boot.
10:23 Regression test Curl with context: korean_mode still produced nonsenseโ€”triggered full rebuild.
10:28 Rebuild & deploy docker-compose build backend && docker-compose up -d backend.
10:33 Validation Curl responses now delivered structured pronunciation guides; TUI timeout smoke test and demo_korean_success.py all green.

kor2Unity Docker images

Docker registry after the fix: rebuilt kor2unity-backend:dev (52 minutes old) alongside Ollama 0.1.48, Rasa services, and supporting containers.

nigpt4 ๎‚ฐ โ€ฆ/uc/en/kor2fix ๎‚ฐ docker logs kor2fix-backend-1 --tail 10
INFO:     172.82.0.1:57400 - "GET /health HTTP/1.1" 200 OK
INFO:     Shutting down
INFO:     Waiting for application shutdown.
INFO:     Application shutdown complete.
INFO:     Finished server process [1]
INFO:     Started server process [1]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8201 (Press CTRL+C to quit)
INFO:     172.82.0.1:37058 - "POST /api/llm/chat HTTP/1.1" 200 OK
 (e) minigpt4 ๎‚ฐ โ€ฆ/uc/en/kor2fix ๎‚ฐ cd /mnt/d/repos/aiegoo/uconGPT/eng2Fix/kor2fix && head -5 backend/api/main.py
"""
Immediate Korean Knowledge Backend - Instant accurate Korean learning responses
"""

from fastapi import FastAPI, HTTPException

๐Ÿ”Ž Before vs After (Terminal Evidence)

Before โ€” Failing sessions

๐Ÿ Auto-activating conda environment: minigpt4
๐ŸŽฎ Korean TUI...
============================================================
๐Ÿ‡ฐ๐Ÿ‡ท kor2Unity - Korean Language Learning Assistant
๐Ÿง  Self-hosted Llama 2 7B-HF + MiniGPT-4
๐Ÿ”ฅ Environment: minigpt4 conda
============================================================
๐Ÿ” Checking available AI services...
โš ๏ธ Ollama API not available: HTTPConnectionPool(host='localhost', port=11434)...
โœ… Legacy FastAPI available
โœ… Connected to self-hosted AI!

๐Ÿ’ฌ You: ์•ˆ๋…•
๐Ÿค” Thinking... (using Ollama Mistral)
๐Ÿ’ญ Response (11.7s):
----------------------------------------
Dear Admin,

Today's article is about the latest developments in the field of AI...
----------------------------------------

Issue: the client still believed it was on the Ollama path, so the generic English essay came back even though only the legacy FastAPI endpoint remained.

Restarting the container and retrying the curl produced equally garbled โ€œtranslationsโ€:

(kor2fix) $ docker-compose restart backend
[+] Restarting 1/1
 โœ” Container kor2fix-backend-1  Started

(kor2fix) $ sleep 3 && curl ... 'How do you say hello in Korean?'
In Korean, the most common way to say "hello" is "gaejungae sari-un" (๋Œ€์ฃผ์ธ๋ง)...

(kor2fix) $ sleep 5 && curl ... 'How do you say hello in Korean?'
In Korean, the word "hi" or "hai" is called "hello." Here's how to say it in Korean:
- "๋ฐ˜๊ฐ‘์œผ๋กœ" (bangguro) - "Hello"
- "์•ˆ๋…" (anbulgwa) - "Morning"
...

Diagnosis: a simple restart wasnโ€™t enough; the container was still serving the stale model bundle.

Corrective steps (in order)

(kor2fix) $ python scripts/fix_korean_immediate.py
โœ… TUI model display fixed!
โœ… Immediate Korean knowledge backend created!

(kor2fix) $ cp backend/api/main_knowledge.py backend/api/main.py
(kor2fix) $ cp scripts/kor2unity_tui_fixed.py scripts/kor2unity_tui.py

(kor2fix) $ docker-compose restart backend

When the restart alone still produced garbled Hangul, I rebuilt the image:

(kor2fix) $ docker-compose build backend
(kor2fix) $ docker-compose up -d backend

When the backend still reported a placeholder echo (because Ollama wasnโ€™t reachable), I patched the service hostname and repeated the build:

(kor2fix) $ python fix_ollama_url.py
โœ… Fixed Ollama URL to use Docker container hostname

(kor2fix) $ docker-compose build backend && docker-compose up -d backend
[+] Building ... kor2unity-backend:dev  Built
[+] Running ... kor2fix-backend-1  Started

After โ€” Clean Korean responses

(kor2fix) $ curl -s -X POST http://localhost:8201/api/llm/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "How do you say hello in Korean?", "context": "korean_mode"}'
{"response":"๐Ÿ‡ฐ๐Ÿ‡ท Korean Greetings - Complete Guide!...","model":"Korean Knowledge Base v5.0"}

(kor2fix) $ curl -s -X POST http://localhost:8201/api/llm/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "์•ˆ๋…•", "context": "korean_mode"}' | jq -r '.response'
๐Ÿ‡ฐ๐Ÿ‡ท Nice! You said "์•ˆ๋…•" (Hi/Bye!)
...

(kor2fix) $ echo '/korean' | timeout 15s kt
TUI test completed successfully

(kor2fix) $ python scripts/demo_korean_success.py
๐ŸŽ‰ KOREAN LEARNING AI - FINAL SUCCESS! ๐Ÿ‡ฐ๐Ÿ‡ท
... all regression tests passed ...

Result: backend now surfaces the curated Korean knowledge base, pronunciation guides, and cultural context with sub-second latency.

The demo script also reiterates the learner guide that now ships with the platform:

๐Ÿ“š Learning Commands:
  "How do you say hello in Korean?"
  "Teach me Korean thank you"
  "What does ์•ˆ๋…•ํ•˜์„ธ์š” mean?"

๐Ÿ‡ฐ๐Ÿ‡ท Korean Practice:
  ์•ˆ๋…•                 # Casual greeting
  ์•ˆ๋…•ํ•˜์„ธ์š”           # Formal greeting
  ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค           # Thank you
  ์ถ”์„ ์ž˜๋ณด๋ƒˆ์–ด?       # Chuseok question

โœจ Features:
  โ€ข Instant accurate responses
  โ€ข Pronunciation guides (romanization)
  โ€ข Cultural context explanations
  โ€ข Formal vs casual usage
  โ€ข Real Korean conversation practice

โš ๏ธ Error Snapshot

โš ๏ธ Ollama API not available: HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded...

Early model behavior

Dear Admin,

Today's article is about the latest developments in the field of AI...

The fallback still advertised โ€œOllama Mistralโ€ because the client switched APIs without updating api_type, which is why the response tone never changed.

๐Ÿ”ง Fix Implementation

Backend swap

cd /mnt/d/repos/aiegoo/uconGPT/eng2Fix/kor2fix
python scripts/fix_korean_immediate.py
cp backend/api/main_knowledge.py backend/api/main.py
cp scripts/kor2unity_tui_fixed.py scripts/kor2unity_tui.py

Container cycle

docker-compose restart backend
sleep 5
curl -s -X POST http://localhost:8201/api/llm/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "How do you say hello in Korean?", "context": "korean_mode"}' | jq -r '.response'

When the first restart still produced garbled Korean, I rebuilt the image to ensure the new FastAPI module shipped with the container:

docker-compose stop backend
sleep 2
docker-compose up -d backend
sleep 5
curl -s -X POST http://localhost:8201/api/llm/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "How do you say hello in Korean?", "context": "korean_mode"}' | jq -r '.response'

Final rebuild

docker-compose build backend
docker-compose up -d backend

โœ… Verification

Health check responses

curl http://localhost:8201/ | jq
{
  "message": "Welcome to kor2Unity Korean Learning API!",
  "version": "2.0.0-python313",
  "status": "running"
}

Conversational probes

curl -s -X POST http://localhost:8201/api/llm/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "์•ˆ๋…•", "context": "korean_mode"}' | jq -r '.response'

๐Ÿ‡ฐ๐Ÿ‡ท Nice! You said โ€œ์•ˆ๋…•โ€ โ€ฆ

TUI smoke test

echo '/korean' | timeout 15s kt

Automated regression

python scripts/demo_korean_success.py
Test Expectation Result
Greeting lesson Formal ์•ˆ๋…•ํ•˜์„ธ์š” guide โœ… Passed
Casual greeting Explains ์•ˆ๋…• usage โœ… Passed
Thanks lesson Highlights ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค โœ… Passed
Chuseok context Cultural explanation โœ… Passed

๐Ÿ“ Lessons Learned

  • Always rebuild the Docker image when replacing backend modulesโ€”hot copies can leave stale layers.
  • Keep the TUI api_type in sync with the selected endpoint to avoid misleading telemetry.
  • Automated demos provide quick confidence that pronunciation guides and cultural context remain intact.

๐Ÿ“Œ Next Steps

  • Re-enable Ollama once the local daemon is reachable to recover multimodal support.
  • Add a health endpoint in the TUI banner so users see which model is active before chatting.