Skip to content

bug of org-ai-refactor-code about utf8 encoding  #132

@jixiuf

Description

@jixiuf
package demo

type StructDemo struct {
	A int // 字段A
}

I select struct StructDemo and M-x: org-ai-refactor-code with prompt:"add json tag"

then generated code become:

type StructDemo struct {
	A int `json:"A"` // \345\255\227\346\256\265A
}

If I replace (encode-coding-string (buffer-substring-no-properties start end) 'utf-8) with (buffer-substring-no-properties start end) in function org-ai--output-to-buffer
the bug gone .

another related bug:
when I apply the patch (after answer y or n ),would got

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
  org-ai--url-request-on-change-function(7699 8766 0)
  url-http-generic-filter(#<process api.openai.com> "424\15\ndata: {\"id\":\"chatcmpl-AITOdss8RF45QBj7dKT0u1RGSJ60k\",\"object\":\"chat.completion.chunk\",\"created\":1728966267,\"model\":\"gpt-4o-mini-2024-07-18\",\"system_fingerprint\":\"fp_e2bde53e6e\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"a\"},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-AITOdss8RF45QBj7dKT0u1RGSJ60k\",\"object\":\"chat.completion.chunk\",\"created\":1728966267,\"model\":\"gpt-4o-mini-2024-07-18\",\"system_fingerprint\":\"fp_e2bde53e6e\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"\\n\"},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-AITOdss8RF45QBj7dKT0u1RGSJ60k\",\"object\":\"chat.completion.chunk\",\"created\":1728966267,\"model\":\"gpt-4o-mini-2024-07-18\",\"system_fingerprint\":\"fp_e2bde53e6e\",\"choices\":[{\"index\":0,\"delta\":{\"content\":\"}\"},\"logprobs\":null,\"finish_reason\":null}]}\n\ndata: {\"id\":\"chatcmpl-AITOdss8RF45QBj7dKT0u1RGSJ60k\",\"object\":\"chat.completion.chunk\",\"created\":1728966267,\"model\":\"gpt-4o-mini-2024-07-18\",\"system_fingerprint\":\"fp_e2bde53e6e\",\"choices\":[{\"index\":0,\"delta\":{},\"logprobs\":null,\"finish_reason\":\"stop\"}]}\n\ndata: [DONE]\n\n\15\n")

GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.41, cairo version 1.18.0) of
2024-10-12

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions