api

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package api provides OpenAI-compatible image generation API types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleGenerateRequest

func HandleGenerateRequest(c *gin.Context, scheduler RunnerScheduler, modelName, prompt string, keepAlive *api.Duration, streamFn func(c *gin.Context, ch chan any))

HandleGenerateRequest handles Ollama /api/generate requests for image gen models. This allows routes.go to delegate image generation with minimal code.

func ImageGenerationHandler

func ImageGenerationHandler(c *gin.Context, scheduler RunnerScheduler)

ImageGenerationHandler handles OpenAI-compatible image generation requests.

func RegisterRoutes

func RegisterRoutes(r gin.IRouter, scheduler RunnerScheduler)

RegisterRoutes registers the image generation API routes.

Types

type GenerateResponse

type GenerateResponse struct {
	Model     string    `json:"model"`
	CreatedAt time.Time `json:"created_at"`
	Response  string    `json:"response"`
	Done      bool      `json:"done"`
}

GenerateResponse matches api.GenerateResponse structure for streaming.

type ImageData

type ImageData struct {
	URL           string `json:"url,omitempty"`
	B64JSON       string `json:"b64_json,omitempty"`
	RevisedPrompt string `json:"revised_prompt,omitempty"`
}

ImageData contains the generated image data.

type ImageGenerationRequest

type ImageGenerationRequest struct {
	Model          string `json:"model"`
	Prompt         string `json:"prompt"`
	N              int    `json:"n,omitempty"`
	Size           string `json:"size,omitempty"`
	ResponseFormat string `json:"response_format,omitempty"`
	Stream         bool   `json:"stream,omitempty"`
}

ImageGenerationRequest is an OpenAI-compatible image generation request.

type ImageGenerationResponse

type ImageGenerationResponse struct {
	Created int64       `json:"created"`
	Data    []ImageData `json:"data"`
}

ImageGenerationResponse is an OpenAI-compatible image generation response.

type ImageProgressEvent

type ImageProgressEvent struct {
	Step  int `json:"step"`
	Total int `json:"total"`
}

ImageProgressEvent is sent during streaming to indicate generation progress.

type RunnerScheduler

type RunnerScheduler interface {
	ScheduleImageGenRunner(ctx *gin.Context, modelName string, opts api.Options, keepAlive *api.Duration) (llm.LlamaServer, error)
}

RunnerScheduler is the interface for scheduling a model runner. This is implemented by server.Server to avoid circular imports.

Jump to

Keyboard shortcuts

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