#### Making sure things are working {#making-sure-things-are-working}
Of course, I'd like to iteratively drill down into actually what I want. It
might be just the data scientist in me, but a bad habit I have is using
notebooks / babel as a first run of things. Maybe it's a good thing, I dunno.
First, a quick test of gptel, to make sure it's working. From the gptel-quick
package, it seems like the request is meant to be the main point of entry for
writing custom prompts.
```emacs-lisp
(require 'gptel)
(defun gptel-hello-world (name)
(let ((result nil)
(done nil))
(gptel-request
(format "Say a friendly hello to %s in one short sentence." name)
:callback (lambda (response _info)
(setq result response
done t)))
(while (not done)
(sleep-for 0.1))
result))
(gptel-hello-world "Justin")
```
Hello Justin, it's great to chat with you!
I got it working with ellama but I wanted to see if gptel works for chaining
prompts. Seems like it does. I would note that for all my experiments I'm using
a local small-ish version of llama 3. I'll probably switch to gpt4o-mini/turbo
for the end. Maybe Claude?
```emacs-lisp
(require 'gptel)
(defun gptel-chain-of-thought (question)
(let ((thoughts '())
(final-answer nil)
(done nil))
;; Initial thought
(gptel-request
(format "Consider this question: %s\nWhat's the first step in answering \
this? Provide your initial thought." question)
:callback (lambda (response _info)
(push response thoughts)
(setq done t)))
(while (not done) (sleep-for 0.1))
(setq done nil)
;; Generate a series of thoughts
(dotimes (_ 3) ; Adjust the number of thoughts as needed
(gptel-request
(format "Based on your previous thought: %s\nWhat's the next step in \
your reasoning?" (car thoughts))
:callback (lambda (response _info)
(push response thoughts)
(setq done t)))
(while (not done) (sleep-for 0.1))
(setq done nil))
;; Final answer
(gptel-request
(format "Based on your chain of thoughts:\n%s\nWhat's your final answer \
to the original question: %s"
(mapconcat 'identity (reverse thoughts) "\n")
question)
:callback (lambda (response _info)
(setq final-answer response
done t)))
(while (not done) (sleep-for 0.1))
;; Display the chain of thought
(dolist (thought (reverse thoughts))
(message "Thought: %s" thought))
(message "Final Answer: %s" final-answer)
final-answer))
;; Example usage
(gptel-chain-of-thought "I'm making an anki deck for SQL, what are 10 sub-topics to study")
```
Based on our conversation:
1. Data types (int, varchar, datetime)
2. Table operations (CREATE, ALTER, DROP)
3. Querying (SELECT, FROM, WHERE, JOIN)
4. Data manipulation (INSERT, UPDATE, DELETE)
5. Views and subqueries
6. Indexes and optimization techniques
7. SQL functions and aggregations (e.g., SUM, AVG, COUNT)
8. Common errors and pitfalls to avoid
9. Advanced SQL topics (e.g., window functions, common table expressions)
10. Best practices for writing efficient and readable SQL code
#### More Experiments with Chain/Analysis of Thought {#more-experiments-with-chain-analysis-of-thought}
Now that we know it's simple to chain prompts in gptel, let's try
using it for the initial part of my idea.[^fn:3]
Maybe let's try it in Python just for ease..