LLM Factory
Een Python bibliotheek voor het eenvoudig werken met verschillende Large Language Models (LLM's) zoals Azure OpenAI, OpenAI, Llama, Cohere en Anthropic.
Installatie
pip install llm-factory
Voorbeeldgebruik
Basis gebruik
from llm_factory import LLMFactory
# Maak een LLM aan met Azure OpenAI
model = LLMFactory("azure_openai").model
# Genereer tekst
response = model.generate("Schrijf een kort verhaal over een robot.")
print(response)
Verschillende providers
# Azure OpenAI
azure_model = LLMFactory("azure_openai").model
# OpenAI
openai_model = LLMFactory("openai").model
# Llama
llama_model = LLMFactory("llama").model
# Anthropic (Claude)
claude_model = LLMFactory("anthropic").model
Configuratie
Environment Variables
Maak een .env bestand aan met de benodigde API keys en endpoints:
# Azure OpenAI
AZURE_OPENAI_API_KEY=your_key
AZURE_OPENAI_ENDPOINT=https://your-endpoint.openai.azure.com/
AZURE_OPENAI_CHAT_DEPLOYMENT=deployment_name
AZURE_OPENAI_EMBEDDING_DEPLOYMENT=embedding_deployment
AZURE_OPENAI_API_VERSION=2023-03-15-preview
# OpenAI
OPENAI_API_KEY=your_openai_key
# Anthropic
ANTHROPIC_API_KEY=your_anthropic_key
# Cohere
COHERE_API_KEY=your_cohere_key
Settings Configuratie (settings.py)
Maak een settings.py bestand aan in je project met de volgende configuratie:
from pathlib import Path
from typing import Optional
from pydantic import Field
from pydantic_settings import BaseSettings
from dotenv import load_dotenv
load_dotenv()
class LLMSettings(BaseSettings):
"""Basis instellingen voor Language Models."""
temperature: float = 0.0
max_tokens: Optional[int] = None
max_retries: int = 3
class OpenAISettings(LLMSettings):
"""OpenAI specifieke instellingen."""
api_key: str = Field(default_factory=lambda: os.getenv("OPENAI_API_KEY"))
default_model: str = "gpt-4-mini"
embedding_model: str = "text-embedding-3-small"
class AzureOpenAISettings(LLMSettings):
"""Azure OpenAI specifieke instellingen."""
api_key: str = Field(default_factory=lambda: os.getenv("AZURE_OPENAI_API_KEY"))
azure_endpoint: str = Field(default_factory=lambda: os.getenv("AZURE_OPENAI_ENDPOINT"))
default_model: str = Field(default_factory=lambda: os.getenv("AZURE_OPENAI_CHAT_DEPLOYMENT"))
embedding_model: str = Field(default_factory=lambda: os.getenv("AZURE_OPENAI_EMBEDDING_DEPLOYMENT"))
api_version: str = Field(default_factory=lambda: os.getenv("AZURE_OPENAI_API_VERSION"))
class LlamaSettings(LLMSettings):
"""Llama specifieke instellingen."""
api_key: str = "key" # Vereist maar niet gebruikt
default_model: str = "llama3.2"
base_url: str = "http://localhost:11434/v1" # Wordt aangepast voor Docker
class AnthropicSettings(LLMSettings):
"""Anthropic specifieke instellingen."""
api_key: str = Field(default_factory=lambda: os.getenv("ANTHROPIC_API_KEY"))
default_model: str = "claude-3-5-sonnet-20241022"
class Settings(BaseSettings):
"""Hoofdinstellingen die alle sub-instellingen combineert."""
openai: OpenAISettings = Field(default_factory=OpenAISettings)
azure_openai: AzureOpenAISettings = Field(default_factory=AzureOpenAISettings)
llama: LlamaSettings = Field(default_factory=LlamaSettings)
anthropic: AnthropicSettings = Field(default_factory=AnthropicSettings)
# Helper functie voor settings instantie
def get_settings() -> Settings:
"""Creëer en return een gecachede instantie van Settings."""
return Settings()
Docker Ondersteuning
Voor gebruik in Docker, wordt de Llama base_url automatisch aangepast:
def is_running_in_docker() -> bool:
return os.path.exists("/.dockerenv")
# In LlamaSettings
base_url = "http://host.docker.internal:11434/v1" if is_running_in_docker() else "http://localhost:11434/v1"
Metadata
Release files for llm-factory-tag 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| llm_factory_tag-0.2.0.tar.gz | 3.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llm_factory_tag-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 5.6 kB
Release files / llm_factory_tag-0.2.0.tar.gz
| Download URL | llm_factory_tag-0.2.0.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a60b09d6e921124e0b397bb3011c484fc6895acadece3f498227982fd931dcc9
|
|
BLAKE2b-256 checksum How to use checksums |
d1f19c3a99b46155d74054bb89af301c0e2fe2ad0ef9a1d026d280693616f04e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.6
|
Release files / llm_factory_tag-0.2.0-py3-none-any.whl
| Download URL | llm_factory_tag-0.2.0-py3-none-any.whl |
|---|---|
| Size | 2.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ef1d3d81aba2c21733b9df947e87ce2552765f0470c2bbac1e6df39a3cc97091
|
|
BLAKE2b-256 checksum How to use checksums |
f33f9ac172b51a0c4605863ca1671d2ed1523701b829ebbc1ebcde29531ae368
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.6
|
Security for llm-factory-tag 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.