import os
import requests
query = "How do I reset my API key?"
chunks = [
"To reset your API key, go to Dashboard > API Keys and click 'Regenerate'.",
"Our pricing plans start at $29/month for the Starter tier.",
"API keys are scoped to a single project. Each project can have up to 5 active keys.",
]
passages = {f"passage_{index}": chunk for index, chunk in enumerate(chunks)}
questions = {
passage_id: {
"type": "noul",
"instructions": f"Is {passage_id} relevant to answering the query?",
"criteria": {
"true": "Relevant to answering the query",
"false": "Not relevant to answering the query",
},
}
for passage_id in passages
}
response = requests.post(
"https://api.fastino.ai/v1/systemone",
headers={"X-API-Key": os.environ["FASTINO_API_KEY"]},
json={
"model": "fastino/GLiDE",
"state": {"query": query, "passages": passages},
"questions": questions,
},
timeout=300,
)
response.raise_for_status()
answers = response.json()["answers"]
scored_chunks = [
{
"chunk": passage,
"score": answers[passage_id]["noul"],
"confidence": answers[passage_id]["confidence"],
}
for passage_id, passage in passages.items()
]
top_chunks = sorted(scored_chunks, key=lambda item: item["score"], reverse=True)
relevant_chunks = [item for item in top_chunks if item["score"] > 0.5]