Skip to main content

LLM plugin for Glueco Gateway SDK - Typed chat completions for OpenAI, Groq, Gemini

Project description

Glueco LLM Plugin

PyPI version Python 3.10+

Typed LLM chat completions for the Glueco Gateway SDK.

Installation

pip install glueco-plugin-llm

Quick Start

from glueco_sdk import GatewayClient, FileKeyStorage, FileConfigStorage
from glueco_plugin_llm import llm_client

# Setup gateway client
client = GatewayClient(
    key_storage=FileKeyStorage(".gateway/keys.json"),
    config_storage=FileConfigStorage(".gateway/config.json"),
)

# Get transport and create LLM client
transport = client.get_transport()
llm = llm_client(transport)

# Make chat completion
response = llm.chat_completions(
    provider="groq",
    model="llama-3.1-8b-instant",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello!"},
    ],
    temperature=0.7,
)

print(response.content)

Streaming

for chunk in llm.chat_completions_stream(
    provider="groq",
    model="llama-3.1-8b-instant",
    messages=[{"role": "user", "content": "Tell me a story"}],
):
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

Supported Providers

Provider Resource ID Models
OpenAI llm:openai gpt-4o, gpt-4o-mini, etc.
Groq llm:groq llama-3.1-8b-instant, llama-3.1-70b, etc.
Gemini llm:gemini gemini-1.5-flash, gemini-1.5-pro, etc.

Types

from glueco_plugin_llm import (
    ChatMessage,
    ChatCompletion,
    ChatCompletionChoice,
    ChatCompletionUsage,
)

# Create typed messages
messages = [
    ChatMessage(role="system", content="You are helpful."),
    ChatMessage(role="user", content="Hello!"),
]

# Response is fully typed
response: ChatCompletion = llm.chat_completions(...)
print(response.id)
print(response.model)
print(response.choices[0].message.content)
print(response.usage.total_tokens)

API Reference

llm_client(transport)

Factory function to create an LLM client.

LLMClient

llm.chat_completions(
    provider: str,          # "openai", "groq", "gemini"
    model: str,             # Model name
    messages: list,         # Conversation messages
    temperature: float,     # Optional (0.0-2.0)
    max_tokens: int,        # Optional
    response_format: dict,  # Optional
    **kwargs,               # Provider-specific params
) -> ChatCompletion

llm.chat_completions_stream(...) -> Iterator[ChatCompletionChunk]

License

MIT

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

glueco_plugin_llm-0.1.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

glueco_plugin_llm-0.1.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file glueco_plugin_llm-0.1.0.tar.gz.

File metadata

  • Download URL: glueco_plugin_llm-0.1.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for glueco_plugin_llm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1bd47e8a211fb13750087aeda93d892978d7ae6d0f995c8b3671af640a293569
MD5 6de2cacaf73c1e32abdccb4378e60cde
BLAKE2b-256 6c20acd6d7fbd2be7ed69e9b465a0e6993d47601fbe0d2ac53324c7032dcebe7

See more details on using hashes here.

File details

Details for the file glueco_plugin_llm-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for glueco_plugin_llm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 03393027d94948c6832bb3b27eb0ba666c80db620d59f6ce2dfffb5b4a861d34
MD5 47ac0c45f53e640bd44e9787c07eca38
BLAKE2b-256 09e665fdcf8f23b0d1b2f25cfec38efe023cf2d68741487d68f9ac6d525d1780

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