clientai
0.4.4
ClientAIは、直接プロバイダーの相互作用から透明なLLM駆動エージェントまで、OpenAI、Replicate、Groq、Ollamaのシームレスなサポートを提供するAIアプリケーションを構築するための統一されたフレームワークを提供するPythonパッケージです。
ドキュメント:igorbenav.github.io/clientai/
すべてのプロバイダーにclientaiをインストールするには、実行してください。
pip install " clientai[all] "または、特定のプロバイダーのみをインストールする場合は、
pip install " clientai[openai] " # For OpenAI support
pip install " clientai[replicate] " # For Replicate support
pip install " clientai[ollama] " # For Ollama support
pip install " clientai[groq] " # For Groq support from clientai import ClientAI
# Initialize with OpenAI
client = ClientAI ( 'openai' , api_key = "your-openai-key" )
# Generate text
response = client . generate_text (
"Tell me a joke" ,
model = "gpt-3.5-turbo" ,
)
print ( response )
# Chat functionality
messages = [
{ "role" : "user" , "content" : "What is the capital of France?" },
{ "role" : "assistant" , "content" : "Paris." },
{ "role" : "user" , "content" : "What is its population?" }
]
response = client . chat (
messages ,
model = "gpt-3.5-turbo" ,
)
print ( response ) from clientai import client
from clientai . agent import create_agent , tool
@ tool ( name = "calculator" )
def calculate_average ( numbers : list [ float ]) -> float :
"""Calculate the arithmetic mean of a list of numbers."""
return sum ( numbers ) / len ( numbers )
analyzer = create_agent (
client = client ( "groq" , api_key = "your-groq-key" ),
role = "analyzer" ,
system_prompt = "You are a helpful data analysis assistant." ,
model = "llama-3.2-3b-preview" ,
tools = [ calculate_average ]
)
result = analyzer . run ( "Calculate the average of these numbers: [1000, 1200, 950, 1100]" )
print ( result )保証された出力構造とタイプの安全性については:
from clientai . agent import Agent , think
from pydantic import BaseModel , Field
from typing import List
class Analysis ( BaseModel ):
summary : str = Field ( min_length = 10 )
key_points : List [ str ] = Field ( min_items = 1 )
sentiment : str = Field ( pattern = "^(positive|negative|neutral)$" )
class DataAnalyzer ( Agent ):
@ think (
name = "analyze" ,
json_output = True , # Enable JSON formatting
)
def analyze_data ( self , data : str ) -> Analysis : # Enable validation
"""Analyze data with validated output structure."""
return """
Analyze this data and return a JSON with:
- summary: at least 10 characters
- key_points: non-empty list
- sentiment: positive, negative, or neutral
Data: {data}
"""
# Initialize and use
analyzer = DataAnalyzer ( client = client , default_model = "gpt-4" )
result = analyzer . run ( "Sales increased by 25% this quarter" )
print ( f"Sentiment: { result . sentiment } " )
print ( f"Key Points: { result . key_points } " )以下を含むその他の例については、私たちのドキュメントを参照してください。
ClientAiエージェントモジュールは、4つのコア原則に基づいて構築されています。
プロンプト中心の設計:プロンプトは明示的で、デバッグ可能で、透明です。あなたが見るのは、モデルに送られるものです。
最初のカスタマイズ:すべてのコンポーネントは、拡張またはオーバーライドするように設計されています。カスタムステップ、ツールセレクター、またはまったく新しいワークフローパターンを作成します。
ゼロロックイン:高レベルのコンポーネントから始めて、必要に応じて低レベルにドロップダウンします。あなたはできる:
Agentを拡張します貢献は大歓迎です!詳細については、貢献ガイドラインをご覧ください。
このプロジェクトは、MITライセンスに基づいてライセンスされています。詳細については、ライセンスファイルを参照してください。
Igor Magalhaes - @igormagalhaesr - [email protected] github.com/igorbenav