Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ jobs:
echo "PIPELINES_RUN_URL=https://test-platform-api.aixplain.com/assets/pipeline/execution/run" >> $GITHUB_ENV
fi
echo "SLACK_TOKEN=${{ secrets.SLACK_TOKEN }}" >> $GITHUB_ENV
echo "HF_TOKEN=${{ secrets.HF_TOKEN }}" >> $GITHUB_ENV

- name: Run Tests
timeout-minutes: ${{ matrix.timeout }}
Expand Down
208 changes: 168 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,71 +1,199 @@
<img src="docs/assets/aixplain-brandmark-line.png" alt="aiXplain logo" title="aiXplain" align="right" height="132" width="85"/>
# aiXplain SDK

# aiXplain
<div align="center">
<img src="docs/assets/aixplain-brandmark-line.png" alt="aiXplain logo" title="aiXplain" height="132" width="85"/>
<br>
<br>

[![Python 3.5+](https://img.shields.io/badge/python-3.5+-blue.svg)](https://www.python.org/downloads/)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)
[![PyPI version](https://badge.fury.io/py/aiXplain.svg)](https://badge.fury.io/py/aiXplain)

**The professional AI SDK for developers and enterprises**
</div>

aixplain is a software development kit (SDK) for the [aiXplain](https://aixplain.com/) platform. With aixplain, developers can quickly and easily:
## 📖 API Reference

- [Discover](https://aixplain.com/platform/discovery/) aiXplain’s ever-expanding catalog of 35,000+ ready-to-use AI models and utilize them.
- [Benchmark](https://aixplain.com/platform/benchmark/) AI systems by choosing models, datasets and metrics.
- [Design](https://aixplain.com/platform/studio/) their own custom pipelines and run them.
- [FineTune](https://aixplain.com/platform/finetune/) pre-trained models by tuning them using your data, enhancing their performance.
- **Complete documentation:**
- [Python](https://docs.aixplain.com/api-reference/python/)
- [Swift](https://docs.aixplain.com/api-reference/swift/)

🔎 **Find [models](https://platform.aixplain.com/discovery/models), [datasets](https://platform.aixplain.com/discovery/datasets), [metrics](https://platform.aixplain.com/discovery/metrics) on the platform.**
## 🚀 Overview

💛 Our repository is constantly evolving. With the help of the scientific community, we plan to add even more datasets, models, and metrics across domains and tasks.
The aiXplain SDK is a comprehensive Python library that empowers developers to integrate cutting-edge AI capabilities into their applications with ease. Access thousands of AI models, build custom pipelines, and deploy intelligent solutions at scale.

## Getting Started
### ✨ Key Features

### Installation
To install the base package, simply,
- **🔍 Discover**: Access 35,000+ ready-to-use AI models across multiple domains
- **⚡ Benchmark**: Compare AI systems using comprehensive datasets and metrics
- **🛠️ Design**: Create and deploy custom AI pipelines with our visual designer
- **🎯 FineTune**: Enhance pre-trained models with your data for optimal performance

## 📦 Installation

### Basic Installation
```bash
pip install aixplain
```

To install aiXplain with additional model building support:
### With Model Building Support
```bash
pip install aixplain[model-builder]
```

### API Key Setup
Before you can use the aixplain SDK, you'll need to obtain an API key from our platform. For details refer this [Team API Key Guide](docs/user/api_setup.md).
## 🔑 Authentication

Once you get the API key, you'll need to add this API key as an environment variable on your system.
Get your API key from the aiXplain platform:

#### Linux or macOS
```bash
export TEAM_API_KEY=YOUR_API_KEY
```
#### Windows
1. Visit [platform.aixplain.com](https://platform.aixplain.com)
2. Navigate to your API Keys section
3. Generate a new Team API key

### Set Your API Key

**Linux/macOS:**
```bash
set TEAM_API_KEY=YOUR_API_KEY
export TEAM_API_KEY=your_api_key_here
```
#### Jupyter Notebook

**Windows:**
```cmd
set TEAM_API_KEY=your_api_key_here
```
%env TEAM_API_KEY=YOUR_API_KEY

**Jupyter Notebook:**
```python
%env TEAM_API_KEY=your_api_key_here
```

### Usage
For detailed setup instructions, visit [docs.aixplain.com/setup](https://docs.aixplain.com/setup).

Let’s see how we can use aixplain to run a machine translation model. The following example shows an [English to French translation model](https://platform.aixplain.com/discovery/model/61dc52976eb5634cf06e97cc).
## 🏃‍♂️ Quick Start

### Running Your First Model

```python
from aixplain.factories import ModelFactory
model = ModelFactory.get("61dc52976eb5634cf06e97cc") # Get the ID of a model from our platform.
translation = model.run("This is a sample text") # Alternatively, you can input a public URL or provide a file path on your local machine.

# Get an English to French translation model
model = ModelFactory.get("61dc52976eb5634cf06e97cc")

# Run translation
result = model.run("Hello, how are you today?")
print(result.data) # "Bonjour, comment allez-vous aujourd'hui?"
```

### Building a Pipeline

```python
from aixplain.factories.pipeline_factory import PipelineFactory
from aixplain.modules.pipeline.designer import Input

pipeline = PipelineFactory.init("Multi Input-Output Pipeline")
text_input_node = Input(data="text_input", data_types=["TEXT"], pipeline=pipeline)

TRANSLATION_ASSET_ID = '60ddefbe8d38c51c5885f98a'
translation_node = pipeline.translation(asset_id=TRANSLATION_ASSET_ID)

SENTIMENT_ASSET_ID = '61728750720b09325cbcdc36'
sentiment_node = pipeline.sentiment_analysis(asset_id=SENTIMENT_ASSET_ID)

text_input_node.link(translation_node, 'input', 'text')
translation_node.link(sentiment_node, 'data', 'text')

translated_output_node = translation_node.use_output('data')
sentiment_output_node = sentiment_node.use_output('data')

pipeline.save()
outputs = pipeline.run({
'text_input': 'This is example text to translate.'
})

print(outputs)
```
*Check out the [explore section](docs/user/user_doc.md#explore) of our guide on Models to get the ID of your desired model*

## Quick Links
### Working with Agents

```python
from aixplain.factories import AgentFactory

agent = AgentFactory.create(
name="Google Search Agent",
description="A search agent",
instructions="Use Google Search to answer queries.",
tools=[
AgentFactory.create_model_tool("65c51c556eb563350f6e1bb1")
],
llm_id="669a63646eb56306647e1091"
)
response = agent.run("How can I help you today?")
```

## 📊 Core Modules

| Module | Description | Documentation |
|--------|-------------|---------------|
| **Models** | Access 35,000+ AI models | [docs.aixplain.com/concepts/assets/models](https://docs.aixplain.com/concepts/assets/models/) |
| **Pipelines** | Build custom AI workflows | [docs.aixplain.com/concepts/assets/pipelines](https://docs.aixplain.com/concepts/assets/pipelines) |
| **Agents** | Deploy intelligent AI assistants | [docs.aixplain.com/concepts/assets/agents](https://docs.aixplain.com/concepts/assets/agents) |
| **Datasets** | Manage and process data | [docs.aixplain.com/concepts/assets/data/overview](https://docs.aixplain.com/concepts/assets/data/overview) |
| **Benchmarks** | Evaluate AI performance | [docs.aixplain.com/concepts/services/benchmark/benchmark-models](https://docs.aixplain.com/concepts/services/benchmark/benchmark-models) |
| **FineTuning** | Customize models with your data | [docs.aixplain.com/concepts/services/finetune/finetune-llm](https://docs.aixplain.com/concepts/services/finetune/finetune-llm) |

## 📚 Documentation

Comprehensive documentation and guides are available at **[docs.aixplain.com](https://docs.aixplain.com)**:

### 🎯 Getting Started
- [**Quick Start Guide**](https://docs.aixplain.com/getting-started/) - Get up and running in minutes
- [**API Key Setup**](https://docs.aixplain.com/getting-started/python) - Authentication and configuration
- [**Tutorials**](https://docs.aixplain.com/tutorials/) - Build your first AI application

### 📖 Core Guides
- [**Discover**](https://docs.aixplain.com/concepts/assets/models) aiXplain’s ever-expanding catalog of 35,000+ ready-to-use AI models and utilize them.
- [**Benchmark**](https://docs.aixplain.com/concepts/services/benchmark/benchmark-models) AI systems by choosing models, datasets and metrics.
- [**Design**](https://docs.aixplain.com/concepts/assets/pipelines) their own custom pipelines and run them.
- [**FineTune**](https://docs.aixplain.com/concepts/services/finetune/finetune-llm) pre-trained models by tuning them using your data, enhancing their performance.


## 🛠️ Advanced Examples

### Batch Processing
```python
# Process multiple inputs efficiently
inputs = ["text1", "text2", "text3"]
results = model.run_batch(inputs)
```

## 🤝 Community & Support

- **📖 Documentation**: [docs.aixplain.com](https://docs.aixplain.com)
- **💬 Discord Community**: [discord.gg/aixplain](https://discord.gg/aixplain)
- **🐛 Issues**: [GitHub Issues](https://github.com/aixplain/aiXplain/issues)
- **📧 Support**: support@aixplain.com
- **🔄 Release Notes**: [GitHub Releases](https://github.com/aixplain/aiXplain/releases)

## 🔗 Platform Links

- **🏠 Platform Home**: [platform.aixplain.com](https://platform.aixplain.com)
- **🔍 Model Discovery**: [platform.aixplain.com/discovery/models](https://platform.aixplain.com/discovery/models)
- **📊 Datasets**: [platform.aixplain.com/discovery/datasets](https://platform.aixplain.com/discovery/datasets)
- **📏 Metrics**: [platform.aixplain.com/discovery/metrics](https://platform.aixplain.com/discovery/metrics)

## 📄 License

This project is licensed under the Apache License 2.0. See the [LICENSE](LICENSE) file for details.

## 🏢 About aiXplain

aiXplain is the leading AI platform for building, deploying, and managing AI solutions at scale. We democratize AI by making cutting-edge models accessible to developers and enterprises worldwide.

---

* [Team API Key Guide](docs/user/api_setup.md)
* [User Documentation](docs/user/user_doc.md)
* [Developer Guide](docs/development/developer_guide.md)
* [API Reference](https://docs.aixplain.com)
* [Release notes](https://github.com/aixplain/aiXplain/releases)
<div align="center">

**Ready to build the future with AI?**

## Support
Raise issues for support in this repository.
Pull requests are welcome!
[**Get Started →**](https://docs.aixplain.com/getting-started/) | [**Explore Models →**](https://platform.aixplain.com/discovery/models) | [**Join Community →**](https://discord.com/invite/T5dCmjRSYA)

## Note
The **aiXtend** python package was renamed to **aiXplain** from the release v0.1.1.
</div>
47 changes: 38 additions & 9 deletions aixplain/factories/agent_factory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class AgentFactory:
This class provides class methods for creating various types of agents and tools,
as well as managing existing agents in the platform.
"""

@classmethod
def create(
cls,
Expand Down Expand Up @@ -112,7 +113,10 @@ def create(
"Note: In upcoming releases, `llm` will become a required parameter.",
UserWarning,
)
from aixplain.factories.agent_factory.utils import build_agent, build_tool_payload
from aixplain.factories.agent_factory.utils import (
build_agent,
build_tool_payload,
)

agent = None
url = urljoin(config.BACKEND_URL, "sdk/agents")
Expand Down Expand Up @@ -142,7 +146,7 @@ def create(
{
"type": "llm",
"description": "main",
"parameters": llm.get_parameters().to_list() if llm.get_parameters() else None,
"parameters": (llm.get_parameters().to_list() if llm.get_parameters() else None),
}
)
payload["llmId"] = llm.id
Expand Down Expand Up @@ -203,7 +207,11 @@ def create_from_dict(cls, dict: Dict) -> Agent:

@classmethod
def create_task(
cls, name: Text, description: Text, expected_output: Text, dependencies: Optional[List[Text]] = None
cls,
name: Text,
description: Text,
expected_output: Text,
dependencies: Optional[List[Text]] = None,
) -> AgentTask:
"""Create a new task for an agent.

Expand All @@ -217,7 +225,12 @@ def create_task(
Returns:
AgentTask: Created task object.
"""
return AgentTask(name=name, description=description, expected_output=expected_output, dependencies=dependencies)
return AgentTask(
name=name,
description=description,
expected_output=expected_output,
dependencies=dependencies,
)

@classmethod
def create_model_tool(
Expand Down Expand Up @@ -251,17 +264,28 @@ def create_model_tool(
if supplier is not None:
if isinstance(supplier, str):
for supplier_ in Supplier:
if supplier.lower() in [supplier_.value["code"].lower(), supplier_.value["name"].lower()]:
if supplier.lower() in [
supplier_.value["code"].lower(),
supplier_.value["name"].lower(),
]:
supplier = supplier_
break
assert isinstance(supplier, Supplier), f"Supplier {supplier} is not a valid supplier"
return ModelTool(
function=function, supplier=supplier, model=model, name=name, description=description, parameters=parameters
function=function,
supplier=supplier,
model=model,
name=name,
description=description,
parameters=parameters,
)

@classmethod
def create_pipeline_tool(
cls, description: Text, pipeline: Union[Pipeline, Text], name: Optional[Text] = None
cls,
description: Text,
pipeline: Union[Pipeline, Text],
name: Optional[Text] = None,
) -> PipelineTool:
"""Create a new pipeline tool for use with an agent.

Expand Down Expand Up @@ -471,7 +495,12 @@ def list(cls) -> Dict:
logging.info(f"Response for GET List Agents - Page Total: {page_total} / Total: {total}")
for agent in results:
agents.append(build_agent(agent))
return {"results": agents, "page_total": page_total, "page_number": 0, "total": total}
return {
"results": agents,
"page_total": page_total,
"page_number": 0,
"total": total,
}
else:
error_msg = "Agent Listing Error: Please contact the administrators."
if isinstance(resp, dict) and "message" in resp:
Expand All @@ -486,7 +515,7 @@ def get(cls, agent_id: Text, api_key: Optional[Text] = None) -> Agent:

Args:
agent_id (Text): ID of the agent to retrieve.
api_key (Optional[Text], optional): API key for authentication.
api_key (Optional[Text], optional): API key for authentication.
Defaults to None, using the configured TEAM_API_KEY.

Returns:
Expand Down
9 changes: 6 additions & 3 deletions aixplain/factories/agent_factory/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def build_tool_payload(tool: Union[Tool, Model]):
"id": tool.id,
"name": tool.name,
"description": tool.description,
"supplier": tool.supplier.value["code"] if isinstance(tool.supplier, Supplier) else tool.supplier,
"supplier": (tool.supplier.value["code"] if isinstance(tool.supplier, Supplier) else tool.supplier),
"parameters": parameters,
"function": tool.function if hasattr(tool, "function") and tool.function is not None else None,
"function": (tool.function if hasattr(tool, "function") and tool.function is not None else None),
"type": "model",
"version": tool.version if hasattr(tool, "version") else None,
"assetId": tool.id,
Expand Down Expand Up @@ -155,7 +155,10 @@ def build_llm(payload: Dict, api_key: Text = config.TEAM_API_KEY) -> LLM:
# Convert parameters list to dictionary format expected by ModelParameters
params_dict = {}
for param in tool["parameters"]:
params_dict[param["name"]] = {"required": False, "value": param["value"]}
params_dict[param["name"]] = {
"required": False,
"value": param["value"],
}
# Create ModelParameters and set it on the LLM
from aixplain.modules.model.model_parameters import ModelParameters

Expand Down
Loading