[GH-ISSUE #6868] API request with Chinese characters in prompt not correctly be received... #4338

Closed
opened 2026-04-12 15:16:09 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @ingted on GitHub (Sep 19, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/6868

What is the issue?

Same issue as API request with Chinese characters in prompt

$url = 'http://localhost:11434/api/generate'

$body = @{
    model = "llama3-zh:latest"
    prompt = "一加一是多少"
    format = "json"
    stream = $false
} | ConvertTo-Json

$headers = @{
    "Content-Type" = "application/json"
    "Charset" = "utf-8"
}

$response = Invoke-WebRequest -Uri $url -Method Post -Body $body -Headers $headers

$response.Content

Response:

{"model":"llama3-zh:latest","created_at":"2024-09-19T02:35:55.596601Z","response":"{\"query\": \"What is the best way to learn a new language?\", \"context\": {\"language\": \"Spanish\", \"level\": \"beginner\"}}","done":true,"done_reason":"stop","context":[
319,27,91,318,5011,91,29,882,319,27708,7801,27,91,318,6345,91,1459,27,91,318,5011,91,29,78191,319,5018,1663,794,330,3923,374,279,1888,1648,311,4048,264,502,4221,32111,330,2196,794,5324,11789,794,330,62897,498,330,3374,794,330,7413,1215,32075],"total_duration
":665925000,"load_duration":54531900,"prompt_eval_count":25,"prompt_eval_duration":63678000,"eval_count":32,"eval_duration":544130000}

OS

Windows

GPU

Nvidia

CPU

Intel

Ollama version

0.3.11

Originally created by @ingted on GitHub (Sep 19, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/6868 ### What is the issue? Same issue as [API request with Chinese characters in prompt](https://github.com/ollama/ollama/issues/3793) ``` $url = 'http://localhost:11434/api/generate' $body = @{ model = "llama3-zh:latest" prompt = "一加一是多少" format = "json" stream = $false } | ConvertTo-Json $headers = @{ "Content-Type" = "application/json" "Charset" = "utf-8" } $response = Invoke-WebRequest -Uri $url -Method Post -Body $body -Headers $headers $response.Content ``` Response: ``` {"model":"llama3-zh:latest","created_at":"2024-09-19T02:35:55.596601Z","response":"{\"query\": \"What is the best way to learn a new language?\", \"context\": {\"language\": \"Spanish\", \"level\": \"beginner\"}}","done":true,"done_reason":"stop","context":[ 319,27,91,318,5011,91,29,882,319,27708,7801,27,91,318,6345,91,1459,27,91,318,5011,91,29,78191,319,5018,1663,794,330,3923,374,279,1888,1648,311,4048,264,502,4221,32111,330,2196,794,5324,11789,794,330,62897,498,330,3374,794,330,7413,1215,32075],"total_duration ":665925000,"load_duration":54531900,"prompt_eval_count":25,"prompt_eval_duration":63678000,"eval_count":32,"eval_duration":544130000} ``` ### OS Windows ### GPU Nvidia ### CPU Intel ### Ollama version 0.3.11
GiteaMirror added the bug label 2026-04-12 15:16:09 -05:00
Author
Owner

@ingted commented on GitHub (Sep 25, 2024):

Resolved! If you have the same issue, please move content type out of the header:

$url = 'http://localhost:11434/api/generate'

$body = '{
    "model": "llama3-zh:latest",
    "prompt":  "give the answer of ''一加一是多少'' in format {''result'': (answer value)}",
    "format": "json",
    "stream": false
}'

$headers = @{    
    'Accept'        = 'application/json'
}

$response = Invoke-WebRequest -Uri $url -Method Post -Body $body -Headers $headers -ContentType "application/json; charset=utf-8"

$response.Content
<!-- gh-comment-id:2372716313 --> @ingted commented on GitHub (Sep 25, 2024): Resolved! If you have the same issue, please move content type out of the header: ``` $url = 'http://localhost:11434/api/generate' $body = '{ "model": "llama3-zh:latest", "prompt": "give the answer of ''一加一是多少'' in format {''result'': (answer value)}", "format": "json", "stream": false }' $headers = @{ 'Accept' = 'application/json' } $response = Invoke-WebRequest -Uri $url -Method Post -Body $body -Headers $headers -ContentType "application/json; charset=utf-8" $response.Content ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#4338