A python package to interact with products from Lorica Cybersecurity
Project description
Lorica Package
Introduction
This package provides functionality for interacting with Lorica Cybersecurity products. The following capabilities are currently offered:
- Attestation and OHTTP Public Key verification for Lorica AI deployment.
- OHTTP encapsulation for secure interaction with Lorica AI deployment.
Lorica AI Interaction using Requests Session
To interact with a Lorica AI deployment through a requests.Session, simply replace the object construction with lorica.Session:
import lorica
import json
# Create lorica.Session that inherits from requests.Session.
session = lorica.Session()
deployment_url = "DEPLOYMENT_URL"
lorica_api_key = "LORICA_API_KEY"
# Use session like a request.Session including response streaming support.
stream = True
resp = session.post(
f"{deployment_url}/v1/chat/completions",
headers={"Authorization": f"Bearer {lorica_api_key}"},
json={
"model": "meta-llama/Llama-3.2-3B-Instruct",
"messages": [
{"role": "system", "content": "You are a helpful AI assistant."},
{"role": "user", "content": "where does the sun rise from?"},
],
"temperature": 0.7,
"max_tokens": 1024,
"stream": stream,
},
stream=stream
)
resp.raise_for_status()
if stream:
for line in resp.iter_lines(decode_unicode=True):
if not line or not line.startswith("data: "):
continue
data = line[len("data: "):].strip()
if data == "[DONE]":
break
chunk = json.loads(data)
print(chunk["choices"][0]["delta"]["content"], end="", flush=True)
else:
print(resp.json()["choices"][0]["message"]["content"])
Lorica AI Interaction using HTTPX Transport
To interact with a Lorica AI deployment through a httpx.Transport, simply replace the object construction with lorica.Transport:
import lorica
import httpx
import json
# Initialize httpx client with the lorica.Transport that inherits from httpx.Transport
httpx_client = httpx.Client(transport=lorica.Transport())
deployment_url = "DEPLOYMENT_URL"
lorica_api_key = "LORICA_API_KEY"
# Use client as normal including chunked-encoding response support.
method = "POST"
url = deployment_url + "/v1/chat/completions"
stream = True
data = {
"model": "meta-llama/Llama-3.2-3B-Instruct",
"messages": [
{"role": "system", "content": "You are a helpful AI assistant."},
{"role": "user", "content": "where does the sun rise from?"},
],
"temperature": 0.7,
"max_tokens": 1024,
"stream": stream,
}
headers = {"Authorization": f"Bearer {lorica_api_key}"}
if stream:
with httpx_client.stream(method, url, json=data, headers=headers) as resp:
resp.raise_for_status()
for line in resp.iter_lines():
if not line or not line.startswith("data: "):
continue
data = line[len("data: "):].strip()
if data == "[DONE]":
break
chunk = json.loads(data)
print(chunk["choices"][0]["delta"]["content"], end="", flush=True)
else:
resp = httpx_client.post(url, json=data, headers=headers, timeout=30)
resp.raise_for_status()
print(resp.json()["choices"][0]["message"]["content"])
Lorica AI Interaction using OpenAI Client
This is also applicable to clients that utilize httpx for their HTTP communication, for example openai client:
import lorica
import httpx
import openai
# Initialize httpx client with lorica.Transport that inherits from httpx.Transport
httpx_client = httpx.Client(transport=lorica.Transport())
deployment_url = "DEPLOYMENT_URL"
lorica_api_key = "LORICA_API_KEY"
# Configure OpenAI client with httpx client
client = openai.OpenAI(
api_key=lorica_api_key,
http_client=httpx_client,
base_url=deployment_url + "/v1")
# Use OpenAI SDK as normal for example llama chat (including stream capability)
stream = True
completion = client.chat.completions.create(
model="meta-llama/Llama-3.2-3B-Instruct",
messages=[
{"role": "system", "content": "You are a helpful AI assistant."},
{"role": "user", "content": "where does the sun rise from?"},
],
temperature=0.7,
max_tokens=1024,
stream=stream,
)
if stream:
for chunk in completion:
print(chunk.choices[0].delta.content or "", end="", flush=True)
else:
print(completion.choices[0].message.content)
Optional Parameter Configurability
The lorica.Transport and lorica.Session class constructors take in optional parameters:
- trustee_url: In our attestation flow, a Trustee service acts as the Verifier according to the RATS attestion procedure RFC9334. The classes default to use the Trustee deployed by Lorica but this parameter can be use to override the URL to point to any other Trustee instance.
- attest: This parameter can be used to disable the attestation flow in the absence of a Trustee service. We recommend keeping attestation ON unless the network route to the deployment is trusted.
Fetching the Attested Deployment Report
The lorica.Transport and lorica.Session classes provide a get_attested_deployment_report() method that takes in a deployment's URL to output the deployment's attestation report which features attested measurements of the deployment's hardware and software. This method only outputs a report if the deployment passes all Trustee and client-side checks as part of the attestation flow. The full JSON Web Token (JWT) issued by Trustee can also be accessed via the get_attestation_token() method.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 lorica-0.2a1.tar.gz.
File metadata
- Download URL: lorica-0.2a1.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e49efd10e0bd3e41b4b66ddac63af117bcc045b38c9824f5f8b93ebe75761758
|
|
| MD5 |
5bb130fb614569f5297814a1437d73c2
|
|
| BLAKE2b-256 |
4a266e33fa97937f58d139a6800fb572d90e94c969947df7d6e0052d7dce4751
|
Provenance
The following attestation bundles were made for lorica-0.2a1.tar.gz:
Publisher:
CI.yml on loricacyber/lorica
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lorica-0.2a1.tar.gz -
Subject digest:
e49efd10e0bd3e41b4b66ddac63af117bcc045b38c9824f5f8b93ebe75761758 - Sigstore transparency entry: 202119492
- Sigstore integration time:
-
Permalink:
loricacyber/lorica@1613b06eba868e56e95f19bb02bb1129375f57ba -
Branch / Tag:
refs/tags/v0.2a1 - Owner: https://github.com/loricacyber
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
CI.yml@1613b06eba868e56e95f19bb02bb1129375f57ba -
Trigger Event:
push
-
Statement type:
File details
Details for the file lorica-0.2a1-py3-none-any.whl.
File metadata
- Download URL: lorica-0.2a1-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1575680348a061e617a9391ef5ee61a9dcab6816c0044e6e39a77cd6f37ee619
|
|
| MD5 |
871999280196bebc552604e9013210f9
|
|
| BLAKE2b-256 |
1f3b7d7dd66ed0a28f1431b63a7a3b6b8d86afa0b2e8215a1299b9ee137065c5
|
Provenance
The following attestation bundles were made for lorica-0.2a1-py3-none-any.whl:
Publisher:
CI.yml on loricacyber/lorica
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lorica-0.2a1-py3-none-any.whl -
Subject digest:
1575680348a061e617a9391ef5ee61a9dcab6816c0044e6e39a77cd6f37ee619 - Sigstore transparency entry: 202119500
- Sigstore integration time:
-
Permalink:
loricacyber/lorica@1613b06eba868e56e95f19bb02bb1129375f57ba -
Branch / Tag:
refs/tags/v0.2a1 - Owner: https://github.com/loricacyber
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
CI.yml@1613b06eba868e56e95f19bb02bb1129375f57ba -
Trigger Event:
push
-
Statement type: