Init Python test
All checks were successful
Build and Push AI Image / build-and-push (push) Successful in 43s

This commit is contained in:
Zombori Péter
2025-12-03 13:13:42 +01:00
parent e7dc38b91e
commit 2220d6f7ca
8 changed files with 100 additions and 1 deletions

34
ai.py Normal file
View File

@@ -0,0 +1,34 @@
import os
import sys
from openai import OpenAI
def main():
api_key = os.getenv("OPENAI_API_KEY")
if not api_key:
print("ERROR: OPENAI_API_KEY environment variable is not set.", file=sys.stderr)
sys.exit(1)
# Az új OpenAI kliens automatikusan az OPENAI_API_KEY env-ből dolgozik
client = OpenAI()
prompt = "Please respond with exactly the string: hello world"
try:
response = client.responses.create(
model="gpt-4.1-mini",
input=prompt,
)
# Egyszerű, „naivan” kiszedjük a szöveget
msg = response.output[0].content[0].text
print("Model response:", msg)
except Exception as e:
print(f"ERROR while calling OpenAI API: {e}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()