[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/gptel 65e6d73372 013/273: gptel: Include more API paramete
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/gptel 65e6d73372 013/273: gptel: Include more API parameters |
Date: |
Wed, 1 May 2024 10:01:26 -0400 (EDT) |
branch: elpa/gptel
commit 65e6d733728b69294965ee12954085eb730f2298
Author: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
Commit: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
gptel: Include more API parameters
gptel.el (gptel--system-message, gptel--system-message-alist,
gptel--model, gptel--temperature, gptel--max-tokens,
gptel--request-data): Add new buffer-local variables to hold API
parameters. Generating the full request data plist is now done in a
separate function, `gptel--request-data'.
---
gptel-curl.el | 6 +-----
gptel.el | 30 +++++++++++++++++++++++-------
2 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/gptel-curl.el b/gptel-curl.el
index 5f8c79e722..3ccfdb3d46 100644
--- a/gptel-curl.el
+++ b/gptel-curl.el
@@ -45,11 +45,7 @@ PROMPTS is the data to send, TOKEN is a unique identifier."
(list "--location" "--silent" "--compressed" "--disable"))
(url "https://api.openai.com/v1/chat/completions")
(data (encode-coding-string
- (json-encode
- `(:model "gpt-3.5-turbo"
- ;; :temperature 1.0
- ;; :top_p 1.0
- :messages [,@prompts]))
+ (json-encode (gptel--request-data prompts))
'utf-8))
(api-key
(cond
diff --git a/gptel.el b/gptel.el
index a09de5244e..dfd3987690 100644
--- a/gptel.el
+++ b/gptel.el
@@ -90,6 +90,18 @@ When set to nil, it is inserted all at once.
(defvar gptel-prompt-string "### ")
(aio-defun gptel-send ()
+;; Model and interaction parameters
+(defvar-local gptel--system-message
+ "You are a large language model living in Emacs and a helpful assistant.
Respond concisely.")
+(defvar gptel--system-message-alist
+ `((default . ,gptel--system-message)
+ (programming . "You are a large language model and a careful programmer.
Respond only with code unless explicitly asked.")
+ (writing . "You are a large language model and a writing assistant.
Respond concisely.")
+ (chat . "You are a large language model and a conversation partner.
Respond concisely."))
+ "Prompt templates (directives).")
+(defvar-local gptel--max-tokens nil)
+(defvar-local gptel--model "gpt-3.5-turbo")
+(defvar-local gptel--temperature 1.0)
(defvar-local gptel--num-messages-to-send nil)
(defsubst gptel--numberize (val)
@@ -173,6 +185,16 @@ instead."
gptel--system-message))
prompts)))))
+(defun gptel--request-data (prompts)
+ "JSON encode PROMPTS for sending to ChatGPT."
+ (let ((prompts-plist
+ `(:model ,gptel--model
+ :messages [,@prompts])))
+ (when gptel--temperature
+ (plist-put prompts-plist :temperature (gptel--numberize
gptel--temperature)))
+ (when gptel--max-tokens
+ (plist-put prompts-plist :max_tokens (gptel--numberize
gptel--max-tokens)))
+ prompts-plist))
(aio-defun gptel--get-response (prompts)
"Fetch response for PROMPTS from ChatGPT.
@@ -189,13 +211,7 @@ Return the message received."
`(("Content-Type" . "application/json")
("Authorization" . ,(concat "Bearer " api-key))))
(url-request-data
- (encode-coding-string
- (json-encode
- `(:model "gpt-3.5-turbo"
- ;; :temperature 1.0
- ;; :top_p 1.0
- :messages [,@prompts]))
- 'utf-8)))
+ (encode-coding-string (json-encode (gptel--request-data prompts))
'utf-8)))
(pcase-let ((`(,_ . ,response-buffer)
(aio-await
(aio-url-retrieve
"https://api.openai.com/v1/chat/completions"))))
- [nongnu] branch elpa/gptel created (now 97ab6cbd1e), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 99aa8dcc5f 001/273: Add gptel.el and a README., ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel deeb606409 003/273: Update license., ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 88995a6436 007/273: gptel-curl: Add curl module and playback feature., ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel cf6999ac12 002/273: Fix byte-compile warnings, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel cd6d90b24d 026/273: gptel-transient: Improve "send in existing/new session" option, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 8fca5bc762 019/273: gptel: Add org-mode support and update README, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 8a6ef565f0 033/273: gptel-transient: Remove unused lexical vars, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 86bf0c9f74 004/273: gptel: Avoid logging url-retrieve messages, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel de70a066d7 017/273: gptel: Pulse inserted text, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 65e6d73372 013/273: gptel: Include more API parameters,
ELPA Syncer <=
- [nongnu] elpa/gptel 0d26b34526 029/273: gptel: Add a debug flag, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 6f951ed690 037/273: Add gptel-api-key-from-auth-source (Fix #13), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 4f3ca23454 040/273: gptel: Update commentary and README, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 9f8a984729 038/273: gptel: Change how api-key is read, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 9b3db255e8 049/273: gptel: Turn API parameters into defcustoms, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel a5fe30312f 005/273: gptel: Fix spacing issues in response, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 3c10147a72 009/273: gptel: Tweak README, minor linting, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 77d1010fbc 010/273: gptel-curl: Add package version, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 03113afd50 008/273: gptel: Rename internal functions, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel b212c24c4a 018/273: gptel: tweak prompt, rename url functions, ELPA Syncer, 2024/05/01