### Basic Installation of AbstractCore Source: https://context7_llms Installs the core AbstractCore library using pip. This is the fundamental step to begin using the library. ```bash pip install abstractcore ``` -------------------------------- ### Provider-Specific Installation for AbstractCore Source: https://context7_llms Installs AbstractCore with support for specific LLM providers using pip. This allows users to tailor their installation based on the LLM services they intend to use, reducing unnecessary dependencies. ```bash # OpenAI pip install abstractcore[openai] # Anthropic pip install abstractcore[anthropic] # Ollama (local models) pip install abstractcore[ollama] # LMStudio (local models) pip install abstractcore[lmstudio] # MLX (Apple Silicon) pip install abstractcore[mlx] # HuggingFace pip install abstractcore[huggingface] # Server support pip install abstractcore[server] # Embeddings pip install abstractcore[embeddings] # Everything pip install abstractcore[all] ``` -------------------------------- ### AbstractCore: Advanced Universal Tool Calling Example Source: https://context7_llms Provides a more comprehensive example of AbstractCore's universal tool calling, showcasing the integration of multiple tools (`get_weather` and `calculate`) with a local Ollama model. This highlights the library's ability to abstract provider-specific complexities. ```python from abstractcore import create_llm, tool @tool def get_weather(city: str) -> str: """Get current weather for a specified city.""" return f"Weather in {city}: 72°F, Sunny" @tool def calculate(expression: str) -> float: """Perform mathematical calculations.""" return eval(expression) # Simplified for demo # Works with ANY provider - OpenAI, Anthropic, Ollama, etc. llm = create_llm("ollama", model="qwen3:4b-instruct-2507-q4_K_M") response = llm.generate( "What's the weather in Tokyo and what's 15 * 23?", tools=[get_weather, calculate] ) ``` -------------------------------- ### Bash: Starting the AbstractCore HTTP Server Source: https://context7_llms Provides the command to start the AbstractCore HTTP server using `uvicorn`. This server provides an OpenAI-compatible REST API, allowing integration with any OpenAI-compatible client. The command specifies the host and port for the server to listen on. ```bash # Start server uvicorn abstractcore.server.app:app --host 0.0.0.0 --port 8000 ``` -------------------------------- ### Bash: CLI Applications for Document Summarization and Knowledge Graph Extraction Source: https://context7_llms Provides examples of using the command-line interface (CLI) for document summarization and knowledge graph extraction. These commands allow users to specify styles, lengths, focus areas, output formats, and other parameters without writing Python code. The `--verbose` flag can be used for more detailed output. ```bash # Document summarization with multiple styles and lengths summarizer document.pdf --style executive --length brief --output summary.txt summarizer report.txt --focus "technical details" --chunk-size 15000 --verbose # Knowledge graph extraction with various formats and modes extractor research_paper.pdf --format json-ld --focus technology --iterate 3 --mode thorough extractor article.txt --entity-types person,organization,location --output entities.jsonld --minified extractor large_doc.txt --mode fast --no-embeddings --timeout 600 --max-tokens 32000 ``` -------------------------------- ### Python: Tool Chaining with Multiple Tools Source: https://context7_llms Illustrates how to chain tools together in Python using the `@tool` decorator. This example shows two tools, `get_user_location` and `get_weather`, and how an LLM can use them sequentially by passing the output of the first tool as input to the second. ```python from abstractcore.tools import tool @tool def get_user_location(user_id: str) -> str: """Get the location of a user.""" locations = {"user123": "Paris", "user456": "Tokyo"} return locations.get(user_id, "Unknown") @tool def get_weather(city: str) -> str: """Get weather for a city.""" return f"Weather in {city}: 72°F, sunny" # Assuming 'llm' is an initialized language model instance # response = llm.generate( # "What's the weather like for user123?", # tools=[get_user_location, get_weather] # ) # LLM will first call get_user_location, then get_weather with the result ``` -------------------------------- ### Bash: Debugging LLM Responses with AbstractCore CLI Source: https://context7_llms Illustrates how to use the `judge` CLI command with the `--debug` flag to inspect raw LLM responses. This is useful for troubleshooting issues with specific providers or models. The example shows debugging a response from `lmstudio` with the `qwen/qwen3-next-80b` model. ```bash # Debug raw LLM responses for troubleshooting judge document.txt --debug --provider lmstudio --model qwen/qwen3-next-80b ``` -------------------------------- ### Python: Enhance Tool Metadata with @tool Decorator Source: https://context7_llms Demonstrates how to use the `@tool` decorator in Python to add rich metadata to functions, which is automatically injected into system prompts. This includes descriptions, tags, usage guidance, and examples, facilitating better LLM interaction with tools. ```python from abstractcore.tools import tool @tool( description="Search the database for records matching the query", tags=["database", "search", "query"], when_to_use="When the user asks for specific data from the database", examples=[ { "description": "Find all users named John", "arguments": { "query": "name=John", "table": "users" } } ] ) def search_database(query: str, table: str = "users") -> str: """Search the database for records matching the query.""" return f"Searching {table} for: {query}" ``` -------------------------------- ### Basic LLM Usage with AbstractCore Source: https://context7_llms Demonstrates the fundamental usage of AbstractCore by creating an LLM instance and generating a simple text response. It highlights the flexibility of specifying different LLM providers. ```python from abstractcore import create_llm # Basic Usage - Works with any provider llm = create_llm("openai", model="gpt-4o-mini") # or "anthropic", "ollama", etc. response = llm.generate("What is the capital of France?") print(response.content) ``` -------------------------------- ### Python: Basic Session Management with AbstractCore Source: https://context7_llms Demonstrates basic session management in Python using AbstractCore's `BasicSession`. It shows how to initialize a session with an LLM and system prompt, generate responses that maintain context across turns, and save/load sessions with optional analytics. ```python from abstractcore import BasicSession, create_llm llm = create_llm("openai", model="gpt-4o-mini") session = BasicSession(llm, system_prompt="You are a helpful assistant.") response1 = session.generate("My name is Alice") response2 = session.generate("What's my name?") # Remembers context # Save with analytics session.save("conversation.json", summary=True, assessment=True, facts=True) # Load session loaded_session = BasicSession.load("conversation.json") ``` -------------------------------- ### Python: Interacting with the OpenAI-Compatible HTTP Server Source: https://context7_llms Shows how to use the `openai` Python client to interact with the AbstractCore HTTP server. By setting the `base_url` to the server's address and using a placeholder API key, clients can send requests to the server, routing them to any specified LLM provider. This enables leveraging AbstractCore's capabilities through a familiar OpenAI interface. ```python # Use with any OpenAI-compatible client import openai client = openai.OpenAI(base_url="http://localhost:8000/v1", api_key="unused") response = client.chat.completions.create( model="ollama/qwen3-coder:30b", # Route to any provider messages=[{"role": "user", "content": "Hello!"}] ) ``` -------------------------------- ### Bash: CLI Applications for Text Evaluation and Debugging Source: https://context7_llms Illustrates the usage of the CLI for text evaluation, including specifying criteria, context, and output formats. It also demonstrates the `--debug` flag for troubleshooting and mentions the automatic JSON self-repair capabilities for handling malformed responses. The `--focus` parameter allows for targeted evaluation. ```bash # Text evaluation with focus areas and debug capabilities judge essay.txt --criteria clarity,accuracy,coherence --context "academic writing" --include-criteria judge code.py --context "code review" --format plain --verbose --debug judge README.md --focus "technical accuracy,examples" --temperature 0.05 --max-output-tokens 8000 ``` -------------------------------- ### Python: Programmatic Use of AbstractCore Processing APIs Source: https://context7_llms Demonstrates how to use the AbstractCore processing tools programmatically within Python scripts. It shows instantiation of `BasicSummarizer`, `BasicExtractor`, and `BasicJudge` classes and their respective methods for performing summarization, knowledge graph extraction, and text evaluation. The code highlights passing parameters like `style`, `output_format`, and `context`. ```python from abstractcore.processing import BasicSummarizer, BasicExtractor, BasicJudge # Use programmatically summarizer = BasicSummarizer() summary = summarizer.summarize(text, style="executive", length="brief") extractor = BasicExtractor() kg = extractor.extract(text, output_format="jsonld") judge = BasicJudge() assessment = judge.evaluate(text, context="code review", focus="error handling") ``` -------------------------------- ### Python: Event System for Tool Execution Monitoring Source: https://context7_llms Demonstrates how to use AbstractCore's event system in Python to monitor and control tool execution. It shows how to register global event handlers for specific event types like `GENERATION_COMPLETED` and `TOOL_STARTED` to implement custom logic, such as cost monitoring or preventing dangerous tool calls. ```python from abstractcore.events import EventType, on_global def cost_monitor(event): if event.cost_usd and event.cost_usd > 0.10: # Assuming 'alert' function is defined elsewhere # alert(f"High cost request: ${event.cost_usd}") pass # Placeholder for alert function def prevent_dangerous_tools(event): for call in event.data.get('tool_calls', []): if call.name in ['delete_file', 'system_command']: event.prevent() # Stop execution # Register event handlers on_global(EventType.GENERATION_COMPLETED, cost_monitor) on_global(EventType.TOOL_STARTED, prevent_dangerous_tools) ``` -------------------------------- ### Session Management with BasicSession in AbstractCore Source: https://context7_llms Illustrates how to use AbstractCore's `BasicSession` for managing conversational context. This allows the LLM to remember previous messages in a conversation, facilitating multi-turn interactions. ```python from abstractcore import create_llm, BasicSession session = BasicSession(llm, system_prompt="You are a helpful assistant.") session.add_message('user', 'My name is Alice') response = session.generate('What is my name?') # Remembers context ``` -------------------------------- ### Streaming Responses with AbstractCore Source: https://context7_llms Demonstrates how to receive streaming responses from the LLM, enabling real-time output for interactive applications. The `stream=True` argument activates this functionality. ```python for chunk in llm.generate("Tell me a story", stream=True): print(chunk.content, end="", flush=True) ``` -------------------------------- ### Universal Tool Calling in AbstractCore Source: https://context7_llms Illustrates AbstractCore's universal tool calling capability, allowing custom functions decorated with '@tool' to be used with any LLM provider. This feature simplifies integrating external logic into LLM workflows. ```python from abstractcore import create_llm, tool @tool def get_weather(city: str) -> str: """Get current weather for a city.""" return f"Weather in {city}: 72°F, Sunny" response = llm.generate("What's the weather in Paris?", tools=[get_weather]) ``` -------------------------------- ### Python: Configure Tool Syntax Rewriting for CLIs Source: https://context7_llms Shows how to configure tool syntax rewriting in Python for compatibility with different agentic CLIs. It demonstrates setting custom tool call tags and using predefined tag rewriters for formats like 'codex', 'crush', and 'gemini'. ```python from abstractcore.tools.tag_rewriter import create_tag_rewriter from abstractcore import create_llm # Custom tag configuration llm_custom = create_llm( "ollama", model="qwen3-coder:30b", tool_call_tags="mytag" # Becomes: ...JSON... ) # Predefined CLI formats # Codex CLI rewriter_codex = create_tag_rewriter("codex") # Qwen3 format # Crush CLI rewriter_crush = create_tag_rewriter("crush") # LLaMA3 format # Gemini CLI rewriter_gemini = create_tag_rewriter("gemini") # XML format ``` -------------------------------- ### Python: Embedding Generation with AbstractCore Source: https://context7_llms Shows how to use AbstractCore's `EmbeddingManager` in Python to generate text embeddings. It covers initializing the manager with different providers (HuggingFace, Ollama, LMStudio) and models, and demonstrates embedding single strings and batches, as well as computing similarity. ```python from abstractcore.embeddings import EmbeddingManager # HuggingFace (default) embedder_hf = EmbeddingManager(model="sentence-transformers/all-MiniLM-L6-v2") # Ollama embedder_ollama = EmbeddingManager(model="granite-embedding:278m", provider="ollama") # LMStudio embedder_lmstudio = EmbeddingManager(model="text-embedding-all-minilm-l6-v2-embedding", provider="lmstudio") # Generate embeddings embedding = embedder_hf.embed("Hello world") embeddings = embedder_hf.embed_batch(["Hello", "World", "AI"]) # Similarity computation similarity = embedder_hf.compute_similarity("Hello", "Hi there") ``` -------------------------------- ### Structured Output with Pydantic in AbstractCore Source: https://context7_llms Shows how to leverage Pydantic models for structured output from LLM generations. AbstractCore automatically handles parsing the LLM's response into the specified Pydantic model, including retries for validation errors. ```python from abstractcore import create_llm from pydantic import BaseModel class Person(BaseModel): name: str age: int person = llm.generate("Extract: John Doe is 25", response_model=Person) print(f"{person.name}, age {person.age}") ``` -------------------------------- ### Bash: Alternative CLI Methods via Python Module Source: https://context7_llms Shows how to invoke the CLI applications indirectly using the `python -m` command. This method is useful for integrating the tools within Python scripts or environments where direct command execution might be less convenient. It mirrors the functionality of the direct CLI commands. ```bash # Method 1: Direct commands (recommended) summarizer document.txt --style executive extractor report.pdf --format triples judge essay.md --criteria soundness # Method 2: Via Python module python -m abstractcore.apps.summarizer document.txt --style executive python -m abstractcore.apps.extractor report.pdf --format triples python -m abstractcore.apps.judge essay.md --criteria soundness ``` -------------------------------- ### Python: Explicit Memory Management for Local LLMs Source: https://context7_llms Demonstrates explicit memory management when using local LLM providers. This involves creating an LLM instance, generating a response, and then explicitly unloading and deleting the instance to free up memory. This is crucial for managing resources with local models. ```python # Explicit memory management for local models llm = create_llm("ollama", model="large-model") response = llm.generate("Hello")llm.unload() # Free memory del llm ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.