Skip to main content

Cloud Security Alliance AI Foundation Model API Clients

Project description

Cloud Security Alliance AI Foundation Model API Clients

You can get this library at https://pypi.org/project/csa-ai-foundation-model-api-clients/ or via:

pip install csa-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

from csa_ai_foundation_model_api_clients import FoundationModelAPIClient

def main():
    model = 'claude'
    system_prompt = "You are a helpful assistant who answers in rhyme."
    user_prompt = "What is the capital of "
    user_data = "France?"
    output_file = 'claude-response.json'

    FoundationModelAPIClient(
        model=model,
        system_prompt=system_prompt,
        system_prompt_type="text",
        user_prompt=user_prompt,
        user_prompt_type="text",
        user_data=user_data,
        user_data_type="text",
        temperature=0.7,
        max_tokens=100,
        output_file=output_file
    )

if __name__ == '__main__':
    main()

Using this as a command line tool by calling it as a module (please note all prompts MUST be files currently when used as a command line tool):

python3 -m csa_ai_foundation_model_api_clients.csa_ai_foundation_model_api_clients \
    --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.10.tar.gz (11.8 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.10.tar.gz.

File metadata

File hashes

Hashes for csa_ai_foundation_model_api_clients-0.1.10.tar.gz
Algorithm Hash digest
SHA256 f610e1e8f329fbd94bdc755de61f619ec9e9f3266839ba99153f212c579f1627
MD5 b787978b054f47b483d453b078a42599
BLAKE2b-256 4e123f5e09e81c08c321d9677c0dc5617251b5743df1c86a8b3c05ecccb5751b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for csa_ai_foundation_model_api_clients-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 3ffe724d9eb7c808c26fe73ba3c1b090065081801f32fe9018a66521baa24401
MD5 18b7e7340fd7858ab29afd7df1c3fef0
BLAKE2b-256 cb45fd2c6d2f3ea3cabe8da0a56bc82f7932a6c7467e9e29412bc4d6d626d2ba

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