A common management module for AI generation services
Project description
AI Manager
AI Managerは、複数のAIサービス(OpenAI, Google, Anthropicなど)を統一的に利用するためのPythonライブラリです。このライブラリを使用することで、各社のAPIキー管理や入力ルールを簡単に扱うことができます。
特徴
- 複数のAIサービスに対応(OpenAI, Google, Anthropic)
- APIキーの管理が容易
- 柔軟なAPI選択とプロンプト処理
- 環境変数による設定管理
- テキストに特化した設計
インストール
以下のコマンドを使用して、pip経由でライブラリをインストールします。
pip install simple-ai-manager
環境設定
環境変数を使用してAPIキーを管理します。プロジェクトディレクトリに.envファイルを作成し、以下のようにAPIキーを設定してください。
OPENAI_API_KEY=your_openai_api_key
GOOGLE_API_KEY=your_google_api_key
ANTHROPIC_API_KEY=your_anthropic_api_key
トークン数の制限をかけたい場合は、以下のように環境変数にMAX_TOKENSを書いて設定してください。
MAX_TOKENS=10000
設定しない場合は、デフォルト値が使われます。 デフォルト値は以下の通りです。 openai/1000 google/8192 anthropic/1000
使い方
基本的な使い方
AI Managerを使用して、各社のAIサービスを呼び出す基本的な方法を示します。
from dotenv import load_dotenv
import os
from simple_ai_manager import AIManager
# 環境変数の読み込み
load_dotenv()
# AIManagerのインスタンスを作成
ai_manager = AIManager()
# 使用するAIの会社、モデル、プロンプトを設定
company = 'openai' # 'google' または 'anthropic' も使用可能
model = 'text-davinci-003' # 例としてOpenAIのモデル名
prompt = 'Hello, how are you?'
# APIを呼び出してレスポンスを取得
try:
response = ai_manager.call_api(company, model, prompt)
print(response)
except Exception as e:
print(f'Error: {e}')
レスポンスはテキストだけに限定させています。 テキストを渡してテキストで貰うときに特化した簡略化ツールです。
各社のAIサービス利用例
OpenAI
company = 'openai'
model = 'text-davinci-003'
prompt = 'Hello, how are you?'
response = ai_manager.call_api(company, model, prompt)
print(response)
company = 'google'
model = 'text-bison-001'
prompt = 'Hello, how are you?'
response = ai_manager.call_api(company, model, prompt)
print(response)
Anthropic
company = 'anthropic'
model = 'claude'
prompt = 'Hello, how are you?'
response = ai_manager.call_api(company, model, prompt)
print(response)
AIからの返答をファイルに保存
AIからの返答を指定したディレクトリにyyyymmddhhmmss.txt形式で保存する方法を示します。
import datetime
company = 'openai'
model = 'text-davinci-003'
prompt = 'Hello, how are you?'
try:
response = ai_manager.call_api(company, model, prompt)
# 取得結果(AIからの返事)を保存するディレクトリ
save_dir = 'ai_responses'
if not os.path.exists(save_dir):
os.makedirs(save_dir)
# 現在の日時を使用してファイル名を生成
now = datetime.datetime.now()
timestamp = now.strftime('%Y%m%d%H%M%S')
file_path = os.path.join(save_dir, f'{timestamp}.txt')
# AIの返答をファイルに保存
with open(file_path, 'w') as file:
file.write(response)
print(f'Response saved to {file_path}')
except Exception as e:
print(f'Error: {e}')
貢献
バグの報告や機能のリクエストはGitHub Issuesで受け付けています。プルリクエストも歓迎します。
ライセンス
このプロジェクトはMITライセンスの下で提供されています
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simple_ai_manager-0.1.3.tar.gz.
File metadata
- Download URL: simple_ai_manager-0.1.3.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa816fe450bd199f30b141f24186b3be74bb1bd9496c31f762a6e8860776e145
|
|
| MD5 |
90c1f37fe51a96a4aa46fb62b71f38ab
|
|
| BLAKE2b-256 |
2ccecd7a15e08a85e74af2aa6bb742f49214fcd7cad80908e14499dd15c5d02f
|
File details
Details for the file simple_ai_manager-0.1.3-py3-none-any.whl.
File metadata
- Download URL: simple_ai_manager-0.1.3-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45c0c320a1d88f82dc5b4e8f92333f5eb55fc48e84d266d474a9bc0c9edc1862
|
|
| MD5 |
ce06a8a4976a750b50c5f102da85c544
|
|
| BLAKE2b-256 |
a0161dbf0a895e6470fe020f669e33136e73988395410121be7dbd317a1d1694
|