Skip to main content

YAMLLM

A Python library for YAML-based LLM configuration and execution.

Installation

pip install yamllm-core
uv add yamllm-core

Quick Start

In order to run a simple query, run a script as follows. NOTE: Printing of the response is not required as this is handles by the query method. This uses the rich library to print the responses in the console.

from yamllm import OpenAIGPT, GoogleGemini, DeepSeek, MistralAI
import os
import dotenv

dotenv.load_dotenv()

config_path = "path/to/config.yaml"

# Initialize LLM with config
llm = GoogleGemini(config_path=config_path, api_key=os.environ.get("GOOGLE_API_KEY"))

# Make a query
response = llm.query("Give me some boiler plate pytorch code please")

In order to have an ongoing conversation with the model, run a script as follows.

from yamllm import OpenAIGPT, GoogleGemini, DeepSeek, MistralAI
from rich.console import Console
import os
import dotenv

dotenv.load_dotenv()
console = Console()

config_path = "path/to/config.yaml"

llm = GoogleGemini(config_path=config_path, api_key=os.environ.get("GOOGLE_API_KEY"))

while True:
    try:          
        prompt = input("\nHuman: ")
        if prompt.lower() == "exit":
            break
        
        response = llm.query(prompt)
        if response is None:
            continue
        
    except FileNotFoundError as e:
        console.print(f"[red]Configuration file not found:[/red] {e}")
    except ValueError as e:
        console.print(f"[red]Configuration error:[/red] {e}")
    except Exception as e:
        console.print(f"[red]An error occurred:[/red] {str(e)}")

Working with Conversation History

You can view your conversation history using the ConversationStore class. This will display all messages in a tabulated format:

from yamllm import ConversationStore
import pandas as pd
from tabulate import tabulate

# Initialize the conversation store
history = ConversationStore("yamllm/memory/conversation_history.db")

# Retrieve messages and create a DataFrame
messages = history.get_messages()
df = pd.DataFrame(messages)

# Display messages in tabular format
print(tabulate(df, headers='keys', tablefmt='psql'))

Working with Vector Store

The vector store allows you to manage and inspect embedded vectors from your conversations:

from yamllm.memory import VectorStore

# Initialize the vector store
vector_store = VectorStore()

# Retrieve vectors and metadata
vectors, metadata = vector_store.get_vec_and_text()

# Display vector store information
print(f"Number of vectors: {len(vectors)}")
print(f"Vector dimension: {vectors.shape[1] if len(vectors) > 0 else 0}")
print(f"Number of metadata entries: {len(metadata)}")
print(metadata)

Tools

Available Tools

YAMLLM integrates a set of specialized tools to enhance functionality:

  • Calculator: Executes arithmetic and mathematical operations.
  • Web Search: Fetches up-to-date information from the internet. This use the DuckDuckGo API to search the internet.
  • Weather: Retrieves current weather conditions and forecasts. This uses the OpenWeatherMap API to retrieve the current temperature, wind speed, humidity and description.
  • Web Scraper: Extracts data from websites for further processing. This uses the beautiful soup library to parse the selected website.

These tools allow the library to handle queries that require real-time data, precise calculations, and dynamic content retrieval.

Configuration

YAMLLM uses YAML files for configuration. Set up a .config file to define the parameters for your LLM instance. This file should include settings such as the model type, temperature, maximum tokens, and system prompt.

Example configuration:

  # LLM Provider Settings
provider:
  name: "openai"  # supported: openai, google, deepseek and mistralai supported.
  model: "gpt-4o-mini"  # model identifier
  api_key: # api key goes here, best practice to put into dotenv
  base_url: # optional: for custom endpoints when using the google, deepseek or mistral

# Model Configuration
model_settings:
  temperature: 0.7
  max_tokens: 1000
  top_p: 1.0
  frequency_penalty: 0.0
  presence_penalty: 0.0
  stop_sequences: []
  
# Request Settings
request:
  timeout: 30  # seconds
  retry:
    max_attempts: 3
    initial_delay: 1
    backoff_factor: 2
    
# Context Management
context:
  system_prompt: "You are a helpful, conversational assistant with access to tools. 
    When asked questions about current events, news, calculations, or unit conversions, use the appropriate tool.
    For current information, use the web_search tool instead of stating you don't have up-to-date information.

    Always present information in a natural, conversational way:
    - For web search results, summarize the key points in your own words
    - For calculations, explain the result in plain language
    - For conversions, provide context about the conversion
    - Use a friendly, helpful tone throughout

    Do not show raw data or JSON in your responses unless specifically asked to do so."
  max_context_length: 16000
  memory:
    enabled: true
    max_messages: 10  # number of messages to keep in conversation history
    session_id: "session2"
    conversation_db: "memory/conversation_history.db"
    vector_store:
      index_path: "memory/vector_store/faiss_index.idx"
      metadata_path: "memory/vector_store/metadata.pkl"
      top_k: 3
    
# Output Formatting
output:
  format: "text"  # supported: text, json, markdown
  stream: false

logging:
  level: "INFO"
  file: "yamllm.log"
  format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"

# Tool Management 
tools:
  enabled: true
  tool_timeout: 10  # seconds
  tool_list: ['calculator', 'web_search', 'weather', 'web_scraper']

# Safety Settings
safety:
  content_filtering: true
  max_requests_per_minute: 60
  sensitive_keywords: []

Place the .config file in your project directory and reference it in your code to initialize the LLM instance.

Features

  • YAML-based configuration
  • Simple API interface
  • Customizable prompt templates
  • Error handling and retry logic
  • In built memory management in sqlite database for short term memory
  • Use of vector database for long term memory based on semantic search
  • Choose streaming or non-streamed response

License

MIT License

Metadata

Release files for yamllm-core 0.1.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yamllm-core 0.1.12
File Size Uploaded Provenance
yamllm_core-0.1.12.tar.gz 146.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for yamllm-core 0.1.12
File Interpreter ABI Platform
yamllm_core-0.1.12-py3-none-any.whl Python 3 none any Details

Total release size: 175.0 kB

Release files / yamllm_core-0.1.12.tar.gz

Download URL yamllm_core-0.1.12.tar.gz
Size 146.2 kB
Tags Source
SHA-256 checksum
How to use checksums
951e3643b3870fafaec029ed29024c91d6d845a34baf6047f6eb26b9ba336aef
BLAKE2b-256 checksum
How to use checksums
ceda127c6dc21bfe77492875a39c506de4240a3f9ef3be789e0ccefbe8640b4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.10

Release files / yamllm_core-0.1.12-py3-none-any.whl

Download URL yamllm_core-0.1.12-py3-none-any.whl
Size 28.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f3777290142d0bd93bdb76802ec32eabe49941ef98886c8e388ea3b910145a2
BLAKE2b-256 checksum
How to use checksums
c5ab9a4d9e4e97d409b248a1d9a9e8a81ca05f511e0e0c10d84143ca8a7b22e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.10

Security for yamllm-core 0.1.12

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page