長話短說

對我來說,人工智慧無所不在。每個人都想做人工智慧。

但有時,很難知道要掌握哪些工具才能在應用程式中成功實現人工智慧功能。

因此,我整理了一份儲存庫列表,您可以在其中學習掌握人工智慧巫術。

奇士 GIF


  1. Composition 👑:建構 AI 自動化速度提高 10 倍🚀

工具和整合構成了建構人工智慧代理的核心。

我一直在建立 AI 工具和代理,但工具的準確性一直是一個問題,直到我遇到 Composio。

Composio 可以輕鬆整合 GitHub、Slack、Jira、Airtable 等流行應用程式,並更輕鬆地與 AI 代理整合以建立複雜的自動化。

它代表您的使用者處理整合的使用者身份驗證和授權。這樣您就可以安心地建立您的 AI 應用程式。並且它通過了 SOC2 認證。

那麼,您可以按照以下方法開始使用它。

Python

pip install composio-core

新增 GitHub 整合。

composio add github

Composio 代表您處理使用者身份驗證和授權。

以下是如何使用 GitHub 整合來為儲存庫加註星標。

from openai import OpenAI
from composio_openai import ComposioToolSet, App

openai_client = OpenAI(api_key="******OPENAIKEY******")

# Initialise the Composio Tool Set
composio_toolset = ComposioToolSet(api_key="**\\*\\***COMPOSIO_API_KEY**\\*\\***")

## Step 4
# Get GitHub tools that are pre-configured
actions = composio_toolset.get_actions(actions=[Action.GITHUB_ACTIVITY_STAR_REPO_FOR_AUTHENTICATED_USER])

## Step 5
my_task = "Star a repo ComposioHQ/composio on GitHub"

# Create a chat completion request to decide on the action
response = openai_client.chat.completions.create(
model="gpt-4-turbo",
tools=actions, # Passing actions we fetched earlier.
messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": my_task}
  ]
)

執行此 Python 腳本以使用代理程式執行給定的指令。

Composio 可與 LangChain、LlamaIndex、CrewAi 等著名框架搭配使用。

有關更多訊息,請存取官方文件,有關更複雜的示例,請參閱存儲庫的示例部分。

合成 GIF

{% cta https://dub.composio.dev/FZLK76b %}為 Composio 儲存庫加註星標 ⭐{% endcta %}


  1. Unsloth :AI模型更快的訓練和微調

訓練和微調大型語言模型 (LLM) 是人工智慧工程的重要組成部分。

在許多情況下,專有模型可能無法達到目的。它可能是成本、個性化或隱私。在某些時候,您將需要在自訂資料集上微調您的模型。目前,Unsloth 是微調和培訓 LLM 的最佳資料庫之一。

它支援流行的LLM 的完整、LoRA 和QLoRA 微調,包括Llama-3 和Mistral 及其衍生品,如Yi、Open-hermes 等。 3 和Mistral 等的速度。

要開始使用 Unsloth,請使用pip安裝它,並確保您有torch 2.4CUDA 12.1

pip install --upgrade pip
pip install "unsloth[cu121-torch240] @ git+https://github.com/unslothai/unsloth.git"

這是一個使用 SFT(監督微調)在資料集上訓練 Mistral 模型的簡單腳本

from unsloth import FastLanguageModel 
from unsloth import is_bfloat16_supported
import torch
from trl import SFTTrainer
from transformers import TrainingArguments
from datasets import load_dataset
max_seq_length = 2048 # Supports RoPE Scaling internally, so choose any!
# Get LAION dataset
url = "https://huggingface.co/datasets/laion/OIG/resolve/main/unified_chip2.jsonl"
dataset = load_dataset("json", data_files = {"train" : url}, split = "train")

# 4bit pre quantized models we support for 4x faster downloading + no OOMs.
fourbit_models = [
    "unsloth/mistral-7b-v0.3-bnb-4bit",      # New Mistral v3 2x faster!
] # More models at https://huggingface.co/unsloth

model, tokenizer = FastLanguageModel.from_pretrained(
    model_name = "unsloth/llama-3-8b-bnb-4bit",
    max_seq_length = max_seq_length,
    dtype = None,
    load_in_4bit = True,
)

# Do model patching and add fast LoRA weights
model = FastLanguageModel.get_peft_model(
    model,
    r = 16,
    target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
                      "gate_proj", "up_proj", "down_proj",],
    lora_alpha = 16,
    lora_dropout = 0, # Supports any, but = 0 is optimized
    bias = "none",    # Supports any, but = "none" is optimized
    # [NEW] "unsloth" uses 30% less VRAM, fits 2x larger batch sizes!
    use_gradient_checkpointing = "unsloth", # True or "unsloth" for very long context
    random_state = 3407,
    max_seq_length = max_seq_length,
    use_rslora = False,  # We support rank stabilized LoRA
    loftq_config = None, # And LoftQ
)

trainer = SFTTrainer(
    model = model,
    train_dataset = dataset,
    dataset_text_field = "text",
    max_seq_length = max_seq_length,
    tokenizer = tokenizer,
    args = TrainingArguments(
        per_device_train_batch_size = 2,
        gradient_accumulation_steps = 4,
        warmup_steps = 10,
        max_steps = 60,
        fp16 = not is_bfloat16_supported(),
        bf16 = is_bfloat16_supported(),
        logging_steps = 1,
        output_dir = "outputs",
        optim = "adamw_8bit",
        seed = 3407,
    ),
)
trainer.train()

更多資訊請參考官方文件

不懶惰 IMG

{% cta https://github.com/unslothai/unsloth %}為 Unsloth 儲存庫加註星標 ⭐{% endcta %}


  1. DsPy :LLM 程式框架

阻礙 LLM 在生產用例中使用的因素之一是其隨機性。對於這些用例來說,提示他們輸出所需的回應的失敗率很高。

DsPy 正在解決這個問題。它不是提示,而是對LLMs進行編程以獲得最大的可靠性。

DSPy 透過執行兩項關鍵操作來簡化此操作:

  1. 將程式流程與參數分開:此功能可使程式流程(您採取的步驟)與每個步驟如何完成的詳細資訊(LM 提示和權重)分開。這使得管理和更新您的系統變得更加容易。

  2. 引入新的優化器: DSPy 使用先進的演算法,根據您的目標(例如提高準確性或減少錯誤)自動微調 LM 提示和權重。

請查看此入門筆記本,以了解有關如何使用 DsPy 的更多資訊。

dspy gif

{% cta https://github.com/stanfordnlp/dspy %}為 DsPy 儲存庫加註星標 ⭐{% endcta %}


  1. TaiPy :使用 Python 更快地建立 AI Web 應用程式

Taipy 是一款基於 Python 的開源軟體,專為在生產環境中建立 AI Web 應用程式而設計。它使 Python 開發人員能夠在生產中部署演示應用程式,從而增強了 Streamlit 和 Gradio。

Taipy 專為資料科學家和機器學習工程師建立資料和 AI Web 應用程式而設計。

  1. 能夠建立生產就緒的 Web 應用程式

  2. 無需學習新語言。只需要Python。

  3. 專注於資料和人工智慧演算法,無需開發和部署複雜性。

使用pip快速開始使用它。

pip install taipy

這個簡單的 Taipy 應用程式示範如何使用 Taipy 建立基本的電影推薦系統。

import taipy as tp
import pandas as pd
from taipy import Config, Scope, Gui

# Defining the helper functions

# Callback definition - submits scenario with genre selection
def on_genre_selected(state):
    scenario.selected_genre_node.write(state.selected_genre)
    tp.submit(scenario)
    state.df = scenario.filtered_data.read()

## Set initial value to Action
def on_init(state):
    on_genre_selected(state)

# Filtering function - task
def filter_genre(initial_dataset: pd.DataFrame, selected_genre):
    filtered_dataset = initial_dataset[initial_dataset["genres"].str.contains(selected_genre)]
    filtered_data = filtered_dataset.nlargest(7, "Popularity %")
    return filtered_data

# The main script
if __name__ == "__main__":
    # Taipy Scenario & Data Management

    # Load the configuration made with Taipy Studio
    Config.load("config.toml")
    scenario_cfg = Config.scenarios["scenario"]

    # Start Taipy Core service
    tp.Core().run()

    # Create a scenario
    scenario = tp.create_scenario(scenario_cfg)

    # Taipy User Interface
    # Let's add a GUI to our Scenario Management for a complete application

    # Get list of genres
    genres = [
        "Action", "Adventure", "Animation", "Children", "Comedy", "Fantasy", "IMAX"
        "Romance","Sci-FI", "Western", "Crime", "Mystery", "Drama", "Horror", "Thriller", "Film-Noir","War", "Musical", "Documentary"
    ]

    # Initialization of variables
    df = pd.DataFrame(columns=["Title", "Popularity %"])
    selected_genre = "Action"

    # User interface definition
    my_page = """
# Film recommendation

## Choose your favorite genre
<|{selected_genre}|selector|lov={genres}|on_change=on_genre_selected|dropdown|>

## Here are the top seven picks by popularity
<|{df}|chart|x=Title|y=Popularity %|type=bar|title=Film Popularity|>
    """

    Gui(page=my_page).run()

查看文件以了解更多資訊。

太比 gif

{% cta https://github.com/avaiga/taipy %}Star Taipy 儲存庫 ⭐{% endcta %}


  1. Phidata :使用記憶體建構LLM代理。

通常,建立有效的代理可能並不像聽起來那麼容易。管理記憶體、快取和工具執行可能變得具有挑戰性。

Phidata 是一個開源框架,它提供了一種方便可靠的方法來建立具有長期記憶、上下文知識以及使用函數呼叫採取行動的能力的代理。

透過pip安裝開始使用 Phidata

pip install -U phidata

我們來建立一個簡單的助手,可以查詢財務資料。

from phi.assistant import Assistant
from phi.llm.openai import OpenAIChat
from phi.tools.yfinance import YFinanceTools

assistant = Assistant(
    llm=OpenAIChat(model="gpt-4o"),
    tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True)],
    show_tool_calls=True,
    markdown=True,
)
assistant.print_response("What is the stock price of NVDA")
assistant.print_response("Write a comparison between NVDA and AMD, use all tools available.")

一個可以上網的助手。

from phi.assistant import Assistant
from phi.tools.duckduckgo import DuckDuckGo

assistant = Assistant(tools=[DuckDuckGo()], show_tool_calls=True)
assistant.print_response("Whats happening in France?", markdown=True)

請參閱官方文件以取得範例和資訊。

菲達特IMG

{% cta https://github.com/phidatahq/phidata %}明星 Phidata 儲存庫 ⭐{% endcta %}


  1. Phoenix :LLM可觀察性變得高效

建立人工智慧應用程式只能透過加入可觀察層來完成。通常,LLM 會申請有許多變化的部分,例如提示、模型溫度、p 值等,即使發生微小的變化,也會對結果產生重大影響。

這會使應用程式高度不穩定且不可靠。這就是LLMs可觀察性發揮作用的地方。 ArizeAI 的 Phoneix 可以輕鬆追蹤 LLM 執行的整個追蹤。

它是一個開源人工智慧可觀察平台,專為實驗、評估和故障排除而設計。它提供:

  • 追蹤- 使用基於 OpenTelemetry 的儀器追蹤 LLM 應用程式的執行時。

  • 評估- 利用LLMs透過回應和檢索評估來對應用程式的性能進行基準測試。

  • 資料集- 建立範例的版本資料集以進行實驗、評估和微調。

  • 實驗- 追蹤和評估提示、LLM 和檢索更改。

Phoenix 與供應商和語言無關,支援 LlamaIndex、LangChain、DSPy 等框架以及 OpenAI 和 Bedrock 等 LLM 供應商。

它可以在各種環境中執行,包括 Jupyter 筆記本、本機電腦、容器或雲端。

Phoneix 上手很簡單。

pip install arize-phoenix

首先,啟動 Phoenix 應用程式。

import phoenix as px
session = px.launch_app()

這將啟動 Phoneix 伺服器。

現在,您可以為 AI 應用程式設定跟踪,以便在跟踪流入時除錯您的應用程式。

若要使用 LlamaIndex 的一鍵功能,您必須先安裝小型整合:

pip install 'llama-index>=0.10.44'
import phoenix as px
from openinference.instrumentation.llama_index import LlamaIndexInstrumentor
import os
from gcsfs import GCSFileSystem
from llama_index.core import (
    Settings,
    VectorStoreIndex,
    StorageContext,
    set_global_handler,
    load_index_from_storage
)
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.llms.openai import OpenAI
import llama_index

# To view traces in Phoenix, you will first have to start a Phoenix server. You can do this by running the following:
session = px.launch_app()

# Initialize LlamaIndex auto-instrumentation
LlamaIndexInstrumentor().instrument()

os.environ["OPENAI_API_KEY"] = "<ENTER_YOUR_OPENAI_API_KEY_HERE>"

# LlamaIndex application initialization may vary
# depending on your application
Settings.llm = OpenAI(model="gpt-4-turbo-preview")
Settings.embed_model = OpenAIEmbedding(model="text-embedding-ada-002")

# Load your data and create an index. Here we've provided an example of our documentation
file_system = GCSFileSystem(project="public-assets-275721")
index_path = "arize-phoenix-assets/datasets/unstructured/llm/llama-index/arize-docs/index/"
storage_context = StorageContext.from_defaults(
    fs=file_system,
    persist_dir=index_path,
)

index = load_index_from_storage(storage_context)

query_engine = index.as_query_engine()

# Query your LlamaIndex application
query_engine.query("What is the meaning of life?")
query_engine.query("How can I deploy Arize?")

# View the traces in the Phoenix UI
px.active_session().url

一旦您為應用程式執行了足夠數量的查詢(或聊天),您就可以透過刷新瀏覽器 URL 來查看 UI 的詳細資訊。

請參閱他們的文件以獲取更多追蹤、資料集版本控制和評估範例。

鳳凰城 GIF

{% cta https://github.com/Arize-ai/phoenix %}Star Phoenix 儲存庫 ⭐{% endcta %}


  1. Airbyte :可靠且可擴展的資料管道

資料對於建立人工智慧應用至關重要,尤其是在生產中,您必須管理來自不同來源的大量資料。 Airbyte 在這方面表現出色。

Airbyte 為 API、資料庫、資料倉儲和資料湖提供了包含 300 多個連接器的廣泛目錄

Airbyte 還具有一個名為 PyAirByte 的 Python 擴充功能。此擴充功能支援 LangChain 和 LlamaIndex 等流行框架,讓您可以輕鬆地將資料從多個來源移至 GenAI 應用程式。

請參閱此筆記本,以了解有關使用 LangChain 實現 PyAirByte 的詳細資訊。

有關更多訊息,請查看文件

空中位元組 gif

{% cta https://github.com/airbytehq/airbyte %}Star AirByte 儲存庫 ⭐{% endcta %}


  1. AgentOps :代理監控和可觀察性

就像傳統的軟體系統一樣,人工智慧代理需要持續的監控和觀察。這對於確保代理人的行為不偏離期望非常重要。

AgentOps 提供了監控和觀察 AI 代理程式的全面解決方案。

它提供用於回放分析、LLM 成本管理、代理基準測試、合規性和安全性的工具,並與 CrewAI、AutoGen 和 LangChain 等框架進行本地整合。

透過pip安裝 AgentOps 來開始使用它。

pip install agentops

初始化 AgentOps 用戶端並自動取得每個 LLM 呼叫的分析。

import agentops

# Beginning of program's code (i.e. main.py, __init__.py)
agentops.init( < INSERT YOUR API KEY HERE >)

...

# (optional: record specific functions)
@agentops.record_action('sample function being record')
def sample_function(...):
    ...

# End of program
agentops.end_session('Success')
# Woohoo You're done 🎉

有關更多訊息,請參閱他們的文件

代理行動 GIF

{% cta https://github.com/AgentOps-AI/agentops %}明星 AgentOps 儲存庫 ⭐{% endcta %}


  1. RAGAS :RAG評估框架

建立 RAG 管道具有挑戰性,但確定其在現實場景中的有效性則是另一回事。儘管 RAG 應用程式框架取得了進步,但確保真實用戶的可靠性仍然很困難,特別是當錯誤檢索的成本很高時。

RAGAS是一個旨在解決這個問題的框架。它可以幫助您評估檢索增強生成 (RAG) 管道。

它可以幫助您產生綜合測試集,針對它們測試您的 RAG 管道,並在生產中監控您的 RAG 應用程式。

查看文件以了解如何使用 RAGAS 改進新的和現有的 RAG 管道。

拉格斯文件

{% cta https://github.com/explodinggradients/ragas %}Star RAGAS 儲存庫 ⭐{% endcta %}


感謝您閱讀這篇文章。如果您已經建立或使用任何其他開源 AI 儲存庫,請在下面發表評論。


原文出處:https://dev.to/composiodev/9-essential-open-source-libraries-to-master-as-an-ai-developer-o98


共有 0 則留言