Skip to main content

An LLM wrapper built for scene prog projects

Project description

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 currently supports only OpenAI backend.


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 following fields:

OPENAI_API_KEY=<Your OpenAI 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)

Queries

Please send your questions to k5gupta@ucsd.edu

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sceneprogllm-0.3.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sceneprogllm-0.3.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file sceneprogllm-0.3.0.tar.gz.

File metadata

  • Download URL: sceneprogllm-0.3.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for sceneprogllm-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b52c817e08f33d50a94ac98f7312b0f140710466befc3aa3f59ac85316995428
MD5 bc0082b61423249061dd5fe1ca1a9605
BLAKE2b-256 89364c1863acac81a8b15896e92008eea45eaa385eafded4e0498e6ad5be2357

See more details on using hashes here.

File details

Details for the file sceneprogllm-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: sceneprogllm-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for sceneprogllm-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7f99766d13183ed9a03e7550265fcd174d185b7f10e63f9d6bcbc729cb2c2b51
MD5 1c91af1b464de4cfaa33ad62b7c2f5b2
BLAKE2b-256 7d4332c9c6e7f490a96db04c9b41e9a3d1d63c53db9938e6da286f32e3161775

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page