Skip to content

Instantly share code, notes, and snippets.

@rtrppl
Created August 6, 2023 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtrppl/54ecdb41fb8a47175c2b6bfe1ff4d2ed to your computer and use it in GitHub Desktop.
Save rtrppl/54ecdb41fb8a47175c2b6bfe1ff4d2ed to your computer and use it in GitHub Desktop.
gpt-dictionary-sentence
(defun lt/gpt-dictionary-sentence ()
"Provide a separate translation and dictionary look-up for all Chinese words in the current sentence, including pinyin."
(interactive)
(set-mark (point))
(forward-sentence)
(unless (region-active-p)
(user-error "No region active"))
(let ((buffer (get-buffer-create "*ChatGPT Chinese Dictionary*"))
(prompt "You emulate a traditional dictionary. Provide a separate translation for all (!) words in the Chinese sentence that follows the final colon. The format of the translation should be: Chinese characters &nbsp (pinyin) - English. Add a line break after each translation. Add a translation of the whole sentence at the end, but don't start this translation with Translation: : ")
(buffer-text (buffer-substring-no-properties (region-beginning) (region-end))))
(with-current-buffer buffer
(erase-buffer)
(insert (chatgpt-shell-post-prompt (concat prompt buffer-text)))
(display-buffer buffer t))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment