|
29 | 29 | ;; |
30 | 30 | ;;; API |
31 | 31 |
|
32 | | -(defun google-gemini-content-make-contents (text) |
33 | | - "Create a contents value." |
34 | | - `((parts . [((text . ,text))]))) |
35 | | - |
36 | 32 | ;;;###autoload |
37 | | -(cl-defun google-gemini-content-generate ( contents callback |
| 33 | +(cl-defun google-gemini-content-generate ( text callback |
38 | 34 | &key |
39 | | - (content-type "application/json")) |
| 35 | + (content-type "application/json") |
| 36 | + (category "HARM_CATEGORY_DANGEROUS_CONTENT") |
| 37 | + (threshold "BLOCK_ONLY_HIGH") |
| 38 | + stop-sequences |
| 39 | + temperature |
| 40 | + max-output-tokens |
| 41 | + top-p |
| 42 | + top-k) |
40 | 43 | "Send generate content request." |
41 | 44 | (request (format "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=%s" |
42 | 45 | google-gemini-key) |
43 | 46 | :type "POST" |
44 | 47 | :headers (google-gemini--headers content-type) |
45 | 48 | :data (google-gemini--json-encode |
46 | | - `(("contents" . [,contents]))) |
| 49 | + `(("contents" . [((parts . [((text . ,text))]))]) |
| 50 | + ("safetySettings" . [(("category" . ,category) |
| 51 | + ("threshold" . ,threshold))]) |
| 52 | + ("generationConfig" . |
| 53 | + (("stopSequences" . ,stop-sequences) |
| 54 | + ("temperature" . ,temperature) |
| 55 | + ("maxOutputTokens" . ,max-output-tokens) |
| 56 | + ("topP" . ,top-p) |
| 57 | + ("topK" . ,top-k))))) |
47 | 58 | :parser 'json-read |
48 | 59 | :complete (cl-function |
49 | 60 | (lambda (&key data &allow-other-keys) |
|
56 | 67 | (defun google-gemini-content-prompt () |
57 | 68 | "Start making a conversation to Google Gemini." |
58 | 69 | (interactive) |
59 | | - (if-let* ((text (read-string "Content: ")) |
60 | | - (contents (google-gemini-content-make-contents text))) |
61 | | - (google-gemini-content-generate contents |
| 70 | + (if-let ((text (read-string "Content: "))) |
| 71 | + (google-gemini-content-generate text |
62 | 72 | (lambda (data) |
63 | 73 | (let-alist data |
64 | 74 | (let-alist (elt .candidates 0) |
|
0 commit comments