{"library":"langchain-classic","code":"import os\nfrom langchain.llms import OpenAI\nfrom langchain.prompts import PromptTemplate\nfrom langchain.chains import LLMChain\n\n# Set your OpenAI API key as an environment variable (e.g., export OPENAI_API_KEY=\"sk-...\")\n# For this example, we use os.environ.get to prevent errors if the key is not set.\nopenai_api_key = os.environ.get('OPENAI_API_KEY', '')\n\nif not openai_api_key:\n    print(\"Warning: OPENAI_API_KEY environment variable not set. Please set it to run the example.\")\n    print(\"Skipping LLM interaction.\")\nelse:\n    llm = OpenAI(openai_api_key=openai_api_key, temperature=0.7)\n\n    prompt = PromptTemplate(\n        input_variables=[\"topic\"],\n        template=\"Tell me a short, funny joke about {topic}.\"\n    )\n\n    chain = LLMChain(llm=llm, prompt=prompt)\n\n    try:\n        response = chain.run(\"developers\")\n        print(f\"Joke about developers:\\n{response}\")\n    except Exception as e:\n        print(f\"An error occurred during LLM interaction: {e}\")\n        print(\"Please ensure your OPENAI_API_KEY is valid and has access to the OpenAI API.\")\n","lang":"python","description":"This quickstart demonstrates a basic LLM interaction using an `LLMChain` with an OpenAI model and a `PromptTemplate`, typical of `langchain-classic` usage. Ensure `OPENAI_API_KEY` is set in your environment variables.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}