Skip to main content

A powerful and flexible LLM interface library for Gemini and other models.

Project description

RAW Project

A powerful and flexible LLM interface library for Gemini and other models, designed for modern Python applications, featuring a robust Agent framework.

Features

  • Gemini Integration: Seamless support for Google's Gemini models (default: gemini-1.5-flash).
  • Unified Interface: Clean, consistent API for chat, completion, and tool usage.
  • Agent Framework: Build autonomous agents with tool-calling capabilities.
  • Async Support: Fully asynchronous implementation using httpx and asyncio.
  • Tool Calling: Easy-to-use function calling/tool usage with schema generation.
  • Streaming: Native support for streaming responses.

Installation

pip install raw

or with uv:

uv add raw

Quick Start / Documentation

1. Using LLMs

The project supports LLMs via the BaseLLM interface. The primary implementation provided is GeminiLLM.

Initialization

To use GeminiLLM, you need a Google Gemini API key.

import os
from RAW.llms.gemini import GeminiLLM
from RAW.utils import Logger

# Check/Set API Key
api_key = os.environ.get("GEMINI_API_KEY")
if not api_key:
    raise ValueError("GEMINI_API_KEY not set")

# Optional: Configure Logger
logger = Logger("MyLLM")

# Initialize
# Default model: gemini-1.5-flash (configurable via model argument)
llm = GeminiLLM(api_key=api_key, logger=logger, model="gemini-1.5-flash")

Basic Chat

You can interact with the LLM using the chat method, which accepts a list of Message objects.

from RAW.modals import Message

messages = [
    Message(role="user", content="Hello, who are you?")
]

# Non-streaming
response = await llm.chat(messages=messages)
print(response.content)

# Streaming
async for chunk in await llm.chat(messages=messages, stream=True):
    print(chunk.content)

2. Making Tools

Tools allow the Agent to perform actions or retrieve information. A Tool consists of a name, description, parameters, and a python function.

Define the Function

Create an async function that performs the desired action.

async def get_weather(location: str):
    """Fetches weather for a given location."""
    # Your logic here (e.g., API call)
    return f"The weather in {location} is sunny."

Define the Tool Definition

Wrap the function in a Tool object, specifying its schema using ToolParam.

from RAW.modals import Tool
from RAW.modals.tools import ToolParam

weather_tool = Tool(
    name="get_weather",
    description="Get the weather for a specific location",
    parameters=[
        ToolParam(
            name="location",
            type="string",
            description="City and State, e.g. New York, NY",
            required=True
        )
    ],
    function=get_weather
)

3. Making an Agent

The Agent orchestrates the interaction between the LLM, Tools, and the User. It manages the conversation history and tool execution loop.

Initialization

Combine the LLM and Tools into an Agent.

from RAW.agent import Agent

agent = Agent(
    name="WeatherBot",
    base_prompt="You are a helpful assistant that can check the weather.",
    tools=[weather_tool], # List of Tool objects
    llm=llm,              # The LLM instance
    logger=logger         # Optional logger
)

Running the Agent

The agent is callable. You can run it in a loop to handle user input.

user_input = "What is the weather in London?"

# The agent returns a generator yielding chunks of the response
async for chunk in agent(user_input, stream=True):
    # 'chunk' can be a dictionary containing content or tool execution status
    if isinstance(chunk, dict) and 'content' in chunk:
        content_obj = chunk['content']
        # content_obj might be a Message dump or a string
        if isinstance(content_obj, dict) and 'content' in content_obj:
             print(content_obj['content'], end="", flush=True)

Full Example

See main.py in the project root for a complete, runnable example of a Chatbot Agent.

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

raw_agents-0.1.5.tar.gz (126.3 kB view details)

Uploaded Source

Built Distribution

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

raw_agents-0.1.5-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file raw_agents-0.1.5.tar.gz.

File metadata

  • Download URL: raw_agents-0.1.5.tar.gz
  • Upload date:
  • Size: 126.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for raw_agents-0.1.5.tar.gz
Algorithm Hash digest
SHA256 9e7f821a77fb92a48e5138578502fe8087ef48a053b2c1cdd7ccca0aa2932e88
MD5 d498439e0e7450c04765236c91b73797
BLAKE2b-256 6e521a61f6bc76ad886ba0195440fae2ce395aee6aa25543eeb840f630a189a8

See more details on using hashes here.

File details

Details for the file raw_agents-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: raw_agents-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for raw_agents-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7f6bc30921829ee070e48bae4c77f7b92c5cc40f1efca9f3e13481fef41f0730
MD5 a2daa73ac6600b578b4c55ff305a968a
BLAKE2b-256 aed1a2e20033911a1c82b6f730540e727ef45085b82101519e4470d61d018f8e

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