
Adala 是一个 Autonomous DAta (Labeling) Agent(自主数据标注智能体)框架。
Adala 提供了一个强大的框架,用于实现专门处理数据的智能体,尤其侧重于多样化的数据标注任务。这些智能体是自主的,意味着它们可以通过迭代学习独立掌握一个或多个技能。学习过程受其运行环境、观察和反思的影响。用户通过提供基准事实数据集来定义环境。每个智能体都在我们称之为“运行时”(与 LLM 同义)的环境中学习和应用其技能。

Adala 是一个多功能框架,专为人工智能和机器学习领域的个人和专业人士设计。以下人群可以从中受益:
虽然上述角色是核心,但必须指出,Adala 经过精心设计,旨在简化和提升 AI 开发之旅,服务于所有爱好者,无论他们在该领域的具体细分领域如何。🥰
安装 Adala:
pip install adala
Adala 会频繁发布更新。为了确保您使用的是最新版本,建议从 GitHub 安装:
pip install git+https://github.com/HumanSignal/Adala.git
开发者安装:
git clone https://github.com/HumanSignal/Adala.git
cd Adala/
poetry install
设置 OPENAI_API_KEY(查看此处的说明)
export OPENAI_API_KEY='your-openai-api-key'
在这个例子中,我们将直接在 Python notebook 中使用 Adala 作为独立库。
点击此处查看扩展的快速入门示例。
import pandas as pd
from adala.agents import Agent
from adala.environments import StaticEnvironment
from adala.skills import ClassificationSkill
from adala.runtimes import OpenAIChatRuntime
from rich import print
# 训练数据集
train_df = pd.DataFrame([
["It was the negative first impressions, and then it started working.", "Positive"],
["Not loud enough and doesn't turn on like it should.", "Negative"],
["I don't know what to say.", "Neutral"],
["Manager was rude, but the most important that mic shows very flat frequency response.", "Positive"],
["The phone doesn't seem to accept anything except CBR mp3s.", "Negative"],
["I tried it before, I bought this device for my son.", "Neutral"],
], columns=["text", "sentiment"])
# 测试数据集
test_df = pd.DataFrame([
"All three broke within two months of use.",
"The device worked for a long time, can't say anything bad.",
"Just a random line of text."
], columns=["text"])
agent = Agent(
# 连接到数据集
environment=StaticEnvironment(df=train_df),
# 定义一项技能
skills=ClassificationSkill(
name='sentiment',
instructions="Label text as positive, negative or neutral.",
labels=["Positive", "Negative", "Neutral"],
input_template="Text: {text}",
output_template="Sentiment: {sentiment}"
),
# 定义您的技能可能使用的所有不同运行时
runtimes = {
# 您可以在此处通过 `OpenAIRuntime(..., api_key='your-api-key')` 指定您的 OPENAI API KEY
'openai': OpenAIChatRuntime(model='gpt-4o'),
},
teacher_runtimes = {
# 您可以在此处通过 `OpenAIRuntime(..., api_key='your-api-key')` 指定您的 OPENAI API KEY
'default': OpenAIChatRuntime(model='gpt-4o'),
},
default_runtime='openai',
)
print(agent)
print(agent.skills)
agent.learn(learning_iterations=3, accuracy_threshold=0.95)
print('\n=> Run tests ...')
predictions = agent.run(test_df)
print('\n => Test results:')
print(predictions)
但是,如果您希望使用 Claude、Gemini 或其他与 OpenAI 兼容的 LLMs,可以通过 OpenRouter.ai 来实现。以下是如何使用 OpenRouter API 的示例:
首先设置 OPENROUTER_API_KEY 环境变量,您可以从 OpenRouter 获取。
export OPENROUTER_API_KEY='your-openrouter-api-key'
然后,让我们看看如何修改前面的示例以使用 OpenRouter 和 Claude 3.5 Haiku。
import os
import pandas as pd
from adala.agents import Agent
from adala.environments import StaticEnvironment
from adala.skills import ClassificationSkill
from adala.runtimes import OpenAIChatRuntime
from rich import print
# 训练数据集
train_df = pd.DataFrame([
["It was the negative first impressions, and then it started working.", "Positive"],
["Not loud enough and doesn't turn on like it should.", "Negative"],
["I don't know what to say.", "Neutral"],
["Manager was rude, but the most important that mic shows very flat frequency response.", "Positive"],
["The phone doesn't seem to accept anything except CBR mp3s.", "Negative"],
["I tried it before, I bought this device for my son.", "Neutral"],
], columns=["text", "sentiment"])
# 测试数据集
test_df = pd.DataFrame([
"All three broke within two months of use.",
"The device worked for a long time, can't say anything bad.",
"Just a random line of text."
], columns=["text"])
agent = Agent(
# 连接到数据集
environment=StaticEnvironment(df=train_df),
# 定义一项技能
skills=ClassificationSkill(
name='sentiment',
instructions="Label text as positive, negative or neutral.",
labels=["Positive", "Negative", "Neutral"],
input_template="Text: {text}",
output_template="Sentiment: {sentiment}"
),
# 定义您的技能可能使用的所有不同运行时
runtimes = {
# 您可以在此处指定您的 OpenRouter API Key,或提前在环境变量 OPENROUTER_API_KEY 中设置
'openrouter': OpenAIChatRuntime(
base_url="https://openrouter.ai/api/v1",
model="anthropic/claude-3.5-haiku",
api_key=os.getenv("OPENROUTER_API_KEY"),
provider="Custom"
),
},
default_runtime='openrouter',
teacher_runtimes = {
"default" : OpenAIChatRuntime(
base_url="https://openrouter.ai/api/v1",
model="anthropic/claude-3.5-haiku",
api_key=os.getenv("OPENROUTER_API_KEY"),
provider="Custom"
),
}
)
print(agent)
print(agent.skills)
agent.learn(learning_iterations=3, accuracy_threshold=0.95)
print('\n=> Run tests ...')
predictions = agent.run(test_df)
print('\n => Test results:')
print(predictions)
| 技能 | 描述 | Colab |
|---|---|---|
| ClassificationSkill | 将文本分类到一组预定义的标签中。 | |
| ClassificationSkillWithCoT | 使用思维链推理,将文本分类到一组预定义的标签中。 | |
| SummarizationSkill | 将文本总结为更短的文本。 | |
| QuestionAnsweringSkill | 根据给定的上下文回答问题。 | |
| TranslationSkill | 将文本从一种语言翻译到另一种语言。 | |
| TextGenerationSkill | 根据给定的提示生成文本。 | |
| Skill sets | 通过一系列技能处理复杂任务。 | |
| OntologyCreator | 从一组文本示例中推断本体。 | |
| Math reasoning | 解决 GSM8k 数据集上的小学数学问题。 | |

增强技能、优化运行时,或开创新的智能体类型。无论您是精心设计细微的任务、优化计算环境,还是为特定领域定制专门的智能体,您的贡献都将推动 Adala 的演进。加入我们,共同塑造智能系统的未来,使 Adala 对全球用户来说更加多功能和具有影响力。
您需要帮助或希望与社区互动吗?查看 Discord 频道!
无论您有问题、需要澄清,还是只是想讨论与项目相关的话题,Discord 社区都欢迎您!