AIKit을 사용하여 단 몇 줄의 코드로 여러 AI 제공자를 통합할 수 있습니다.
<script src="https://cdn.jsdelivr.net/gh/lukaPlayground/aikit@latest/dist/aikit.min.js"></script>
npm install @lukaplayground/aikit
GitHub Releases에서 최신 버전을 다운로드하세요.
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/gh/lukaPlayground/aikit@latest/dist/aikit.min.js"></script>
</head>
<body>
<script>
const ai = new AIKit({
provider: 'openai',
apiKey: 'your-openai-api-key'
});
ai.chat('Hello, AI!').then(response => {
console.log(response.text);
});
</script>
</body>
</html>
여러 AI 제공자를 설정하고 자동 폴백을 활성화할 수 있습니다:
const ai = new AIKit({
providers: [
{ name: 'openai', apiKey: 'key1', priority: 1 },
{ name: 'claude', apiKey: 'key2', priority: 2 },
{ name: 'gemini', apiKey: 'key3', priority: 3 }
],
autoFallback: true // 자동으로 다음 제공자로 전환
});
QA 기능을 활용한 응답 검증:
const response = await ai.chat('파이썬에 대해 설명해주세요', {
validate: {
minLength: 100,
maxLength: 1000,
mustInclude: ['파이썬', '프로그래밍'],
language: 'korean'
}
});
API 사용 비용을 실시간으로 추적:
const ai = new AIKit({
provider: 'openai',
apiKey: 'your-key',
enableCostTracking: true
});
await ai.chat('Hello');
const report = ai.getCostReport();
console.log(report);
// {
// total: "0.0023",
// totalUSD: "$0.0023",
// byProvider: { openai: "$0.0023" },
// ...
// }
중복 요청을 방지하여 비용 절감:
const ai = new AIKit({
provider: 'openai',
apiKey: 'your-key',
enableCache: true
});
// 첫 번째 요청 - API 호출
await ai.chat('2+2는?');
// 같은 질문 - 캐시에서 반환 (비용 없음)
await ai.chat('2+2는?');
new AIKit({
// 필수
provider: 'openai',
apiKey: 'your-key',
// 선택사항
enableCache: true,
enableCostTracking: true,
maxRetries: 3,
timeout: 30000,
autoFallback: false,
// 멀티 프로바이더
providers: [...]
});
ai.chat('your message', {
model: 'gpt-4',
temperature: 0.7,
maxTokens: 1000,
validate: {
minLength: 10,
maxLength: 1000,
mustInclude: ['keyword'],
format: 'json',
language: 'korean'
},
skipCache: false
});
// 통계 확인
const stats = ai.getStats();
// 비용 리포트
const cost = ai.getCostReport();
// 캐시 초기화
ai.clearCache();
// 설정 업데이트
ai.updateConfig({ provider: 'claude' });