Skip to main content

A python package to interact with products from Lorica Cybersecurity

Project description

Lorica Package

Introduction

This package provides functionality for interaction with Lorica Cybersecurity products. The following capabilities are currently offered:

  • OHTTP encapsulation for secure interaction with Lorica AI deployment.

Lorica AI OHTTP Encapsulation using Requests Session

To encapsulate requests and responses through a requests.Session, simply replace the object construction with lorica.ohttp.Session:

import lorica.ohttp

# Create lorica.ohttp.Session that inherits from requests.Session.
session = lorica.ohttp.Session()

lorica_api_key = "LORICA_API_KEY"
deployment_url = "DEPLOYMENT_URL"

# Use session like a request.Session.
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": False,
    },
)
print(resp.text)

Lorica AI OHTTP Encapsulation using HTTPX Transport

To encapsulate requests and responses through a httpx.Transport, simply replace the object construction with lorica.ohttp.Transport:

import httpx
import lorica.ohttp

# Initialize httpx client with the lorica.ohttp.Transport that inherits from httpx.Transport
httpx_client = httpx.Client(transport=lorica.ohttp.Transport())

lorica_api_key = "LORICA_API_KEY"
deployment_url = "DEPLOYMENT_URL"

# Use client as normal including chunked-encoding response support.
method = "POST"
url = deployment_url
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": True,
}
headers = {"Authorization": f"Bearer {lorica_api_key}"}
with httpx_client.stream(method, url, json=data, headers=headers) as resp:
    print(resp.status_code)
    print(resp.headers)
    for chunk in resp.stream:
        print(chunk.decode(), end="", flush=True)

Lorica AI OHTTP Encapsulation using OpenAI Client

This is also applicable to clients that utilize httpx for their HTTP communication, for example openai client:

import httpx
import openai
import lorica.ohttp

# Initialize httpx client with lorica.ohttp.Transport that inherits from httpx.Transport
httpx_client = httpx.Client(transport=lorca.ohttp.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)
is_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.2,
    top_p=0.7,
    max_tokens=1024,
    stream=is_stream,
)
if is_stream:
    for chunk in completion:
        print(chunk.choices[0].delta.content or "", end="", flush=True)
else:
    print(completion.choices[0].message.content)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lorica-0.1a2.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lorica-0.1a2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file lorica-0.1a2.tar.gz.

File metadata

  • Download URL: lorica-0.1a2.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for lorica-0.1a2.tar.gz
Algorithm Hash digest
SHA256 370d5fe68d3e82e2063c1c23e2f2b47833c8384eb5999308c46472655bb1c116
MD5 983308e2cc23ddca934e7a64de1cff23
BLAKE2b-256 786fc8d4861a22d3c2d0236bf7369ab30e82a37c97a350e6b0a48a57ac65e2d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for lorica-0.1a2.tar.gz:

Publisher: CI.yml on Lorica-Cyber/lorica

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lorica-0.1a2-py3-none-any.whl.

File metadata

  • Download URL: lorica-0.1a2-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for lorica-0.1a2-py3-none-any.whl
Algorithm Hash digest
SHA256 88182500ee9292e52571c1ddd37fbd248ba941141a60162d9027462336913d3f
MD5 beeb837ee501ccba65c21f5dd8bfd2c5
BLAKE2b-256 9119c6f8d34015111628843a95a7f2b1259137ef423785ddf98ac48ff3be962c

See more details on using hashes here.

Provenance

The following attestation bundles were made for lorica-0.1a2-py3-none-any.whl:

Publisher: CI.yml on Lorica-Cyber/lorica

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page