Skip to main content

Lightweight wrapper for cortecs.ai enabling ⚡️ instant provisioning

Project description

cortecs-py

PyPI Version Python Versions Downloads Workflow Status Documentation Join our Discord

Lightweight wrapper for the cortecs.ai enabling instant provisioning.

⚡Quickstart

Dynamic provisioning allows you to run LLM-workflows on dedicated compute. The LLM and underlying resources are automatically provisioned for the duration of use, providing maximum cost-efficiency. Once the workflow is complete, the infrastructure is automatically shut down.

This library starts and stops your resources. The logic can be implemented using popular frameworks such as LangChain or crewAI.

  1. Start your LLM
  2. Execute (massive batch) jobs
  3. Shutdown your LLM
from cortecs_py.client import Cortecs
from cortecs_py.integrations.langchain import DedicatedLLM

cortecs = Cortecs()

with DedicatedLLM(client=cortecs, model_name='cortecs/phi-4-FP8-Dynamic') as llm:
    essay = llm.invoke('Write an essay about dynamic provisioning')
    print(essay.content)

Example

Install

pip install cortecs-py

Summarizing documents

First, set up the environment variables. Use your credentials from cortecs.ai.

export OPENAI_API_KEY="<YOUR_CORTECS_API_KEY>"
export CORTECS_CLIENT_ID="<YOUR_ID>"
export CORTECS_CLIENT_SECRET="<YOUR_SECRET>"

This example shows how to use LangChain to configure a simple summarization chain. The llm is dynamically provisioned and the chain is executed in parallel.

from langchain_community.document_loaders import ArxivLoader
from langchain_core.prompts import ChatPromptTemplate

from cortecs_py.client import Cortecs
from cortecs_py.integrations.langchain import DedicatedLLM

cortecs = Cortecs()
loader = ArxivLoader(
    query="reasoning",
    load_max_docs=40,
    get_ful_documents=True,
    doc_content_chars_max=25000,  # ~6.25k tokens, make sure the models supports that context length
    load_all_available_meta=False
)

prompt = ChatPromptTemplate.from_template("{text}\n\n Explain to me like I'm five:")
docs = loader.load()

with DedicatedLLM(client=cortecs, model_name='cortecs/phi-4-FP8-Dynamic') as llm:
    chain = prompt | llm

    print("Processing data batch-wise ...")
    summaries = chain.batch([{"text": doc.page_content} for doc in docs])
    for summary in summaries:
        print(summary.content + '-------\n\n\n')

This simple example showcases the power of dynamic provisioning. We summarized 224.2k input tokens into 12.9k output tokens in 55 seconds. The llm can be fully utilized in those 55 seconds enabling better cost efficiency. Comparing to serverless open source model providers we observe the following:

Price Comparison (USD) Price Comparison per Million Tokens (USD)

Use Cases

For more information see our docs or join our discord.

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

cortecs_py-0.1.1.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

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

cortecs_py-0.1.1-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file cortecs_py-0.1.1.tar.gz.

File metadata

  • Download URL: cortecs_py-0.1.1.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for cortecs_py-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5f6f6e29af784490983fbfc261a7e0d97620d04ca7b51eb85c6250c2f50c5c11
MD5 a99eeeb44e1f76418741d94eb10f679d
BLAKE2b-256 d8044e5bf9720bcc57400e5be6e2f4bb7c72fd3d617fd63b601265034c5db4bd

See more details on using hashes here.

File details

Details for the file cortecs_py-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: cortecs_py-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for cortecs_py-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6c9c0556cc4639c5ccb83c06f5fa9b4cdbb4f0c83df99630f03abdf2bea8492d
MD5 c5dfd865dd092b53dd1d0840593da9f8
BLAKE2b-256 7a53ec5e4e050cd6e571fba33ca43187a037b615c67c9c974ef591c17c8e08b9

See more details on using hashes here.

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