-
Notifications
You must be signed in to change notification settings - Fork 0
/
2023-06-18-google-bard-and-emacs.html
101 lines (99 loc) · 4.78 KB
/
2023-06-18-google-bard-and-emacs.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="description" content="How to utilize Google Bard from within Emacs">
<link rel="alternate"
type="application/rss+xml"
href="https://www.birkey.co/rss.xml"
title="RSS feed for https://www.birkey.co/">
<title>Google Bard and Emacs</title>
<link href="static/style.css" rel="stylesheet" type="text/css" />
<link rel="apple-touch-icon" sizes="180x180" href="static/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="static/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="static/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="mask-icon" href="static/safari-pinned-tab.svg" color="#5bbad5">
<link rel="alternate" type="application/rss+xml" title="RSS Feed for birkey.co" href="/rss.xml">
<meta name="author" content="Kasim Tuman">
<meta name="referrer" content="no-referrer">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8">
<meta name="viewport" content="initial-scale=1,width=device-width,minimum-scale=1">
</head>
<body>
<div id="preamble" class="status"><br><center>
<div style="display: inline-block; vertical-align:middle;">
<a href="https://www.birkey.co/index.html" style="text-decoration: none;"><b>BIRKEY CONSULTING</b><br>
</a><hr/><div style="text-align: justify;display: inline-block; width: 100%;">
<a class="title" href="https://github.com/oneness">ABOUT</a> <a class="title" href="https://www.birkey.co/rss.xml">RSS</a> <a class="title" href="https://www.birkey.co/archive.html">ARCHIVE</a></div></div>
</center><br><br>
<div style="margin-bottom: 3ch;text-transform: none;"></div></div>
<div id="content">
<div class="post-date">18 Jun 2023</div><h1 class="post-title"><a href="https://www.birkey.co/2023-06-18-google-bard-and-emacs.html">Google Bard and Emacs</a></h1>
<p>
After reading a Google blog post on Bard's increasing ability for
reasoning about source code, I thought I would give it a try. The
issue is that not like OpenAI, Bard currently does not have an http
API that I can use via curl. I googled around and came across the
`bard-rs` project here: <a href="https://github.com/Alfex4936/Bard-rs">https://github.com/Alfex4936/Bard-rs</a>. So I
followed the excellent instruction to get set up using bard from
command line and its is pretty solid. I used following Elisp to use
`bard-rs` from Emacs' compilation buffer here:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp">(defun kcompilation-start (cmd name &optional mode)
(let* ((compile-command nil)
(compilation-save-buffers-predicate 'ignore)
(compilation-buffer
(compilation-start cmd
(if (equal mode 'read-only) nil t)
(lambda (m)
(or (when (boundp 'name)
(format "*%s*" name))
(buffer-name))))))
(when current-prefix-arg
(with-current-buffer compilation-buffer
(switch-to-prev-buffer (get-buffer-window (current-buffer)))))
(message (format "Running %s in %s ..." cmd name))))
(defun kprompt-bard (&optional p)
"Prompts for input to send it to `bard` using `bard-rs` in
*bard-prompt* buffer. If mark-active, uses the text in the region
as the prompt"
(interactive "P")
(let* ((bs "bard-prompt")
(bname (format "*%s*" bs))
(bname (if (get-buffer bname)
bname
(progn (kcompilation-start "bard-rs -e ~/.env" bs)
bname)))
(prompt (if mark-active
(replace-regexp-in-string
"\n"
""
(buffer-substring-no-properties (region-beginning) (region-end)))
(read-string "AI Chat Prompt: "))))
(with-current-buffer (pop-to-buffer bname)
(when p
(end-of-buffer)
(insert "!reset")
(comint-send-input)
(end-of-buffer)
(insert prompt)
(comint-send-input))
(when (not p)
(end-of-buffer)
(insert prompt)
(comint-send-input)))))
</pre>
</div>
<p>
You can bind `kprompt-bard` to any key of your choice and start
interacting with Google bard from the comfort of Emacs' buffer.
</p>
<div class="taglist"><a href="https://www.birkey.co/tags.html">Tags</a>: <a href="https://www.birkey.co/tag-ai.html">AI</a> <a href="https://www.birkey.co/tag-emacs.html">emacs</a> </div></div>
<div id="postamble" class="status"><br><center>
<div style="display: inline-block; vertical-align:middle;"></div></div>
</body>
</html>