Skip to main content

SceneProgLLM

SceneProgLLM is a powerful and versatile Python package that wraps around LangChain's LLM interface to provide enhanced functionality, including support for text, code, JSON, list, pydantic, image, speech and embedding response formats along with image inputs. This project is built to support SceneProg projects and supports both OpenAI (GPT) and Anthropic (Claude) backends — the right backend and API key are selected automatically based on the model_name you pass.


Features

  1. Flexible Response Formats:
    • Supports text, code, list, JSON, pydantic, image, speech and embedding outputs.
  2. Image Input and Output:
    • Accepts image inputs and enables image generation through OpenAI's image generation API.
  3. System Template:
    • Allows users to set a system description template containing placeholders which can be later filled with values.

Installation

To install the package and its dependencies, use the following command:

pip install sceneprogllm

For proper usage, create a .env file in the package root with the keys for the backends you intend to use:

OPENAI_API_KEY=<Your OpenAI key>
ANTHROPIC_API_KEY=<Your Anthropic key>

The backend is chosen from model_name: any model starting with claude (e.g. claude-opus-4-8, claude-sonnet-4-6, claude-haiku-4-5) uses Anthropic with ANTHROPIC_API_KEY; everything else (e.g. gpt-5-nano) uses OpenAI with OPENAI_API_KEY. You can still pass a key explicitly via api_key=....

Note: image, speech and embedding response formats are generated through OpenAI APIs regardless of model_name, since Anthropic does not provide equivalent endpoints. These always require OPENAI_API_KEY.

Getting Started

Importing the Package

from sceneprogllm import LLM

Usage Examples

  1. Generating Text Responses
llm = LLM(response_format="text")
response = llm("What is the capital of France?")
print(response)

>> The capital of France is Paris.
  1. Generating JSON Responses
llm = LLM(
    response_format="json",
    response_params=["capital":"str", "currency":"str"]
)
query = "What is capital and currency of India?"
response = llm(query)
print(response)

>> {'capital': 'New Delhi', 'currency': 'Indian Rupee'}
  1. Generating List Responses
llm = LLM(
   response_format="list",
)
query = "List G7 countries"
response = llm(query)
print(response)

>> ['Canada', 'France', 'Germany', 'Italy', 'Japan', 'United Kingdom', 'United States']
  1. Generating Pydantic Responses
from pydantic import BaseModel, Field
class mypydantic(BaseModel):
    country: str = Field(description="Name of the country")
    capital: str = Field(description="Capital city of the country")

llm = LLM(
    response_format="pydantic",
)
response = llm("What is the capital of France?", pydantic_object=mypydantic)
print(response)

>> country='France' capital='Paris'
  1. Generating Python Code
llm = LLM(response_format="code")
query = "Write a Python function to calculate factorial of a number."
response = llm(query)
print(response)

>>
def factorial(n):
    if n < 0:
        raise ValueError("Factorial is not defined for negative numbers")
    elif n == 0 or n == 1:
        return 1
    else:
        result = 1
        for i in range(2, n + 1):
            result *= i
        return result
  1. Generating images from text
llm = LLM(response_format="image", response_params={"size":"1024x1536", "quality":"auto"})
response = llm("Generate an image of a futuristic cityscape.")
response.save("futuristic_city.png")

>> 
  1. Generating speech from text
llm = LLM(response_format="speech", response_params={"output_path":"speech.wav", "voice":"coral"})
speech_path = llm("This is how I speak!")

>> 
  1. Generating embeddings from text
llm = LLM(response_format="embedding")
response = llm(["Hello World", "I like you"])

>> 
  1. Query using Images
llm = LLM(response_format="json", response_params=["count":"int"])
image_paths = ["assets/lions.png"]
response = llm("How many lions are there in the image?", image_paths=image_paths)
print(response)

>> {'count': 6}
  1. Generating images from text and image
llm = LLM(response_format="image", response_params={"size":"1024x1536", "quality":"auto"})
response = llm("Make the picture realistic", image_paths=["futuristic_city.png"])
response.save("real_futuristic_city.png")

>> 
  1. Set seed and temperature
llm = LLM(
         seed=0,
         temperature=1.0
         )
  1. Control behavious via system description
llm = LLM(
   system_desc="You are a funny AI assistant",
)
response = llm("What is the capital of France")
print(response)

>> 

Ah, the capital of France! That's Paris, the city of romance, lights, and baguettes longer than your arm! Just imagine the Eiffel Tower wearing a beret and saying, "Bonjour!"
  1. Using Template
from sceneprogllm import LLM
llm = LLM(
    system_desc="You are a helpful assistant. {description}",
)

response = llm("What is the capital of France?", system_desc_keys={"description": "You are a funny AI assistant"})
print(response)
  1. Using a Claude model
# Just change model_name — the Anthropic backend and ANTHROPIC_API_KEY are picked automatically.
llm = LLM(model_name="claude-sonnet-4-6", response_format="text")
response = llm("What is the capital of France?")
print(response)

# Structured outputs work the same across backends:
llm = LLM(model_name="claude-opus-4-8", response_format="json", response_params={"capital": "str"})
print(llm("What is the capital of India?"))

Queries

Please send your questions to k5gupta@ucsd.edu

Metadata

Release files for sceneprogllm 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sceneprogllm 0.4.0
File Size Uploaded Provenance
sceneprogllm-0.4.0.tar.gz 10.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for sceneprogllm 0.4.0
File Interpreter ABI Platform
sceneprogllm-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.9 kB

Release files / sceneprogllm-0.4.0.tar.gz

Download URL sceneprogllm-0.4.0.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
934bbbb9ade4a2ec935cb17029ddfde4ffe06faf75ec3f6d1f11957b8ad2ec62
BLAKE2b-256 checksum
How to use checksums
68fdee7ef7fc9eb65d320a89f97ad15e462c076da5280eb058896e30c41d9f74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release files / sceneprogllm-0.4.0-py3-none-any.whl

Download URL sceneprogllm-0.4.0-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1062cc156675cf41d82eaa5ec01e39a04d64aacb8de2f4a2211e72cd177e0561
BLAKE2b-256 checksum
How to use checksums
bb521bef6e159c5d5e3fd04c6e274950174b14e0ed3e54f3a48c1cc247d98100
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Security for sceneprogllm 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page