Last active
March 18, 2023 04:38
-
-
Save SamSaffron/ef63174268ebb95523e28a0f607f90ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "openai" | |
require "tempfile" | |
require "optparse" | |
API_KEY = ENV["OPEN_AI_API_KEY"] | |
intensity = 1 | |
OptionParser | |
.new do |opts| | |
opts.on( | |
"-i", | |
"--intensity INTENSITY", | |
Integer, | |
"Intensity value (1-10)" | |
) { |parsed| intensity = parsed } | |
end | |
.parse! | |
if !intensity.between?(1, 10) | |
puts "Please provide a valid intensity value between 1 and 10 using --intensity flag." | |
exit 1 | |
end | |
messages = [ | |
{ role: "system", content: <<~TEXT }, | |
You are a markdown proofreader, you correct egregious typos and phrasing issues, but keep the | |
original voice of the user. You do not touch code blocks. I will provide you with text to correct. | |
If nothing needs fixing then you will just echo it back. | |
Optionally a user can specify intensity. Intensity 10 is a pedandic English teacher correcting the text. Intensity 1 is a minimal proofreader. By default you operate at intensity 1. | |
TEXT | |
{ role: "user", content: <<~TEXT }, | |
 | |
TEXT | |
{ role: "assistant", content: <<~TEXT }, | |
 | |
TEXT | |
{ role: "user", content: <<~TEXT }, | |
Intensity 1: | |
The rain in spain stays mainly in the plane. | |
TEXT | |
{ role: "assistant", content: <<~TEXT }, | |
The rain in Spain, stays mainly in the Plane. | |
TEXT | |
{ role: "user", content: <<~TEXT }, | |
Intensity 1: | |
The rain in Spain, stays mainly in the Plane. | |
TEXT | |
{ role: "assistant", content: <<~TEXT }, | |
The rain in Spain, stays mainly in the Plane. | |
TEXT | |
{ role: "user", content: <<~TEXT }, | |
Intensity 1: | |
Hello, | |
Sometimes the logo isn't changing automatically when color scheme changes. | |
 | |
TEXT | |
{ role: "assistant", content: <<~TEXT }, | |
Hello, | |
Sometimes the logo does not change automatically when the color scheme changes. | |
 | |
TEXT | |
{ role: "user", content: <<~TEXT }, | |
Intensity 1: | |
Any ideas what is wrong with this peace of cod? | |
> This quot contains a typo | |
```ruby | |
# this has speling mistakes | |
testin.atypo = 11 | |
baad = "bad" | |
``` | |
TEXT | |
{ role: "assistant", content: <<~TEXT } | |
Any ideas what is wrong with this piece of code? | |
> This quot contains a typo | |
```ruby | |
# This has spelling mistakes | |
testing.a_typo = 11 | |
bad = "bad" | |
``` | |
TEXT | |
] | |
input = <<~TEXT | |
### Prioritizing complete term match in title over partial match | |
Discourse performs a `stem` + `prefix match` when searching. This can sometimes lead to very surprising results. | |
For example: `redis` stems to `redi` so a search for `redis` can find all the words that start with `redi` such as `redirect` and more. | |
A new hidden site setting was added: `prioritize_exact_search_title_match` which is now enabled on meta. | |
Before: | |
 | |
After: | |
 | |
This means that if you remember the title and type it in, you are far more likely to hit the title. | |
TEXT | |
messages << { role: "user", content: "Intensity #{intensity}:\n#{input}" } | |
client = OpenAI::Client.new(access_token: API_KEY) | |
response = | |
client.chat(parameters: { model: "gpt-3.5-turbo", messages: messages }) | |
text = response.dig("choices", 0, "message", "content") | |
#p response | |
if !text | |
p response | |
exit 1 | |
end | |
tmp1 = Tempfile.new | |
tmp1.write input | |
tmp1.close | |
tmp2 = Tempfile.new | |
tmp2.write text | |
tmp2.close | |
# using https://github.com/dandavison/delta | |
puts `delta #{tmp1.path} #{tmp2.path}` | |
tmp1.unlink | |
tmp2.unlink |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment