34 lines
676 B
Python
Executable File
34 lines
676 B
Python
Executable File
#!/usr/bin/env python3
|
|
import sys
|
|
import subprocess
|
|
from openai import OpenAI
|
|
|
|
def get_key():
|
|
user = subprocess.check_output(["whoami"]).decode().strip()
|
|
return subprocess.check_output([
|
|
"security",
|
|
"find-generic-password",
|
|
"-a", user,
|
|
"-s", "openai_api_key",
|
|
"-w"
|
|
]).decode().strip()
|
|
|
|
def main():
|
|
key = get_key()
|
|
client = OpenAI(api_key=key)
|
|
|
|
if not sys.stdin.isatty():
|
|
prompt = sys.stdin.read()
|
|
else:
|
|
prompt = " ".join(sys.argv[1:])
|
|
|
|
resp = client.responses.create(
|
|
model="gpt-4.1",
|
|
input=prompt
|
|
)
|
|
|
|
print(resp.output_text)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|