Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clip2ai

clip2ai is a small local tool that sends clipboard text or images to the OpenAI API and copies the response back to the clipboard.

It provides two endpoints:

  • /api/generate-code — returns code without explanations or Markdown.
  • /api/test — returns a direct answer for text questions, screenshots, multiple-choice tasks, and code exercises.

Setup

Clone the repository:

git clone https://github.com/dariiahacker1/clip2ai.git
cd clip2ai

Install dependencies:

pip install -r requirements.txt

Create a .env file:

OPENAI_API_KEY=sk-your-key
OPENAI_MODEL=gpt-4o

Start the server:

python app.py

The API runs at:

http://127.0.0.1:5000

API

Generate code

POST /api/generate-code

Request:

{
  "prompt": "Write a Python function that returns True."
}

Example:

curl -sS -X POST http://127.0.0.1:5000/api/generate-code \
  -H "Content-Type: application/json" \
  -d '{"prompt":"Write a Bash command that prints ping"}'

Response:

{
  "response": "echo ping",
  "message": "Copied to clipboard"
}

Answer a question or test

POST /api/test

Text request:

{
  "text": "What is the capital of France?"
}

Image request:

curl -sS -X POST http://127.0.0.1:5000/api/test \
  -F "images=@screenshot.png"

The endpoint returns plain text containing only the answer.

Clipboard script

send_prompt.sh reads the current clipboard content and sends either text or an image to the selected endpoint.

On macOS, install the required utilities:

brew install pngpaste jq

You can add aliases to ~/.zshrc:

alias send="/path/to/send_prompt.sh"
alias toggle_endpoint="/path/to/toggle_endpoint.sh"

Reload the shell configuration:

source ~/.zshrc

Run:

send

Switch between /api/generate-code and /api/test:

toggle_endpoint

macOS shortcut

To run the script with a keyboard shortcut:

  1. Open the Shortcuts app.
  2. Create a shortcut with the Run Shell Script action.
  3. Run /path/to/send_prompt.sh.
  4. Assign a keyboard shortcut.

The generated response will be copied to the clipboard automatically.

Notes

  • Clipboard images require pngpaste.
  • JSON requests are processed with jq.
  • Image input requires a model that supports vision.
  • Clipboard content is processed locally, but requests are sent to the configured OpenAI model.

About

A clipboard tool for sending text or images to GPT with a keyboard shortcut.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages