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)
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.7.tar.gz
(3.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file LiteLLMJson-0.0.7.tar.gz.
File metadata
- Download URL: LiteLLMJson-0.0.7.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7dfb9e7020d1aa571343c83ccab4b8a438b59b21276b1b0499ef21593df94d8
|
|
| MD5 |
74847bcc102920673949bdb3766b1d92
|
|
| BLAKE2b-256 |
f5a829ed2502bf53da4f445aebed34f54df1c8736604def96ca085f257ca6822
|
File details
Details for the file LiteLLMJson-0.0.7-py3-none-any.whl.
File metadata
- Download URL: LiteLLMJson-0.0.7-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77ce0120883df8b3ccbf49820fdb883c657922d76368361be4f7f785ee125b1c
|
|
| MD5 |
a4395c5519daa3a8e686a61ee7e38c51
|
|
| BLAKE2b-256 |
12e45d3aa8931d5aa687a3db18227835bcacb602a0fdc586de6b2b86289d0c15
|