The platform to prototype, evaluate, improve, and observe your LLM app or feature.
Developers use Inductor to ship high-quality LLM-powered functionality
rapidly and reliably.
# In app.py (your existing LLM app code)
import inductor
from openai import OpenAI
client = OpenAI()
def document_qa(question: str):
"""Answer a question about our documents."""
document_snippets = retrieve_from_vector_db(
question, num_snippets=10)
system_message = (
"You are a helpful document QA assistant. "
"Using only the following document snippets, answer any "
"question asked.\n\n"
"Document snippets:\n\n" +
"\n\n".join(document_snippets))
response = client.chat.completions.create(
messages=[
{"role": "system", "content": system_message},
{"role": "user", "content": question}],
model="gpt-4o")
return response.choices[0].message.content
# In your terminal
$ inductor playground app:document_qa
# In test_suite.py
import app
import inductor
test_suite = inductor.TestSuite(
id_or_name="document_qa", llm_program=app.document_qa)
test_suite.add(
# Add test cases
inductor.TestCase(
inputs={"question": "What is the name of the company?"}),
inductor.TestCase(
inputs={"question": ("Explain how to use the company's "
"product in detail.")}),
# Add quality measure
inductor.QualityMeasure(
name="Answer is correct and relevant",
evaluator="HUMAN",
evaluation_type="BINARY",
spec="Is the answer correct AND relevant to the question asked?"))
# You can set evaluator="LLM" or evaluator="FUNCTION" to use
# LLM-powered or programmatic evaluations, respectively.
if __name__ == "__main__":
test_suite.run()
# In test_suite.yaml
# Test suite configuration
- config:
name: document_qa
llm_program_fully_qualified_name: app:document_qa
# Test cases
- test_case:
inputs:
question: What is the name of the company?
- test_case:
inputs:
question: Explain how to use the company's product in detail.
# Quality measure
- quality:
name: Answer is correct and relevant
evaluator: HUMAN
evaluation_type: BINARY
spec: Is the answer correct AND relevant to the question asked?
# In your terminal (to run test suite)
$ python test_suite.py
# In your terminal (to run test suite)
$ inductor test test_suite.yaml
# In app.py (your existing LLM app code)
def document_qa(question: str):
"""Answer a question about our documents."""
document_snippets = retrieve_from_vector_db(
question,
num_snippets=inductor.hparam("num_snippets", default_value=10))
prompt_header = inductor.hparam(
"prompt_header",
default_value=(
"You are a helpful document QA assistant. "
"Using only the following document snippets, answer any "
"question asked."))
system_message = (
f"{prompt_header}\n\n"
"Document snippets:\n\n" +
"\n\n".join(document_snippets))
response = client.chat.completions.create(
messages=[
{"role": "system", "content": system_message},
{"role": "user", "content": question}],
model="gpt-4o")
return response.choices[0].message.content
# In test_suite.py
# Add hyperparameters
test_suite.add(
inductor.HparamSpec(
hparam_name="num_snippets",
hparam_type="NUMBER",
values=[5, 10, 15]),
inductor.HparamSpec(
hparam_name="prompt_header",
hparam_type="TEXT",
values=[
("You are a helpful document QA assistant. "
"Using only the following document snippets, answer any "
"question asked."),
("You are a document QA assistant. Use the following "
"document snippets to respond to questions concisely, "
"rejecting any unrelated or unanswerable questions.")]))
# In test_suite.yaml
# Hyperparameters
- hparam:
name: num_snippets
type: NUMBER
values: [5, 10, 15]
- hparam:
name: prompt_header
type: TEXT
values:
- |
You are a helpful document QA assistant.
Using only the following document snippets, answer any
question asked.
- |
You are a document QA assistant. Use the following
document snippets to respond to questions concisely,
rejecting any unrelated or unanswerable questions.
# In your terminal
$ python test_suite.py
# In your terminal
$ inductor test test_suite.yaml
# In app.py (your existing LLM app code)
@inductor.logger
# You can also pass quality measures and hyperparameter specs to the
# inductor.logger decorator to do continuous live evaluations and A/B testing.
def document_qa(question: str):
"""Answer a question about our documents."""
document_snippets = retrieve_from_vector_db(
question, num_snippets=10)
inductor.log(document_snippets, name="Document snippets")
system_message = (
"You are a helpful document QA assistant. "
"Using only the following document snippets, answer any "
"question asked.\n\n"
"Document snippets:\n\n" +
"\n\n".join(document_snippets))
response = client.chat.completions.create(
messages=[
{"role": "system", "content": system_message},
{"role": "user", "content": question}],
model="gpt-4o")
inductor.log(response.usage.model_dump(), name="Model token usage")
return response.choices[0].message.content