Skip to main content



Sinapsis OpenAI

Templates for seamless integration with OpenAI's powerful APIs

🐍 Installation • 🚀 Features • 📚 Usage example • 🌐 Webapp • 📙 Documentation • 🔍 License

Sinapsis OpenAI provides a powerful and flexible implementation for leveraging OpenAI's APIs. It enables users to easily configure and run various AI tasks including chat completions, audio processing, and image generation/editing.

🐍 Installation

Install using your package manager of choice. We encourage the use of uv

Example with uv:

  uv pip install sinapsis-openai --extra-index-url https://pypi.sinapsis.tech

or with raw pip:

  pip install sinapsis-openai --extra-index-url https://pypi.sinapsis.tech

🚀 Features

Templates Supported

This module includes multiple templates tailored for different OpenAI tasks:

  • OpenAIChatWrapper: Enables chat completions using OpenAI's chat API, supporting models like GPT-4 and GPT-3.5-turbo.
  • OpenAIAudioTranslationWrapper: Translates audio input into text in another language using Whisper models.
  • OpenAIAudioTranscriptionWrapper: Converts audio input into text, supporting multiple languages and long audio files.
  • OpenAIAudioCreationWrapper: Generates audio from text using speech synthesis with multiple voice options.
  • OpenAIImageCreationWrapper: Creates images from text prompts using DALL-E models, with configurable sizes and formats.
  • OpenAIImageEditionWrapper: Edits images using OpenAI's image editing API, supporting inpainting and variations.
🌍 General Attributes

All templates share the following attribute:

  • model: Determines which model to use depending on the task chosen.
  • openai_init: Dictionary of attributes related to the arguments of the OpenAI client method. Ensure that values are assigned correctly according to the official OpenAI documentation.
Specific Attributes

There are some attributes specific to the templates used:

  • OpenAIChatWrapper has one additional attribute:
    • create (dict, optional): Dictionary of attributes related to the arguments of the OpenAI create method. Ensure that values are assigned correctly according to the official OpenAI chat documentation.
  • OpenAIAudioTranslationWrapper has one additional attribute:
    • create (dict, optional): Dictionary of attributes related to the arguments of the OpenAI create method. Ensure that values are assigned correctly according to the official OpenAI audio documentation.
  • OpenAIAudioTranscriptionWrapper has two additional attributes:
    • create (dict, optional): Dictionary of attributes related to the arguments of the OpenAI create method. Ensure that values are assigned correctly according to the official OpenAI audio documentation.
  • OpenAIAudioCreationWrapper has two additional attributes:
    • output_dir (str, optional): Relative path where the binary audio output file will be saved. Defaults to openai/openai_audio.mp4.
    • create (dict, optional): Dictionary of attributes related to the arguments of the OpenAI create method. Ensure that values are assigned correctly according to the official OpenAI audio documentation.
  • OpenAIImageCreationWrapper has two additional attributes:
    • response_format (Literal, optional): Specifies the format of the API response. Defaults to url.
    • generate (dict, optional): Dictionary of attributes related to the arguments of the OpenAI generate method. Ensure that values are assigned correctly according to the official OpenAI image documentation.
  • OpenAIImageEditionWrapper has three additional attributes:
    • path_to_mask (str, optional): File path to a mask image.
    • path_to_image (str, required): The file path of the original image to be edited. The image is expected to be in png format.
    • edit (dict, optional): Dictionary of attributes related to the arguments of the OpenAI edit method. Ensure that values are assigned correctly according to the official OpenAI image documentation.

For example, for OpenAIImageCreationWrapper use sinapsis info --example-template-config OpenAIImageCreationWrapper to produce an example config like:

agent:
  name: my_test_agent
templates:
- template_name: InputTemplate
  class_name: InputTemplate
  attributes: {}
- template_name: OpenAIImageCreationWrapper
  class_name: OpenAIImageCreationWrapper
  template_input: InputTemplate
  attributes:
    model: 'dall-e-3'
    response_format: url
    openai_init:
      api_key: null
      organization: null
      project: null
      base_url: null
      websocket_base_url: null
      timeout: 2
      max_retries: 2
      default_headers: null
      default_query: null
      http_client: null
    generate:
      n: 1
      quality: 'standard'
      size: '256x256'
      style: 'vivid'
      user: 'my user'
      extra_headers: null
      extra_query: null
      extra_body: null
      timeout: 2

📚 Usage example

Below is an example YAML configuration for chat completions using OpenAI's GPT-4. In this example, we define an agent named my_test_agent and configure a chat template to process a text input ("What is AI?"). The chat template uses GPT-4 with a temperature of 0.2 and limits the response to a maximum of 60 completion tokens. Environment variables are used for API authentication.

Config
agent:
  name: my_test_agent
  description: "Chat example"

templates:

- template_name: InputTemplate
  class_name: InputTemplate
  attributes: {}

- template_name: TextInput
  class_name: TextInput
  template_input: InputTemplate
  attributes:
    text : What is AI?

- template_name: OpenAIChat
  class_name: OpenAIChatWrapper
  template_input: TextInput
  attributes:
    model : gpt-4
    openai_init: {}
    create:
      temperature: 0.2
      max_completion_tokens: 60
This configuration defines an **agent** and a sequence of **templates** to create a chat completion using OpenAI GPT-4.

To run the config, use the CLI:

sinapsis run name_of_config.yml

🌐 Webapp

The webapp provides a simple interface to generate images using OpenAI's DALL-E 3. Just input your text prompt, and the app will create and display the generated image.

git clone git@github.com:Sinapsis-ai/sinapsis-openai.git
cd sinapsis-openai
- template_name: TextInput
  class_name: TextInput
  template_input: InputTemplate
  attributes:
    text: "Your new prompt here"
🐳 Docker

IMPORTANT This docker image depends on the sinapsis:base image. Please refer to the official sinapsis instructions to Build with Docker.

  1. Build the sinapsis-openai image:
docker compose -f docker/compose.yaml build
  1. Start the app container:
docker compose -f docker/compose_apps.yaml up sinapsis-openai-gradio -d
  1. Check the status:
docker logs -f sinapsis-openai-gradio
  1. The logs will display the URL to access the webapp, e.g.:

NOTE: The url can be different, check the output of logs

Running on local URL:  http://127.0.0.1:7860
  1. To stop the app:
docker compose -f docker/compose_apps.yaml down
💻 UV

To run the webapp using the uv package manager, please:

  1. Create the virtual environment and sync the dependencies:
uv sync --frozen
  1. Install the wheel:
uv pip install sinapsis-openai[all] --extra-index-url https://pypi.sinapsis.tech
  1. Activate the environment:
source .venv/bin/activate
  1. Run the webapp:
python webapps/image_creation.py
  1. The terminal will display the URL to access the webapp, e.g.:

NOTE: The url can be different, check the output of the terminal

Running on local URL:  http://127.0.0.1:7860

📙 Documentation

Documentation for this and other sinapsis packages is available on the sinapsis website

Tutorials for different projects within sinapsis are available at sinapsis tutorials page

🔍 License

This project is licensed under the AGPLv3 license, which encourages open collaboration and sharing. For more details, please refer to the LICENSE file.

For commercial use, please refer to our official Sinapsis website for information on obtaining a commercial license.

Metadata

Release files for sinapsis-openai 0.1.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sinapsis-openai 0.1.13
File Size Uploaded
sinapsis_openai-0.1.13.tar.gz 19.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sinapsis-openai 0.1.13
File Interpreter ABI Platform
sinapsis_openai-0.1.13-py3-none-any.whl Python 3 none any Details

Total release size: 40.1 kB

Release files / sinapsis_openai-0.1.13.tar.gz

Download URL sinapsis_openai-0.1.13.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
26b4bf35a94896251d03f0f5107a5d4612680709092ff4299bdfe75797523063
BLAKE2b-256 checksum
How to use checksums
642a47cccb4bf5607cec55fd84884e0a1bb3d04a75da5a568193fc72c1655b21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.16

Release files / sinapsis_openai-0.1.13-py3-none-any.whl

Download URL sinapsis_openai-0.1.13-py3-none-any.whl
Size 20.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ab5d5cee199ead8288cbaa27bac74889b466561721f7d53cc944721860f2fdb
BLAKE2b-256 checksum
How to use checksums
481e81dec2cf16e4f7bfd028b3806fcb4b22bf674507bb36b787f31b2d8754c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.16

Release history Release notifications | RSS feed

This release

0.1.13 This release

2 release files

0.1.12

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page