Ollama ์‚ฌ์šฉ ์‹œ JSON Parse error: Unexpected EOF๊ฐ€ ๋‚˜๋Š” ๋ฌธ์ œ๋ฅผ ์›์ธ-ํ•ด๊ฒฐ ์ˆœ์„œ๋กœ ๋‹ค๋ฃน๋‹ˆ๋‹ค.

๋น ๋ฅด๊ฒŒ ์‹คํ–‰ (๋ณต๋ถ™)

{"provider":"ollama","model":"qwen3-coder","stream":false}
curl -s http://localhost:11434/api/chat -d ...
flowchart TD
A[stream=true] --> B[NDJSON]
B --> C[JSON ํŒŒ์‹ฑ ์‹คํŒจ]
C --> D[Unexpected EOF]
D --> E[stream=false]

๋‹จ๊ณ„๋ณ„ ์ ์šฉ

1) ์ฆ์ƒ ํ™•์ธ

  • ์„ค๋ช…: tool call ์‹œ Unexpected EOF๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ์ด ์ผ€์ด์Šค๋ฅผ ์˜์‹ฌํ•ฉ๋‹ˆ๋‹ค.
  • ์‹คํ–‰ ์˜ˆ์‹œ: {"provider":"ollama","model":"qwen3-coder","stream":false}

2) ์›์ธ ํŒŒ์•…

  • ์„ค๋ช…: Ollama๋Š” stream=true์—์„œ NDJSON์„ ๋ฐ˜ํ™˜ํ•˜๊ณ , SDK๋Š” ๋‹จ์ผ JSON ๊ธฐ๋Œ€๋กœ ํŒŒ์‹ฑ ์‹คํŒจํ•ฉ๋‹ˆ๋‹ค.
  • ์‹คํ–‰ ์˜ˆ์‹œ: curl -s http://localhost:11434/api/chat -d ...

3) ์ฆ‰์‹œ ํ•ด๊ฒฐ

  • ์„ค๋ช…: provider ์„ค์ •์— stream:false๋ฅผ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค.
  • ์‹คํ–‰ ์˜ˆ์‹œ: curl -s http://localhost:11434/api/chat -d ...

4) ๊ฒ€์ฆ

  • ์„ค๋ช…: curl ํ…Œ์ŠคํŠธ๋กœ tool call ์‘๋‹ต์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
  • ์‹คํ–‰ ์˜ˆ์‹œ: curl -s http://localhost:11434/api/chat -d ...

5) ์žฅ๊ธฐ ๋Œ€์‘

  • ์„ค๋ช…: SDK ์ด์Šˆ ํŠธ๋ž˜์ปค๋ฅผ ๊ตฌ๋…ํ•˜๊ณ  ๋ฒ„์ „ ์—…๋ฐ์ดํŠธ๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
  • ์‹คํ–‰ ์˜ˆ์‹œ: curl -s http://localhost:11434/api/chat -d ...

๋ถ€๋ก) ์›๋ฌธ ์ฝ”๋“œ ์Šค๋‹ˆํŽซ (๊ฒ€์ˆ˜์šฉ, ์ดˆ๋ณด์ž๋Š” ๊ฑด๋„ˆ๋›ฐ๊ธฐ)

{"message":{"tool_calls":[{"function":{"name":"read","arguments":{"filePath":"README.md"}}}]}, "done":false}
{"message":{"content":""}, "done":true}
{
  "provider": "ollama",
  "model": "qwen3-coder",
  "stream": false
}
# Test with curl (should work with stream: false)
curl -s http://localhost:11434/api/chat \
  -d '{
    "model": "qwen3-coder",
    "messages": [{"role": "user", "content": "Read file README.md"}],
    "stream": false,
    "tools": [{"type": "function", "function": {"name": "read", "description": "Read a file", "parameters": {"type": "object", "properties": {"filePath": {"type": "string"}}, "required": ["filePath"]}}}]
  }'

๋งˆ๋ฌด๋ฆฌ ์ฒดํฌ

  • ์œ„ โ€œ๋น ๋ฅด๊ฒŒ ์‹คํ–‰โ€ ๋ช…๋ น์„ ์ตœ์†Œ 1๊ฐœ ์‹คํ–‰ํ–ˆ๋‹ค.
  • ์‹คํŒจ ์‹œ โ€œ์›๋ฌธ ์‹คํ–‰ ์ฝ”๋“œ ํ™•์žฅโ€์˜ ๊ด€๋ จ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•ด ์žฌ๊ฒ€์ฆํ–ˆ๋‹ค.
  • ์›๋ณธ ํ•ญ๋ชฉ ๋Œ€์กฐ ์ธ๋ฑ์Šค์—์„œ ๋น ์ง„ ๊ธฐ๋Šฅ์ด ์—†๋Š”์ง€ ํ™•์ธํ–ˆ๋‹ค.

์ถœ์ฒ˜