Skip to content

Commit d2b37f0

Browse files
committed
change ai improve using completion
1 parent 10cf0e0 commit d2b37f0

File tree

5 files changed

+59
-63
lines changed

5 files changed

+59
-63
lines changed

README.md

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,36 @@
33
(:require [robertluo.clerk-doc :as doc]
44
[robertluo.clerk-doc.ai :as ai])) ;=> nil
55
```
6-
# io.github.robertluo/clerk-doc
76

8-
[![CI](https://github.com/robertluo/clerk-doc/actions/workflows/main.yml/badge.svg)](https://github.com/robertluo/clerk-doc/actions/workflows/main.yml)
7+
# `io.github.robertluo/clerk-doc`
98

10-
Turns Clojure source files into markdown. Usually [clerk](https://github.com/nextjournal/clerk) notebooks are good
11-
candidates, when you do not feel like write README.md file for your Github projects.
12-
## Usage
13-
14-
Write a clojure source file just like this.
15-
Add an alias in your `deps.edn`:
9+
[![CI](https://github.com/robertluo/clerk-doc/actions/workflows/main.yml/badge.svg)](https://github.com/robertluo/clerk-doc/actions/workflows/main.yml)
10+
11+
Turns Clojure source files into Markdown. Usually [clerk](https://github.com/nextjournal/clerk) notebooks are good candidates for when you do not feel like writing a README.md file for your Github project.
12+
13+
## Usage
14+
15+
1. Write a Clojure source file, just like this.
16+
2. Add an alias in your `deps.edn`.
17+
3. Call it by `clojure -X:clerk-doc`.
1618
```clojure
1719
(comment
18-
{:clerk-doc {:extra-deps {io.github.robertluo/clerk-doc {:git/tag "v0.1.0" :git/sha "xxxxxx"}}
20+
{:clerk-doc {:extra-deps {io.github.robertluo/clerk-doc {:git/tag "v0.2.1" :git/sha "xxxxxx"}}
1921
:exec-fn robertluo.clerk-doc/clj->md
2022
:exec-args {:from "your-source.clj" :to "README.md"
2123
:eval-code? true :ai-improve? false}}}
2224
) ;=> nil
2325
```
24-
and call it by `clojure -X:clerk`
25-
## Goodies
26-
- If `:eval-code?` set to true, the clojure code in the file will be evaluated,
27-
the result will be append to the generated code blocks.
28-
- Thanks to [openai-clojure](https://github.com/wkok/openai-clojure) the
29-
`:ai-improve?` flag using OpenAI to improve your result md file.
30-
You need set up your environment, please refer to the above link.
31-
Make sure to check the result after ChatGPT's work, it sometimes
32-
surprises me.
33-
> You have to have a paid account of OpenAI, otherwise the OpenAI's rate limit will generate
34-
> a 400 error for anything longer than one simple sentence.
35-
36-
## Changes
37-
38-
- v0.2.0 Improve eval to print out exception and nil
39-
40-
## [UnLicense](https://unlicense.org/)
41-
2023 Robert Luo
26+
27+
28+
## Goodies
29+
- If `:eval-code?` is set to `true`, the Clojure code in the file will be evaluated, and the result will be appended to the generated code blocks.
30+
- Thanks to [openai-clojure](https://github.com/wkok/openai-clojure), the `:ai-improve?` flag uses OpenAI to improve your resulting Markdown file. You need to set up your environment; please refer to the link above. Make sure to check the result after ChatGPT's work; it sometimes surprises me.
31+
> You have to have a paid account with OpenAI, otherwise the OpenAI's rate limit will generate a `400` error for anything longer than one simple sentence.
32+
33+
## Changes
34+
- v0.2.0: Improved eval to print out exceptions and nils
35+
36+
## [UnLicense](https://unlicense.org/)
37+
38+
Copyright (c) 2023 Robert Luo

deps.edn

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
{:paths ["src"],
2-
:deps {org.clojure/clojure {:mvn/version "1.11.1"}
3-
rewrite-clj/rewrite-clj {:mvn/version "1.1.46"}
4-
net.clojars.wkok/openai-clojure {:mvn/version "0.4.0"}},
5-
:aliases
6-
{:dev
7-
{:extra-paths ["test"],
8-
:extra-deps {io.github.robertluo/rich-comment-tests {:git/tag "v1.1.0", :git/sha "6d01d12"}}}
9-
:test
10-
{:exec-fn com.mjdowney.rich-comment-tests.test-runner/run-tests-in-file-tree!
11-
:exec-args {:dirs #{"src"}}}
12-
:readme
13-
{:exec-fn robertluo.clerk-doc/clj->md
14-
:exec-args {:from "src/robertluo/clerk_doc/readme.clj" :to "README.md"
15-
:eval-code? true :ai-improve? false}}
16-
:build
17-
{:deps {io.github.seancorfield/build-clj {:git/tag "v0.8.2", :git/sha "0ffdb4c"}},
18-
:ns-default build}}}
1+
{:paths ["src"],
2+
:deps {org.clojure/clojure {:mvn/version "1.11.1"}
3+
rewrite-clj/rewrite-clj {:mvn/version "1.1.46"}
4+
net.clojars.wkok/openai-clojure {:mvn/version "0.5.0"}},
5+
:aliases {:dev {:extra-paths ["test"],
6+
:extra-deps {io.github.robertluo/rich-comment-tests {:git/tag "v1.1.0"
7+
:git/sha "6d01d12"}}}
8+
:test {:exec-fn com.mjdowney.rich-comment-tests.test-runner/run-tests-in-file-tree!
9+
:exec-args {:dirs #{"src"}}}
10+
:readme {:exec-fn robertluo.clerk-doc/clj->md
11+
:exec-args {:from "src/robertluo/clerk_doc/readme.clj"
12+
:to "README.md"
13+
:eval-code? true
14+
:ai-improve? true}}
15+
:build {:deps {io.github.seancorfield/build-clj {:git/tag "v0.8.2"
16+
:git/sha "0ffdb4c"}},
17+
:ns-default build}}}

src/robertluo/clerk_doc.clj

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,18 @@
7474
(transform-loc (zip/of-string ";;ok\n5\n")) ;=>> #(= 1 (count %))
7575
)
7676

77-
(def block-merge
78-
"turn `zloc` into markdown string (finally)"
79-
(comp (partition-by first) (map merge-blocks)))
80-
8177
(defn process-loc
8278
[ai-improve? zloc]
83-
(let [improvement
79+
(let [f-improve
8480
(fn [block]
8581
(cond-> block
8682
(and ai-improve? (= (first block) :comment))
87-
(update 1 ai/ask-for-comment)))]
83+
(update 1 (comp #(str % "\n") ai/ask-for-comment))))]
8884
(transduce
89-
(comp block-merge (map improvement) (map second))
85+
(comp (partition-by first)
86+
(map merge-blocks)
87+
(map f-improve)
88+
(map second))
9089
str
9190
(transform-loc zloc))))
9291

src/robertluo/clerk_doc/ai.clj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
(defn ask-for-comment
66
"returns an improved version of `text` with help of OPENAI"
77
[text]
8-
(-> (api/create-edit
9-
{:model "text-davinci-edit-001"
10-
:input text
11-
:instruction "Fix the spelling and gramar mistakes"})
8+
(-> (api/create-completion
9+
{:model "text-davinci-003"
10+
:top_p 1.0
11+
:max_tokens 2048
12+
:prompt (str "Correct this to standard English in Markdown format: " text)})
1213
(get-in [:choices 0 :text])))
1314

1415
(comment

src/robertluo/clerk_doc/readme.clj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
(:require [robertluo.clerk-doc :as doc]
55
[robertluo.clerk-doc.ai :as ai]))
66

7-
;; # io.github.robertluo/clerk-doc
7+
;; # `io.github.robertluo/clerk-doc`
88
;;
99
;; [![CI](https://github.com/robertluo/clerk-doc/actions/workflows/main.yml/badge.svg)](https://github.com/robertluo/clerk-doc/actions/workflows/main.yml)
1010
;;
@@ -13,18 +13,18 @@
1313

1414
;; ## Usage
1515
;;
16-
;; Write a clojure source file just like this.
17-
;; Add an alias in your `deps.edn`:
16+
;; 1. Write a clojure source file just like this.
17+
;; 2. Add an alias in your `deps.edn`.
18+
;; 3. call it by `clojure -X:clerk-doc`.
1819

1920
(comment
20-
{:clerk-doc {:extra-deps {io.github.robertluo/clerk-doc {:git/tag "v0.1.0" :git/sha "xxxxxx"}}
21+
{:clerk-doc {:extra-deps {io.github.robertluo/clerk-doc {:git/tag "v0.2.1" :git/sha "xxxxxx"}}
2122
:exec-fn robertluo.clerk-doc/clj->md
2223
:exec-args {:from "your-source.clj" :to "README.md"
2324
:eval-code? true :ai-improve? false}}}
2425
)
2526

26-
;; and call it by `clojure -X:clerk`
27-
27+
;;
2828
;; ## Goodies
2929
;; - If `:eval-code?` set to true, the clojure code in the file will be evaluated,
3030
;; the result will be append to the generated code blocks.
@@ -41,5 +41,5 @@
4141
;; - v0.2.0 Improve eval to print out exception and nil
4242
;;
4343
;; ## [UnLicense](https://unlicense.org/)
44-
44+
;;
4545
;; 2023 Robert Luo

0 commit comments

Comments
 (0)