ociaitoopenai

package module
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

README

OCI AI to OpenAI Plugin

Traefik plugin that transforms OpenAI API requests to Oracle Cloud Infrastructure (OCI) GenAI format. This plugin enables OpenAI-compatible clients to work seamlessly with OCI's Generative AI service.

Installation

Static Configuration
experimental:
  plugins:
    ociaitoopenai:
      moduleName: github.com/zalbiraw/ociaitoopenai
      version: v0.0.1

Configuration

Parameter Type Default Required Description
compartmentId string - Yes OCI compartment ID where GenAI service is located.
region string - Yes OCI region where GenAI service is located (e.g., "us-chicago-1").

Usage

Dynamic Configuration
http:
  middlewares:
    openai-to-oci:
      plugin:
        ociaitoopenai:
          compartmentId: "ocid1.compartment.oc1..aaaaaaaa..."
          region: "us-chicago-1"
  routers:
    openai-api:
      rule: "Host(`openai.example.com`)"
      service: oci-genai
      middlewares:
        - openai-to-oci
Supported Endpoints
  • POST /chat/completionsPOST /20231130/actions/chat
  • GET /modelsGET /20231130/models
Request Flow
  1. Client sends OpenAI request to /chat/completions or /models
  2. Plugin transforms request from OpenAI format to OCI GenAI format
  3. Plugin updates URL path and scheme for OCI GenAI endpoints
  4. Request forwarded to next middleware (typically authentication)
  5. Plugin transforms OCI response back to OpenAI format
  6. Client receives response in OpenAI format
Models Endpoint
  • Passes through all query parameters
  • Defaults capability=CHAT if not specified
  • Always adds required compartmentId

Integration with OCI Auth

This plugin is designed to work with the ociauth plugin for authentication:

http:
  middlewares:
    openai-to-oci:
      plugin:
        ociaitoopenai:
          compartmentId: "ocid1.compartment.oc1..aaaaaaaa..."
          region: "us-chicago-1"
    oci-auth:
      plugin:
        ociauth:
          serviceName: "generativeai"
          region: "us-chicago-1"
  routers:
    openai-api:
      rule: "Host(`openai.example.com`)"
      service: oci-genai
      middlewares:
        - openai-to-oci  # Transform first
        - oci-auth       # Then authenticate

Important: The ociaitoopenai plugin should be applied before the ociauth plugin in the middleware chain.

Documentation

Overview

Package ociaitoopenai is a Traefik plugin that transforms OpenAI API requests to OCI GenAI format.

The plugin intercepts OpenAI ChatCompletion requests and transforms them to OCI GenAI format, enabling OpenAI-compatible clients to work with Oracle Cloud Infrastructure Generative AI services.

Key features: - Seamless OCI GenAI to OpenAI API translation - Request and response format transformation - Comprehensive error handling and logging

This plugin is the reverse counterpart to ocigenai, handling the transformation in the opposite direction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateConfig

func CreateConfig() *config.Config

CreateConfig creates the default plugin configuration. This function is required by Traefik's plugin system.

func New

func New(ctx context.Context, next http.Handler, cfg *config.Config, name string) (http.Handler, error)

New creates a new Proxy plugin instance. It validates the configuration and initializes the transformer.

Parameters:

  • ctx: Context for the plugin initialization
  • next: Next HTTP handler in the middleware chain
  • cfg: Plugin configuration
  • name: Name of the plugin instance

Returns the configured plugin handler or an error if configuration is invalid.

Types

type Proxy

type Proxy struct {
	// contains filtered or unexported fields
}

Proxy represents the main plugin instance that handles request transformation. It contains all the necessary components for transforming requests and responses.

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP implements the http.Handler interface and processes incoming requests.

The plugin only processes POST requests to paths ending with "/chat/completions". All other requests are passed through to the next handler unchanged.

For matching requests, the plugin: 1. Parses the OpenAI ChatCompletion request 2. Transforms it to OCI GenAI format 3. Updates the request URL to point to the OCI GenAI endpoint 4. Forwards the request to the next handler 5. Transforms the response back to OpenAI format

Directories

Path Synopsis
internal
config
Package config provides configuration management for the OCI to OpenAI transformation plugin.
Package config provides configuration management for the OCI to OpenAI transformation plugin.
transform
It provides functionality to transform OpenAI ChatCompletion requests into the format expected by Oracle Cloud's Generative AI service.
It provides functionality to transform OpenAI ChatCompletion requests into the format expected by Oracle Cloud's Generative AI service.
pkg
types
Package types defines the data structures used throughout the OCI to OpenAI transformation plugin.
Package types defines the data structures used throughout the OCI to OpenAI transformation plugin.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL