{"library":"sap-ai-sdk-gen","title":"SAP AI SDK for Generative AI","description":"The SAP Cloud SDK for AI (Python) is designed to simplify interactions with generative AI APIs and services, particularly within the SAP ecosystem. It provides unified interfaces for various large language models (LLMs), enabling developers to easily integrate AI capabilities into their applications. The library is currently at version 6.7.0 and maintains a regular release cadence with updates and new features.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install sap-ai-sdk-gen"],"cli":null},"imports":["from sap_ai_sdk.generative_ai import GenerativeAI","from sap_ai_sdk.generative_ai.completion import Completion","from sap_ai_sdk.generative_ai.chat import Chat","from sap_ai_sdk.generative_ai.image_generation import ImageGeneration"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom sap_ai_sdk.generative_ai import GenerativeAI\nfrom sap_ai_sdk.generative_ai.completion import Completion\n\n# Set your API key as an environment variable (e.g., OPENAI_API_KEY).\n# For SAP AI Core, ensure AI_API_URL, AI_CLIENT_ID, AI_CLIENT_SECRET, AI_AUTH_URL are set.\n# Example: os.environ['OPENAI_API_KEY'] = os.environ.get('OPENAI_API_KEY', '') # For demo, ensure it's loaded.\n\ntry:\n    # Initialize the GenerativeAI client. It automatically detects configured providers.\n    ai_client = GenerativeAI()\n\n    # Get the completion service\n    completion_service: Completion = ai_client.get_completion_service()\n\n    prompt = \"Explain the concept of quantum entanglement in simple terms.\"\n    model_name = \"gpt-3.5-turbo\" # Use a model supported by your configured provider\n\n    print(f\"Requesting completion for model: {model_name}\")\n    response = completion_service.create(\n        prompt=prompt,\n        model_name=model_name,\n        # provider=\"openai\" # Optionally specify if multiple providers are configured\n    )\n\n    print(\"\\nGenerated Text:\")\n    print(response.text)\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure your environment variables (e.g., OPENAI_API_KEY) are correctly set\")\n    print(\"and that a suitable provider is configured for the chosen model.\")","lang":"python","description":"This quickstart demonstrates how to initialize the `GenerativeAI` client and use its `Completion` service. It relies on environment variables for API key configuration (e.g., `OPENAI_API_KEY`) and attempts to generate text using a specified model.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}