import pyautogui
import pyperclip
import time
from openai import OpenAI
client = OpenAI(
api_key=“[api-key]
)
Step 1: Click at (165, 752)
pyautogui.click(165, 752)
time.sleep(1) # Wait for a second to make sure the click is registered
Step 2: Drag from (440, 150) to (1305, 661) to select text
pyautogui.moveTo(440, 150)
pyautogui.dragTo(1305, 661, duration=1) # Duration is in seconds
Step 3: Copy the selected text to the clipboard
pyautogui.hotkey(‘ctrl’, ‘c’)
pyautogui.click(1205, 561)
time.sleep(2) # Wait for a second to make sure the text is copied
Step 4: Retrieve the text from the clipboard and store it in a variable
chat_history = pyperclip.paste()
Print the copied text to verify
print(chat_history)
completion = client.chat.completions.create(
model=“gpt-4o-mini”,
messages=[
{“role”: “system”, “content”: “You are a person named Atif who speaks Hindi as well as English. You are from Pakistan and you are a coder. You will analyze the chat history and respond like Atif. Outtput should be the next chat response (text message only)”},
{“role”: “system”, “content”: “Remove all of the special characters and send a clean message”},
{“role”: “user”, “content”: chat_history}
]
)
response = completion.choices[0].message
pyperclip.copy(response)
# Step 5: Click at coordinates (1808, 1328)
pyautogui.click(1142, 708)
time.sleep(1) # Wait for 1 second to ensure the click is registered
# Step 6: Paste the text
pyautogui.hotkey(‘ctrl’, ‘v’)
time.sleep(2) # Wait for 1 second to ensure the paste command is completed
# Step 7: Press Enter
pyautogui.press(‘enter’)
this is my code which is designed to auto reply in a whatsapp conversation
but when I run it, It works totally fine but in the response their is, ‘ChatCompletionMessage(content=’ at the start and ‘role=‘assistant’, function_call=None, tool_calls=None)’ at the end. I want to remove this pease help!