Skip to content

Instantly share code, notes, and snippets.

@SamSaffron
Last active March 18, 2023 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamSaffron/ef63174268ebb95523e28a0f607f90ea to your computer and use it in GitHub Desktop.
Save SamSaffron/ef63174268ebb95523e28a0f607f90ea to your computer and use it in GitHub Desktop.
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 },
![amazing car|100x100, 22%](upload://hapy.png)
TEXT
{ role: "assistant", content: <<~TEXT },
![Amazing car|100x100, 22%](upload://hapy.png)
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.
![Screen Recording 2023-03-17 at 18.04.22|video](upload://2rcVL0ZMxHPNtPWQbZjwufKpWVU.mov)
TEXT
{ role: "assistant", content: <<~TEXT },
Hello,
Sometimes the logo does not change automatically when the color scheme changes.
![Screen Recording 2023-03-17 at 18.04.22|video](upload://2rcVL0ZMxHPNtPWQbZjwufKpWVU.mov)
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:
![old search results for redis containing many odd results|428x500, 75%](upload://ky475zOx858NdOKAI6Zr5khXWsg.png)
After:
![a lot more redis in results|399x500, 75%](upload://AdJt5qicc5hkZXh5fuzeun6q6li.png)
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