Skip to main content

Cloud Security Alliance AI Foundation Model API Clients

Project description

Cloud Security Alliance AI Foundation Model API Clients

This Python library (csa_ai_foundation_model_api_clients) provides API access to text completions for:

  • Anthropic Claude 3
  • Google Gemini 1.5
  • OpenAI ChatGPT 4

and has plans to add:

  • OpenAI ChatGPT 4 batch mode

You can set the following options:

  • system prompt (aka developer prompt, persona)
  • user prompt (aka instructions)
  • user data (as part of the user prompt)
  • temperature
  • max_tokens

and has plans to add:

  • top_p
  • top_k
  • model specific paramaters

Please note this code does not have tests, or good error handling, but it works. Also with respect to handling rate limiting that is on the todo, but currently if you use this tool put a sleep statement to slow it down.

The code will be looking for the API key as an env variable:

  • ANTHROPIC_CLAUDE_API_KEY
  • GOOGLE_GEMINI_API_KEY
  • OPENAI_CHATGPT_API_KEY

Examples:

Using this as a library:

#!/usr/bin/env python3

import os

from csa_ai_foundation_model_api_clients import FoundationModelAPIClient

def main():
    model_name = 'claude' # or "claude-haiku" or "chatgpt" or "gemini"
    api_key = "SECRET_API_KEY_VALUE" # You can remove api_key here if the env variable is set 

    client = FoundationModelAPIClient(model_name, api_key) # You can remove api_key here if the env variable is set 

    system_prompt = "You are a helpful assistant who speaks in rhymes."
    user_prompt = "What is the capital of France?"
    user_data = None
    output_file = 'response.json'

    response = client.generate_response(
        system_prompt,
        user_prompt,
        user_data,
        temperature=0.7,
        max_tokens=100,
        output_file=output_file
    )

if __name__ == '__main__':
    main()

Using this as a command line tool (you must be in the directory where csa_ai_foundation_model_api_clients.py is because of a relative import path):

./csa_ai_foundation_model_api_clients.py \
    --model chatgpt \
    --system system-prompt.txt \
    --user-prompt user-prompt.txt \
    --user-data user-data.txt \
    --output output.json \
    --temperature 0.9 \
    --max_tokens 2000

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

csa_ai_foundation_model_api_clients-0.1.1.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file csa_ai_foundation_model_api_clients-0.1.1.tar.gz.

File metadata

File hashes

Hashes for csa_ai_foundation_model_api_clients-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5c121a350b420bd97fd6cf10a36e11bf6059e5f87dbacf06ecce5bd387eec45d
MD5 8090514ae932869c4420a09fae832717
BLAKE2b-256 78dd49c447ffc3e9e4ec575e7a31de9aae5161faeb240818617decac86cc6edf

See more details on using hashes here.

File details

Details for the file csa_ai_foundation_model_api_clients-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for csa_ai_foundation_model_api_clients-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 28f37330d06e11d26c9885f68f9d66d5d9d6d4ddc9f3c67d58240883668d7541
MD5 1cae98c563db8a33e264f97f58064e69
BLAKE2b-256 d2f6942bfd4a11730fa3798f6bda8e82ad96358f1ffd136b3b850c9e6de1519f

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