Streaming response character encoding issue
pazars opened this issue · comments
Dāvis Pazars commented
Text in Latvian from a non-streaming response:
import { AnthropicVertex } from '@anthropic-ai/vertex-sdk';
const client = new AnthropicVertex({region:'us-central1'});
const response = await client.messages.create({
messages: [
{
role: 'user',
content: 'Kāds ir latviešu valodas alfabēts?',
},
],
model: 'claude-3-sonnet@20240229',
max_tokens: 512,
stream: false
})
console.log(response.content[0].text);
Latviešu alfabētā ir 33 burti:
A, Ā, B, C, Č, D, E, Ē, F, G, Ģ, H, I, Ī, J, K, Ķ, L, Ļ, M, N, Ņ, O, P, R, S, Š, T, U, Ū, V, Z, Ž
Tas sastāv no 26 latīņu burtiem un 7 patskaņu garumzīmēm un mīkstinājuma zīmēm - garumzīmes ā, ē, ī, ū un mīkstinājuma zīmes č
, ģ, ķ, ļ, ņ, š, ž.
Latviešu alfabēts tiek uzskatīts par vienu no bagātākajiem pasaulē, jo ir tik daudz diakritisko zīmju, kas palīdz precīzi atai
not latviešu valodas skaņu sistēmu.
Text in Latvian from a streaming response:
import { AnthropicVertex } from '@anthropic-ai/vertex-sdk';
const client = new AnthropicVertex({region:'us-central1'});
const response = await client.messages.create({
messages: [
{
role: 'user',
content: 'Kāds ir latviešu valodas alfabēts?',
},
],
model: 'claude-3-sonnet@20240229',
max_tokens: 512,
stream: true
})
let text = "";
for await (const item of response) {
if (item.type === "content_block_delta") {
text = text + item.delta.text;
}
};
console.log(text);
Latvie��u valodas alfab��ts sast��v no 33 burtiem:
A, Ā, B, C, Č, D, E, Ē, F, G, Ģ, H, I, ��, J, K, Ķ, L, ��, M, N, ��, O, P, R, S, ��, T, U, ��, V, Z, Ž
Tas ietver 26 latī��u burtus un 7 diakritiskās jeb paplašinātās līdzskaņu zīmes (��etras garumzīmes un trīs mīkstinājuma zīmes
):
- Garumzīmes: ā, ��, ī, ū
- Mīkstinājuma zīmes: č, ��, ��, ��, ņ, ��, ��
Šīs ��pašās burti atspoguļo latviešu valodas skaņu sistēmu un ir ļoti būtiskas tās pareizā rakstībā un izrunā.
How to correctly display all characters? They should be utf-8.
Dāvis Pazars commented
Using "@anthropic-ai/vertex-sdk": "^0.3.0"
Alex Rattray commented
Thanks for the report, we'll take a look!
Valtteri Karesto commented
Noticed the same issue, mainly with nordic characters like ä and ö. Although in the same response, some of these characters worked and some did not.
Alex Rattray commented
We're working on this and should have a fix out next week!
Robert Craigie commented
A fix for this was released in v0.19.2
!