langchain-iointelligence


Namelangchain-iointelligence JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/soh7410/langchain-iointelligence
SummaryLangChain integration for io Intelligence LLM API with OpenAI compatibility
upload_time2025-07-17 10:27:18
maintainerNone
docs_urlNone
authorSOH
requires_python>=3.8
licenseMIT
keywords langchain llm ai openai chat language-model io-intelligence
VCS
bugtrack_url
requirements langchain requests python-dotenv pytest pytest-cov black flake8 mypy twine
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # langchain-iointelligence

[![PyPI version](https://badge.fury.io/py/langchain-iointelligence.svg)](https://badge.fury.io/py/langchain-iointelligence)
[![Python versions](https://img.shields.io/pypi/pyversions/langchain-iointelligence.svg)](https://pypi.org/project/langchain-iointelligence/)
[![License](https://img.shields.io/pypi/l/langchain-iointelligence.svg)](https://pypi.org/project/langchain-iointelligence/)
[![Downloads](https://pepy.tech/badge/langchain-iointelligence)](https://pepy.tech/project/langchain-iointelligence)

> **📦 [Available on PyPI](https://pypi.org/project/langchain-iointelligence/)** - Install with `pip install langchain-iointelligence`

## 📋 Feature Support Matrix

| Feature | Status | Notes |
|---------|-----------|-------|
| ✅ **Chat Model** | **Fully Supported** | Message-based interface with system/user/assistant roles |
| ✅ **Text LLM** | **Fully Supported** | Traditional prompt-response interface |
| ✅ **Sync Generation** | **Fully Supported** | Standard text generation with token usage tracking |
| ✅ **Error Handling** | **Production Ready** | Comprehensive error classification and retry logic |
| ✅ **Token Usage** | **Fully Supported** | `response.usage_metadata` access (0.2.1+) |
| ⚠️ **Streaming** | **Basic Support** | SSE token chunks; usage-at-end *coming soon* |
| ❌ **Function/Tool Calling** | **Not Supported** | Planned for future release |
| ❌ **Vision/Multimodal** | **Not Supported** | Text-only interface currently |
| ❌ **Embeddings** | **Not Supported** | Use dedicated embedding providers |

> **Note**: Non-core message roles default to `user`. Usage metadata always includes all required fields (`input_tokens`, `output_tokens`, `total_tokens`) with defaults of 0 when data unavailable.

**LangChain-compatible wrapper** for io Intelligence LLM API with **OpenAI-compatible interface**. Features both traditional Text LLM and modern Chat Model interfaces with comprehensive error handling, token usage tracking, and streaming support.

## 🚀 Key Features

* **🔄 Dual Interface Support**: Both `IOIntelligenceLLM` (text-based) and `IOIntelligenceChatModel` (message-based)
* **⚡ OpenAI-Compatible Interface**: Drop-in replacement with identical parameters and behavior
* **📡 Streaming Support**: Token-by-token streaming (usage-at-end coming soon)
* **🛡️ Production-Grade Reliability**: Automatic retries, detailed error classification, and robust fallbacks
* **🔀 Runtime Provider Switching**: Easy switching between OpenAI, Anthropic, and io Intelligence
* **📊 LangChain Token Tracking**: Standard `usage_metadata` with `input_tokens`/`output_tokens`/`total_tokens`
* **🎛️ Modern LangChain Integration**: Full support for `prompt | llm | parser` chains

## ⚙️ Installation

```bash
pip install langchain-iointelligence
```

## 🔐 Quick Setup

Create a `.env` file:

```env
IO_API_KEY=your_api_key_here
IO_API_URL=https://api.intelligence.io.solutions/api/v1/chat/completions
```

## 🎯 Quick Start

### **Modern Chat Model (Recommended)**

```python
from langchain_iointelligence import IOIntelligenceChat
from langchain_core.messages import HumanMessage

# Initialize with ChatGPT-compatible parameters
chat = IOIntelligenceChat(
    model="meta-llama/Llama-3.3-70B-Instruct",
    temperature=0.7,
    max_tokens=1000,
    timeout=30,
    max_retries=3
)

# Direct usage
messages = [HumanMessage(content="Explain quantum computing")]
response = chat.invoke(messages)
print(response.content)  # AIMessage content
print(response.usage_metadata)  # Token usage: input_tokens, output_tokens, total_tokens
```

### **Streaming Responses**

```python
from langchain_iointelligence import IOIntelligenceChat

chat = IOIntelligenceChat(streaming=True)
messages = [HumanMessage(content="Write a story about AI")]

# Real streaming with server-sent events
for chunk in chat.stream(messages):
    print(chunk.content, end="", flush=True)
```

### **Model Discovery**

```python
from langchain_iointelligence import list_available_models, is_model_available

# List all available models
models = list_available_models()
print("Available models:", models)

# Check if specific model exists
if is_model_available("meta-llama/Llama-3.3-70B-Instruct"):
    print("Model is available!")
```

## 🔗 Advanced LangChain Integration

### **Modern Chain with Full Pipeline**

```python
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_iointelligence import IOIntelligenceChat

# Complete modern pipeline
prompt = ChatPromptTemplate.from_messages([
    ("system", "You are an expert technical writer."),
    ("human", "Explain {topic} in {style} style, max {words} words.")
])

chat = IOIntelligenceChat(
    model="meta-llama/Llama-3.3-70B-Instruct",
    temperature=0.3
)

parser = StrOutputParser()

# Modern chain: prompt | chat | parser
chain = prompt | chat | parser

result = chain.invoke({
    "topic": "machine learning",
    "style": "beginner-friendly", 
    "words": "200"
})
print(result)
```

### **Runtime Provider Switching**

```python
from langchain_openai import ChatOpenAI
from langchain_anthropic import ChatAnthropic  
from langchain_iointelligence import IOIntelligenceChat

# Configure multiple providers
providers = {
    "openai": ChatOpenAI(model="gpt-4"),
    "anthropic": ChatAnthropic(model="claude-3-sonnet-20240229"),
    "iointelligence": IOIntelligenceChat(model="meta-llama/Llama-3.3-70B-Instruct")
}

# Runtime switching via configuration
configurable_chat = providers["openai"].configurable_alternatives(
    ConfigurableField(id="provider"),
    default_key="openai",
    **providers
)

# Switch provider at runtime
response = configurable_chat.invoke(
    "Hello world!",
    config={"configurable": {"provider": "iointelligence"}}
)
```

### **Production Fallback Configuration**

```python
from langchain_openai import ChatOpenAI
from langchain_anthropic import ChatAnthropic
from langchain_iointelligence import IOIntelligenceChat

# Multi-tier fallback system
primary = IOIntelligenceChat(
    model="meta-llama/Llama-3.3-70B-Instruct",
    timeout=10,
    max_retries=2
)

secondary = ChatOpenAI(model="gpt-4", timeout=15)
tertiary = ChatAnthropic(model="claude-3-sonnet-20240229")

# Automatic fallback chain
reliable_chat = primary.with_fallbacks([secondary, tertiary])

# Will automatically try alternatives on failure
response = reliable_chat.invoke("Complex analysis request")
```

### **Error Handling and Monitoring**

```python
from langchain_iointelligence import (
    IOIntelligenceChat,
    IOIntelligenceRateLimitError,
    IOIntelligenceServerError,
    IOIntelligenceAuthenticationError
)

chat = IOIntelligenceChat()

try:
    response = chat.invoke("Generate report")
    print(f"Success! Used {response.usage_metadata['total_tokens']} tokens")
    
except IOIntelligenceRateLimitError as e:
    print(f"Rate limited: {e}. Retry after: {e.retry_after}")
    
except IOIntelligenceServerError as e:
    print(f"Server error {e.status_code}: {e}")
    
except IOIntelligenceAuthenticationError:
    print("Invalid API key - check your credentials")
```

## 🛠️ Configuration Options

### **Complete Parameter Reference**

```python
from langchain_iointelligence import IOIntelligenceChat

chat = IOIntelligenceChat(
    # API Configuration
    api_key="your_key",                           # or use IO_API_KEY env var  
    api_url="https://api.example.com/v1/chat",    # or use IO_API_URL env var
    
    # Model Parameters (ChatGPT Compatible)
    model="meta-llama/Llama-3.3-70B-Instruct",   # Model identifier
    temperature=0.7,                              # Creativity (0.0-2.0)
    max_tokens=2000,                              # Response length limit
    
    # Reliability & Performance  
    timeout=30,                                   # Request timeout (seconds)
    max_retries=3,                                # Retry attempts
    retry_delay=1.0,                              # Initial retry delay
    streaming=True,                               # Enable real streaming
)
```

### **Available Models**

Check the latest models dynamically:

```python
from langchain_iointelligence import IOIntelligenceUtils

utils = IOIntelligenceUtils()
models = utils.list_models()

for model in models:
    print(f"Model: {model['id']}")
    if 'description' in model:
        print(f"  Description: {model['description']}")

# Get recommended models
recommended = utils.get_recommended_models()
print("Recommended models:", recommended)
```

Common models include:
- `meta-llama/Llama-3.3-70B-Instruct` (default, balanced performance)
- `meta-llama/Llama-3.1-405B-Instruct` (highest capability)
- `meta-llama/Llama-3.1-70B-Instruct` (fast and efficient)

## 🔌 API Compatibility

**Full OpenAI ChatCompletion API compatibility:**

```json
{
  "model": "meta-llama/Llama-3.3-70B-Instruct",
  "messages": [{"role": "user", "content": "Hello"}],
  "temperature": 0.7,
  "max_tokens": 1000,
  "stream": true,
  "stop": ["END"]
}
```

**Also supports legacy Text Completion format:**

```json
{
  "model": "meta-llama/Llama-3.3-70B-Instruct",
  "prompt": "Hello",
  "temperature": 0.7,
  "max_tokens": 1000
}
```

## 🔍 Migration Guides

### **From OpenAI ChatGPT**

```python
# Before (OpenAI)
from langchain_openai import ChatOpenAI
chat = ChatOpenAI(
    model="gpt-4",
    temperature=0.7,
    max_tokens=1000,
    timeout=30
)

# After (io Intelligence) - Same parameters!
from langchain_iointelligence import IOIntelligenceChat
chat = IOIntelligenceChat(
    model="meta-llama/Llama-3.3-70B-Instruct",
    temperature=0.7,
    max_tokens=1000, 
    timeout=30
)
```

### **From Anthropic Claude**

```python
# Before (Anthropic)
from langchain_anthropic import ChatAnthropic
chat = ChatAnthropic(model="claude-3-sonnet-20240229")

# After (io Intelligence)
from langchain_iointelligence import IOIntelligenceChat
chat = IOIntelligenceChat(model="meta-llama/Llama-3.3-70B-Instruct")

# Same interface - no code changes needed!
response = chat.invoke([HumanMessage(content="Hello")])
```

## ✅ Testing

```bash
# Install test dependencies
pip install pytest pytest-cov

# Run all tests
pytest tests/ -v

# Run with coverage
pytest tests/ --cov=langchain_iointelligence --cov-report=html

# Test specific functionality
pytest tests/test_chat.py::TestIOIntelligenceChatModel::test_streaming -v
```

## 🚀 Advanced Examples

### **Batch Processing with Rate Limit Handling**

```python
import asyncio
from langchain_iointelligence import IOIntelligenceChat, IOIntelligenceRateLimitError

async def process_batch(prompts, chat):
    results = []
    for prompt in prompts:
        try:
            result = await chat.ainvoke(prompt)
            results.append(result)
        except IOIntelligenceRateLimitError:
            await asyncio.sleep(60)  # Wait for rate limit reset
            result = await chat.ainvoke(prompt)  # Retry
            results.append(result)
    return results
```

### **Custom Retry Logic**

```python
from langchain_iointelligence import IOIntelligenceChat

# Custom retry configuration
chat = IOIntelligenceChat(
    max_retries=5,
    retry_delay=2.0,  # Start with 2 second delays
    timeout=60        # Longer timeout for complex requests
)
```

### **Model Performance Comparison**

```python
from langchain_iointelligence import IOIntelligenceChat

models = [
    "meta-llama/Llama-3.3-70B-Instruct",
    "meta-llama/Llama-3.1-405B-Instruct",
    "meta-llama/Llama-3.1-70B-Instruct"
]

prompt = "Solve this math problem: 2x + 5 = 15"

for model in models:
    chat = IOIntelligenceChat(model=model)
    response = chat.invoke(prompt)
    print(f"Model {model}: {response.content}")
    print(f"Tokens used: {response.usage_metadata}")
```

## 🔧 Development

```bash
# Clone repository
git clone https://github.com/soh7410/langchain-iointelligence.git
cd langchain-iointelligence

# Install in development mode
pip install -e ".[dev]"

# Setup environment
cp .env.example .env
# Edit .env with your API credentials

# Code formatting & linting
black langchain_iointelligence/ tests/
mypy langchain_iointelligence/
flake8 langchain_iointelligence/

# Run tests
pytest tests/ -v
```

## 📊 Performance & Monitoring

### **Usage Tracking**

```python
chat = IOIntelligenceChat()
response = chat.invoke("Analyze market trends")

# Access detailed usage information
usage = response.usage_metadata
print(f"Prompt tokens: {usage.get('prompt_tokens')}")
print(f"Completion tokens: {usage.get('completion_tokens')}")
print(f"Total tokens: {usage.get('total_tokens')}")
print(f"Model used: {response.response_metadata.get('model')}")
```

### **Response Timing**

```python
import time

start_time = time.time()
response = chat.invoke("Complex reasoning task")
end_time = time.time()

print(f"Response time: {end_time - start_time:.2f} seconds")
print(f"Tokens per second: {response.usage_metadata['total_tokens'] / (end_time - start_time):.1f}")
```

## 🛡️ Production Best Practices

1. **Always use environment variables** for API keys
2. **Implement proper fallback chains** for reliability
3. **Monitor token usage** to control costs
4. **Use streaming** for better user experience
5. **Handle rate limits gracefully** with exponential backoff
6. **Validate models** before deployment

## 📄 License

MIT License - see [LICENSE](LICENSE) file for details.

## 🤝 Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Run tests (`pytest tests/ -v`)
4. Commit changes (`git commit -m 'Add amazing feature'`)
5. Push to branch (`git push origin feature/amazing-feature`)
6. Create a Pull Request

## 📧 Support

- **Issues**: [GitHub Issues](https://github.com/soh7410/langchain-iointelligence/issues)
- **Documentation**: [GitHub Wiki](https://github.com/soh7410/langchain-iointelligence/wiki)
- **Examples**: See `examples/` directory

---

**🎯 Ready for production use with complete ChatGPT API compatibility and modern LangChain integration!**

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/soh7410/langchain-iointelligence",
    "name": "langchain-iointelligence",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "langchain, llm, ai, openai, chat, language-model, io-intelligence",
    "author": "SOH",
    "author_email": "io Intelligence <support@intelligence.io>",
    "download_url": "https://files.pythonhosted.org/packages/d3/eb/59fe4e9cff2f98d28954b7189872946af9525305d730616f8fda0c3a4164/langchain_iointelligence-0.2.0.tar.gz",
    "platform": null,
    "description": "# langchain-iointelligence\n\n[![PyPI version](https://badge.fury.io/py/langchain-iointelligence.svg)](https://badge.fury.io/py/langchain-iointelligence)\n[![Python versions](https://img.shields.io/pypi/pyversions/langchain-iointelligence.svg)](https://pypi.org/project/langchain-iointelligence/)\n[![License](https://img.shields.io/pypi/l/langchain-iointelligence.svg)](https://pypi.org/project/langchain-iointelligence/)\n[![Downloads](https://pepy.tech/badge/langchain-iointelligence)](https://pepy.tech/project/langchain-iointelligence)\n\n> **\ud83d\udce6 [Available on PyPI](https://pypi.org/project/langchain-iointelligence/)** - Install with `pip install langchain-iointelligence`\n\n## \ud83d\udccb Feature Support Matrix\n\n| Feature | Status | Notes |\n|---------|-----------|-------|\n| \u2705 **Chat Model** | **Fully Supported** | Message-based interface with system/user/assistant roles |\n| \u2705 **Text LLM** | **Fully Supported** | Traditional prompt-response interface |\n| \u2705 **Sync Generation** | **Fully Supported** | Standard text generation with token usage tracking |\n| \u2705 **Error Handling** | **Production Ready** | Comprehensive error classification and retry logic |\n| \u2705 **Token Usage** | **Fully Supported** | `response.usage_metadata` access (0.2.1+) |\n| \u26a0\ufe0f **Streaming** | **Basic Support** | SSE token chunks; usage-at-end *coming soon* |\n| \u274c **Function/Tool Calling** | **Not Supported** | Planned for future release |\n| \u274c **Vision/Multimodal** | **Not Supported** | Text-only interface currently |\n| \u274c **Embeddings** | **Not Supported** | Use dedicated embedding providers |\n\n> **Note**: Non-core message roles default to `user`. Usage metadata always includes all required fields (`input_tokens`, `output_tokens`, `total_tokens`) with defaults of 0 when data unavailable.\n\n**LangChain-compatible wrapper** for io Intelligence LLM API with **OpenAI-compatible interface**. Features both traditional Text LLM and modern Chat Model interfaces with comprehensive error handling, token usage tracking, and streaming support.\n\n## \ud83d\ude80 Key Features\n\n* **\ud83d\udd04 Dual Interface Support**: Both `IOIntelligenceLLM` (text-based) and `IOIntelligenceChatModel` (message-based)\n* **\u26a1 OpenAI-Compatible Interface**: Drop-in replacement with identical parameters and behavior\n* **\ud83d\udce1 Streaming Support**: Token-by-token streaming (usage-at-end coming soon)\n* **\ud83d\udee1\ufe0f Production-Grade Reliability**: Automatic retries, detailed error classification, and robust fallbacks\n* **\ud83d\udd00 Runtime Provider Switching**: Easy switching between OpenAI, Anthropic, and io Intelligence\n* **\ud83d\udcca LangChain Token Tracking**: Standard `usage_metadata` with `input_tokens`/`output_tokens`/`total_tokens`\n* **\ud83c\udf9b\ufe0f Modern LangChain Integration**: Full support for `prompt | llm | parser` chains\n\n## \u2699\ufe0f Installation\n\n```bash\npip install langchain-iointelligence\n```\n\n## \ud83d\udd10 Quick Setup\n\nCreate a `.env` file:\n\n```env\nIO_API_KEY=your_api_key_here\nIO_API_URL=https://api.intelligence.io.solutions/api/v1/chat/completions\n```\n\n## \ud83c\udfaf Quick Start\n\n### **Modern Chat Model (Recommended)**\n\n```python\nfrom langchain_iointelligence import IOIntelligenceChat\nfrom langchain_core.messages import HumanMessage\n\n# Initialize with ChatGPT-compatible parameters\nchat = IOIntelligenceChat(\n    model=\"meta-llama/Llama-3.3-70B-Instruct\",\n    temperature=0.7,\n    max_tokens=1000,\n    timeout=30,\n    max_retries=3\n)\n\n# Direct usage\nmessages = [HumanMessage(content=\"Explain quantum computing\")]\nresponse = chat.invoke(messages)\nprint(response.content)  # AIMessage content\nprint(response.usage_metadata)  # Token usage: input_tokens, output_tokens, total_tokens\n```\n\n### **Streaming Responses**\n\n```python\nfrom langchain_iointelligence import IOIntelligenceChat\n\nchat = IOIntelligenceChat(streaming=True)\nmessages = [HumanMessage(content=\"Write a story about AI\")]\n\n# Real streaming with server-sent events\nfor chunk in chat.stream(messages):\n    print(chunk.content, end=\"\", flush=True)\n```\n\n### **Model Discovery**\n\n```python\nfrom langchain_iointelligence import list_available_models, is_model_available\n\n# List all available models\nmodels = list_available_models()\nprint(\"Available models:\", models)\n\n# Check if specific model exists\nif is_model_available(\"meta-llama/Llama-3.3-70B-Instruct\"):\n    print(\"Model is available!\")\n```\n\n## \ud83d\udd17 Advanced LangChain Integration\n\n### **Modern Chain with Full Pipeline**\n\n```python\nfrom langchain_core.prompts import ChatPromptTemplate\nfrom langchain_core.output_parsers import StrOutputParser\nfrom langchain_iointelligence import IOIntelligenceChat\n\n# Complete modern pipeline\nprompt = ChatPromptTemplate.from_messages([\n    (\"system\", \"You are an expert technical writer.\"),\n    (\"human\", \"Explain {topic} in {style} style, max {words} words.\")\n])\n\nchat = IOIntelligenceChat(\n    model=\"meta-llama/Llama-3.3-70B-Instruct\",\n    temperature=0.3\n)\n\nparser = StrOutputParser()\n\n# Modern chain: prompt | chat | parser\nchain = prompt | chat | parser\n\nresult = chain.invoke({\n    \"topic\": \"machine learning\",\n    \"style\": \"beginner-friendly\", \n    \"words\": \"200\"\n})\nprint(result)\n```\n\n### **Runtime Provider Switching**\n\n```python\nfrom langchain_openai import ChatOpenAI\nfrom langchain_anthropic import ChatAnthropic  \nfrom langchain_iointelligence import IOIntelligenceChat\n\n# Configure multiple providers\nproviders = {\n    \"openai\": ChatOpenAI(model=\"gpt-4\"),\n    \"anthropic\": ChatAnthropic(model=\"claude-3-sonnet-20240229\"),\n    \"iointelligence\": IOIntelligenceChat(model=\"meta-llama/Llama-3.3-70B-Instruct\")\n}\n\n# Runtime switching via configuration\nconfigurable_chat = providers[\"openai\"].configurable_alternatives(\n    ConfigurableField(id=\"provider\"),\n    default_key=\"openai\",\n    **providers\n)\n\n# Switch provider at runtime\nresponse = configurable_chat.invoke(\n    \"Hello world!\",\n    config={\"configurable\": {\"provider\": \"iointelligence\"}}\n)\n```\n\n### **Production Fallback Configuration**\n\n```python\nfrom langchain_openai import ChatOpenAI\nfrom langchain_anthropic import ChatAnthropic\nfrom langchain_iointelligence import IOIntelligenceChat\n\n# Multi-tier fallback system\nprimary = IOIntelligenceChat(\n    model=\"meta-llama/Llama-3.3-70B-Instruct\",\n    timeout=10,\n    max_retries=2\n)\n\nsecondary = ChatOpenAI(model=\"gpt-4\", timeout=15)\ntertiary = ChatAnthropic(model=\"claude-3-sonnet-20240229\")\n\n# Automatic fallback chain\nreliable_chat = primary.with_fallbacks([secondary, tertiary])\n\n# Will automatically try alternatives on failure\nresponse = reliable_chat.invoke(\"Complex analysis request\")\n```\n\n### **Error Handling and Monitoring**\n\n```python\nfrom langchain_iointelligence import (\n    IOIntelligenceChat,\n    IOIntelligenceRateLimitError,\n    IOIntelligenceServerError,\n    IOIntelligenceAuthenticationError\n)\n\nchat = IOIntelligenceChat()\n\ntry:\n    response = chat.invoke(\"Generate report\")\n    print(f\"Success! Used {response.usage_metadata['total_tokens']} tokens\")\n    \nexcept IOIntelligenceRateLimitError as e:\n    print(f\"Rate limited: {e}. Retry after: {e.retry_after}\")\n    \nexcept IOIntelligenceServerError as e:\n    print(f\"Server error {e.status_code}: {e}\")\n    \nexcept IOIntelligenceAuthenticationError:\n    print(\"Invalid API key - check your credentials\")\n```\n\n## \ud83d\udee0\ufe0f Configuration Options\n\n### **Complete Parameter Reference**\n\n```python\nfrom langchain_iointelligence import IOIntelligenceChat\n\nchat = IOIntelligenceChat(\n    # API Configuration\n    api_key=\"your_key\",                           # or use IO_API_KEY env var  \n    api_url=\"https://api.example.com/v1/chat\",    # or use IO_API_URL env var\n    \n    # Model Parameters (ChatGPT Compatible)\n    model=\"meta-llama/Llama-3.3-70B-Instruct\",   # Model identifier\n    temperature=0.7,                              # Creativity (0.0-2.0)\n    max_tokens=2000,                              # Response length limit\n    \n    # Reliability & Performance  \n    timeout=30,                                   # Request timeout (seconds)\n    max_retries=3,                                # Retry attempts\n    retry_delay=1.0,                              # Initial retry delay\n    streaming=True,                               # Enable real streaming\n)\n```\n\n### **Available Models**\n\nCheck the latest models dynamically:\n\n```python\nfrom langchain_iointelligence import IOIntelligenceUtils\n\nutils = IOIntelligenceUtils()\nmodels = utils.list_models()\n\nfor model in models:\n    print(f\"Model: {model['id']}\")\n    if 'description' in model:\n        print(f\"  Description: {model['description']}\")\n\n# Get recommended models\nrecommended = utils.get_recommended_models()\nprint(\"Recommended models:\", recommended)\n```\n\nCommon models include:\n- `meta-llama/Llama-3.3-70B-Instruct` (default, balanced performance)\n- `meta-llama/Llama-3.1-405B-Instruct` (highest capability)\n- `meta-llama/Llama-3.1-70B-Instruct` (fast and efficient)\n\n## \ud83d\udd0c API Compatibility\n\n**Full OpenAI ChatCompletion API compatibility:**\n\n```json\n{\n  \"model\": \"meta-llama/Llama-3.3-70B-Instruct\",\n  \"messages\": [{\"role\": \"user\", \"content\": \"Hello\"}],\n  \"temperature\": 0.7,\n  \"max_tokens\": 1000,\n  \"stream\": true,\n  \"stop\": [\"END\"]\n}\n```\n\n**Also supports legacy Text Completion format:**\n\n```json\n{\n  \"model\": \"meta-llama/Llama-3.3-70B-Instruct\",\n  \"prompt\": \"Hello\",\n  \"temperature\": 0.7,\n  \"max_tokens\": 1000\n}\n```\n\n## \ud83d\udd0d Migration Guides\n\n### **From OpenAI ChatGPT**\n\n```python\n# Before (OpenAI)\nfrom langchain_openai import ChatOpenAI\nchat = ChatOpenAI(\n    model=\"gpt-4\",\n    temperature=0.7,\n    max_tokens=1000,\n    timeout=30\n)\n\n# After (io Intelligence) - Same parameters!\nfrom langchain_iointelligence import IOIntelligenceChat\nchat = IOIntelligenceChat(\n    model=\"meta-llama/Llama-3.3-70B-Instruct\",\n    temperature=0.7,\n    max_tokens=1000, \n    timeout=30\n)\n```\n\n### **From Anthropic Claude**\n\n```python\n# Before (Anthropic)\nfrom langchain_anthropic import ChatAnthropic\nchat = ChatAnthropic(model=\"claude-3-sonnet-20240229\")\n\n# After (io Intelligence)\nfrom langchain_iointelligence import IOIntelligenceChat\nchat = IOIntelligenceChat(model=\"meta-llama/Llama-3.3-70B-Instruct\")\n\n# Same interface - no code changes needed!\nresponse = chat.invoke([HumanMessage(content=\"Hello\")])\n```\n\n## \u2705 Testing\n\n```bash\n# Install test dependencies\npip install pytest pytest-cov\n\n# Run all tests\npytest tests/ -v\n\n# Run with coverage\npytest tests/ --cov=langchain_iointelligence --cov-report=html\n\n# Test specific functionality\npytest tests/test_chat.py::TestIOIntelligenceChatModel::test_streaming -v\n```\n\n## \ud83d\ude80 Advanced Examples\n\n### **Batch Processing with Rate Limit Handling**\n\n```python\nimport asyncio\nfrom langchain_iointelligence import IOIntelligenceChat, IOIntelligenceRateLimitError\n\nasync def process_batch(prompts, chat):\n    results = []\n    for prompt in prompts:\n        try:\n            result = await chat.ainvoke(prompt)\n            results.append(result)\n        except IOIntelligenceRateLimitError:\n            await asyncio.sleep(60)  # Wait for rate limit reset\n            result = await chat.ainvoke(prompt)  # Retry\n            results.append(result)\n    return results\n```\n\n### **Custom Retry Logic**\n\n```python\nfrom langchain_iointelligence import IOIntelligenceChat\n\n# Custom retry configuration\nchat = IOIntelligenceChat(\n    max_retries=5,\n    retry_delay=2.0,  # Start with 2 second delays\n    timeout=60        # Longer timeout for complex requests\n)\n```\n\n### **Model Performance Comparison**\n\n```python\nfrom langchain_iointelligence import IOIntelligenceChat\n\nmodels = [\n    \"meta-llama/Llama-3.3-70B-Instruct\",\n    \"meta-llama/Llama-3.1-405B-Instruct\",\n    \"meta-llama/Llama-3.1-70B-Instruct\"\n]\n\nprompt = \"Solve this math problem: 2x + 5 = 15\"\n\nfor model in models:\n    chat = IOIntelligenceChat(model=model)\n    response = chat.invoke(prompt)\n    print(f\"Model {model}: {response.content}\")\n    print(f\"Tokens used: {response.usage_metadata}\")\n```\n\n## \ud83d\udd27 Development\n\n```bash\n# Clone repository\ngit clone https://github.com/soh7410/langchain-iointelligence.git\ncd langchain-iointelligence\n\n# Install in development mode\npip install -e \".[dev]\"\n\n# Setup environment\ncp .env.example .env\n# Edit .env with your API credentials\n\n# Code formatting & linting\nblack langchain_iointelligence/ tests/\nmypy langchain_iointelligence/\nflake8 langchain_iointelligence/\n\n# Run tests\npytest tests/ -v\n```\n\n## \ud83d\udcca Performance & Monitoring\n\n### **Usage Tracking**\n\n```python\nchat = IOIntelligenceChat()\nresponse = chat.invoke(\"Analyze market trends\")\n\n# Access detailed usage information\nusage = response.usage_metadata\nprint(f\"Prompt tokens: {usage.get('prompt_tokens')}\")\nprint(f\"Completion tokens: {usage.get('completion_tokens')}\")\nprint(f\"Total tokens: {usage.get('total_tokens')}\")\nprint(f\"Model used: {response.response_metadata.get('model')}\")\n```\n\n### **Response Timing**\n\n```python\nimport time\n\nstart_time = time.time()\nresponse = chat.invoke(\"Complex reasoning task\")\nend_time = time.time()\n\nprint(f\"Response time: {end_time - start_time:.2f} seconds\")\nprint(f\"Tokens per second: {response.usage_metadata['total_tokens'] / (end_time - start_time):.1f}\")\n```\n\n## \ud83d\udee1\ufe0f Production Best Practices\n\n1. **Always use environment variables** for API keys\n2. **Implement proper fallback chains** for reliability\n3. **Monitor token usage** to control costs\n4. **Use streaming** for better user experience\n5. **Handle rate limits gracefully** with exponential backoff\n6. **Validate models** before deployment\n\n## \ud83d\udcc4 License\n\nMIT License - see [LICENSE](LICENSE) file for details.\n\n## \ud83e\udd1d Contributing\n\n1. Fork the repository\n2. Create a feature branch (`git checkout -b feature/amazing-feature`)\n3. Run tests (`pytest tests/ -v`)\n4. Commit changes (`git commit -m 'Add amazing feature'`)\n5. Push to branch (`git push origin feature/amazing-feature`)\n6. Create a Pull Request\n\n## \ud83d\udce7 Support\n\n- **Issues**: [GitHub Issues](https://github.com/soh7410/langchain-iointelligence/issues)\n- **Documentation**: [GitHub Wiki](https://github.com/soh7410/langchain-iointelligence/wiki)\n- **Examples**: See `examples/` directory\n\n---\n\n**\ud83c\udfaf Ready for production use with complete ChatGPT API compatibility and modern LangChain integration!**\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "LangChain integration for io Intelligence LLM API with OpenAI compatibility",
    "version": "0.2.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/soh7410/langchain-iointelligence/issues",
        "Documentation": "https://github.com/soh7410/langchain-iointelligence#readme",
        "Homepage": "https://github.com/soh7410/langchain-iointelligence",
        "Repository": "https://github.com/soh7410/langchain-iointelligence"
    },
    "split_keywords": [
        "langchain",
        " llm",
        " ai",
        " openai",
        " chat",
        " language-model",
        " io-intelligence"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "bd86324344b191c2364f67f1a1aaa5dd4137677c0b9df51fda1dc7a20898f829",
                "md5": "a56ef83feb26b99d7f3582f1a66b5f7d",
                "sha256": "d4947150bfa8eadf1c8dcb02de2836e4c69e34221a170fefa11a19104b358faa"
            },
            "downloads": -1,
            "filename": "langchain_iointelligence-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a56ef83feb26b99d7f3582f1a66b5f7d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 18499,
            "upload_time": "2025-07-17T10:27:17",
            "upload_time_iso_8601": "2025-07-17T10:27:17.005631Z",
            "url": "https://files.pythonhosted.org/packages/bd/86/324344b191c2364f67f1a1aaa5dd4137677c0b9df51fda1dc7a20898f829/langchain_iointelligence-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d3eb59fe4e9cff2f98d28954b7189872946af9525305d730616f8fda0c3a4164",
                "md5": "687b21c3e06ab3824efa867ac65be71f",
                "sha256": "2e40f75d7d01fa433646a1983e7eb711f8f48dafca42367d0b858d816a1d1309"
            },
            "downloads": -1,
            "filename": "langchain_iointelligence-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "687b21c3e06ab3824efa867ac65be71f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 24176,
            "upload_time": "2025-07-17T10:27:18",
            "upload_time_iso_8601": "2025-07-17T10:27:18.693832Z",
            "url": "https://files.pythonhosted.org/packages/d3/eb/59fe4e9cff2f98d28954b7189872946af9525305d730616f8fda0c3a4164/langchain_iointelligence-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-17 10:27:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "soh7410",
    "github_project": "langchain-iointelligence",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "langchain",
            "specs": [
                [
                    ">=",
                    "0.1.0"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    ">=",
                    "2.25.0"
                ]
            ]
        },
        {
            "name": "python-dotenv",
            "specs": [
                [
                    ">=",
                    "1.0.1"
                ]
            ]
        },
        {
            "name": "pytest",
            "specs": [
                [
                    ">=",
                    "8.3.4"
                ]
            ]
        },
        {
            "name": "pytest-cov",
            "specs": [
                [
                    ">=",
                    "2.0"
                ]
            ]
        },
        {
            "name": "black",
            "specs": [
                [
                    ">=",
                    "22.0"
                ]
            ]
        },
        {
            "name": "flake8",
            "specs": [
                [
                    ">=",
                    "4.0"
                ]
            ]
        },
        {
            "name": "mypy",
            "specs": [
                [
                    ">=",
                    "0.910"
                ]
            ]
        },
        {
            "name": "twine",
            "specs": [
                [
                    ">=",
                    "4.0"
                ]
            ]
        }
    ],
    "lcname": "langchain-iointelligence"
}
        
SOH
Elapsed time: 1.42331s