Init Python test
All checks were successful
Build and Push AI Image / build-and-push (push) Successful in 43s
All checks were successful
Build and Push AI Image / build-and-push (push) Successful in 43s
This commit is contained in:
34
ai.py
Normal file
34
ai.py
Normal 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()
|
||||
Reference in New Issue
Block a user