Skip to main content

This library offers functionality to cleanly extract JSON from LLM responses and generate prompts for LLM that return JSON. It features a simple implementation while maintaining high versatility.

Project description

lite_llm_json

Description

The library has functionality to cleanly extract JSON from LLM responses and generate prompts for LLM that return JSON. It features a simple yet versatile implementation.

Installation

pip install LiteLLMJson

HowToUse

import openai
from lite_llm_json import LiteLLMJson

# Set the OpenAI API key
api_key = "YOUR_API_KEY"
openai.api_key = api_key

# Define the JSON schema
json_schema = {
    "type": "object",
    "properties": {"name": {"type": "string"}, "age": {"type": "integer"}},
    "required": ["name", "age"],
}
# Instantiate the LiteLLMJson class
llm_json = LiteLLMJson(json_schema)

# Define the query prompt
query_prompt = """## Instructions:
Provide information about a person."""

# Get the generated prompt
generated_prompt = llm_json.generate_prompt(query_prompt)

# Use the OpenAI API to get a completion
response = openai.Completion.create(
    engine="text-davinci-003",
    prompt=generated_prompt
)

# Get the output text
output_text = response["choices"][0]["text"]

# Parse the output text to obtain JSON data
json_data = llm_json.parse_response(output_text)

# Display the JSON data
print(json_data)

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

LiteLLMJson-0.0.3.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

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

LiteLLMJson-0.0.3-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file LiteLLMJson-0.0.3.tar.gz.

File metadata

  • Download URL: LiteLLMJson-0.0.3.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for LiteLLMJson-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ca3a0aee99c87b9245fb80d9abc643318a9d5f0bd6ecefd08b5661eeb1b92dac
MD5 2fdbf81ea60d62051fb1deb8357c22f4
BLAKE2b-256 6b7556ddd6af37e5d86e84af271242d261b08d2af6817e9e754568fc3ca12236

See more details on using hashes here.

File details

Details for the file LiteLLMJson-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: LiteLLMJson-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for LiteLLMJson-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d158fc31574afc6bdd0f6b74f633a0bf29f9924418e5603e5d4f2f5c7a816a45
MD5 161f8ed8bffa8db036f0b8f4274fbcde
BLAKE2b-256 127c1853d4713b12ae877c3ec8d66373829e15f9e1525609dd961096b2e0c524

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