forked from AvicennaJr/pycon_arusha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext-correction-groq.py
57 lines (38 loc) · 1.31 KB
/
text-correction-groq.py
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
from pynput import keyboard
from pynput.keyboard import Key, Controller
import pyperclip
import time
from groq import Groq
client = Groq(api_key="your-api-key-here")
controller = Controller()
def fix_text(text):
message = text
chat_completion = client.chat.completions.create(
messages=[
{
"role": "system",
"content": "you are an ai system designed to fix typos in a provided text while preserving all lines and punctuations. If provided with a text, eg: 'helloooo there, howww are yoou', you will return 'hello there, how are you' and nothing else. Do not respond with a preamble or any other information except for the corrected text. Do not even put the corrected text in quotation marks."
},
{
"role": "user",
"content": message,
}
],
model="mixtral-8x7b-32768",
)
return chat_completion.choices[0].message.content
def fix_selection():
with controller.pressed(Key.ctrl):
controller.tap('c')
time.sleep(0.1)
text = pyperclip.paste()
fixed_text = fix_text(text)
pyperclip.copy(fixed_text)
time.sleep(0.1)
with controller.pressed(Key.ctrl):
controller.tap('v')
def on_f9():
fix_selection()
with keyboard.GlobalHotKeys({
'<65478>': on_f9}) as h:
h.join()