Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
This is the Opper Python SDK. See below for getting started, and the docs for more information. The SDK has builtin documentation and examples in function docstrings, which should be visible in your code editor as you are using the functions.
pip install opperai
OPPER_API_KEY
environment variable is read by the SDK if no api_key
is provided to the Client
object.from typing import List
from opperai import Index, Opper, trace
from opperai.types import DocumentIn
from opperai.types.indexes import DocumentIn, RetrievalResponse
from pydantic import BaseModel
class Answer(BaseModel):
steps: List[str]
class QuestionAndContext(BaseModel):
question: str
context: List[RetrievalResponse]
@trace
def answer_question(index: Index, question: str) -> Answer:
results = index.query(question, 1, None)
result, response = opper.call(
name="answer_question",
instructions="Answer the question and provide the steps to do so",
input=QuestionAndContext(question=question, context=results),
output_type=Answer,
)
response.span.save_metric("artificial_score", 5)
return result
@trace
def translate(answer: Answer, language: str) -> str:
result, _ = opper.call(
name="translate",
instructions="Translate the answer to the given language",
input=answer,
output_type=Answer,
)
return result
qna = [
{
"question": "I cannot log in to my account",
"answer": "Use the reset password feature by clicking on 'Forgot password?' and then follow the instructions from email",
"id": "1",
},
{
"question": "How can I see my invoices?",
"answer": "Go to the billing section and click on 'Invoices'",
"id": "2",
},
{
"question": "How can I add a new user to my account?",
"answer": "Upgrade account and add the user to your account",
"id": "3",
},
]
opper = Opper()
def index_qna(qnas: list[dict]):
index = opper.indexes.create("qna")
for qna in qnas:
index.add(
DocumentIn(
key=qna["id"],
content=f"question: {qna['question']}\nanswer: {qna['answer']}",
metadata={
"id": qna["id"],
},
)
)
return index
def run():
index = index_qna(qna)
question = "How can I see my invoices?"
with opper.traces.start("answer_question") as trace:
answer = answer_question(index, question)
print(answer)
run()
See examples in our documentation and examples folder.
FAQs
Opper Python client
We found that opperai demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.