Een package om LLM modellen te initialiseren op basis van provider.
Project description
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"
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 llm_factory_tag-0.2.0.tar.gz.
File metadata
- Download URL: llm_factory_tag-0.2.0.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a60b09d6e921124e0b397bb3011c484fc6895acadece3f498227982fd931dcc9
|
|
| MD5 |
1abd02cbc11e5f44dc3c55b0945e1c50
|
|
| BLAKE2b-256 |
d1f19c3a99b46155d74054bb89af301c0e2fe2ad0ef9a1d026d280693616f04e
|
File details
Details for the file llm_factory_tag-0.2.0-py3-none-any.whl.
File metadata
- Download URL: llm_factory_tag-0.2.0-py3-none-any.whl
- Upload date:
- Size: 2.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef1d3d81aba2c21733b9df947e87ce2552765f0470c2bbac1e6df39a3cc97091
|
|
| MD5 |
020cf2f02e741597806c12c840851f70
|
|
| BLAKE2b-256 |
f33f9ac172b51a0c4605863ca1671d2ed1523701b829ebbc1ebcde29531ae368
|