Skip to main content

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=100

設定しない場合は、デフォルト値が使われます。 デフォルト値は以下の通りです。 openai/1000 google/8192 anthropic/1000

使い方

基本的な使い方

AI Managerを使用して、各社のAIサービスを呼び出す基本的な方法を示します。

from dotenv import load_dotenv
import os
from 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)

Google

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['choices'][0]['message']['content'])
    
    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

simple_ai_manager-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_ai_manager-0.1.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file simple_ai_manager-0.1.0.tar.gz.

File metadata

  • Download URL: simple_ai_manager-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for simple_ai_manager-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b944177cf50635642bac0a31d8c497e27eb3af2dce26e13175aacebad019cfec
MD5 9dee1c1119fdbd7c272838de9c54b332
BLAKE2b-256 ab55c074f9ab7df03ee57e26540e07f76dc7f55596c477c128eaacdc3ac167fe

See more details on using hashes here.

File details

Details for the file simple_ai_manager-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_ai_manager-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0f52647e9a022befa50fda6bee5b79b324e92f1b35b204b183012ce5c712657
MD5 e929a719754efdb2993803180644e887
BLAKE2b-256 43ed05d64f8732f3e781b95e4f2332f78b47e4fb2dbd7c0ace506a6cb431699f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page