clientai
0.4.4
ClientAI는 OpenAI, Replicate, Groq 및 Ollama에 대한 완벽한 지원을 통해 직접 공급자 상호 작용에서 투명한 LLM 구동 에이전트에 이르기까지 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 에이전트 모듈은 네 가지 핵심 원칙을 기반으로합니다.
프롬프트 중심 설계 : 프롬프트는 명시적이고 디지털화 가능하며 투명합니다. 당신이 보는 것은 모델로 전송되는 것입니다.
사용자 정의 먼저 : 모든 구성 요소는 확장되거나 재정의되도록 설계되었습니다. 사용자 정의 단계, 도구 선택기 또는 완전히 새로운 워크 플로 패턴을 만듭니다.
제로 잠금 장치 : 고급 구성 요소로 시작하여 필요에 따라 더 낮은 레벨로 떨어집니다. 당신은 할 수 있습니다 :
Agent 확장하십시오기부금을 환영합니다! 자세한 내용은 기고 가이드 라인을 참조하십시오.
이 프로젝트는 MIT 라이센스에 따라 라이센스가 부여됩니다. 자세한 내용은 라이센스 파일을 참조하십시오.
Igor Magalhaes - @igormagalhaesr - [email protected] github.com/igorbenav