midjourney-apiserve

module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: BSD-2-Clause

README

List

midjourney-apiserver

midjourney-apiserver is an unofficial API service for Midjourney, designed to integrate the powerful capabilities of Midjourney into one's own business.

List

How to use

midjourney-apiserver only provides the grpc protocol with a default port of 8080.

Please refer to the api.proto for more information.

Here are some tools for debugging grpc that you can use: awesome-grpc.

If you are using Golang, you can use this code for testing:

package main

import (
	"context"
	"encoding/json"
	"io/ioutil"
	"log"
	"net/http"

	"github.com/hongliang5316/midjourney-apiserver/pkg/api"
	"github.com/hongliang5316/midjourney-apiserver/pkg/store"
	"github.com/hongliang5316/midjourney-apiserver/pkg/webhook"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
)

var apiServiceClient api.APIServiceClient

func init() {
	conn, err := grpc.Dial("127.0.0.1:8080", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		panic(err)
	}

	apiServiceClient = api.NewAPIServiceClient(conn)

}

func webhookHandler(w http.ResponseWriter, r *http.Request) {
	body, _ := ioutil.ReadAll(r.Body)
	req := &webhook.WebhookRequest{}
	json.Unmarshal(body, req)

	log.Printf("req: %+v", req)

	if req.Type == store.TypeImagine {
		resp, err := apiServiceClient.Upscale(context.Background(), &api.UpscaleRequest{
			Index:   1,
			TaskId:  req.TaskID,
			Webhook: "http://127.0.0.1:8000/",
		})
		if err != nil {
			panic(err)
		}

		log.Printf("resp: %+v", resp)
	}
}

func main() {
	go func() {
		resp, err := apiServiceClient.Imagine(context.Background(), &api.ImagineRequest{
			Prompt:  "a car",
			Webhook: "http://127.0.0.1:8000/",
		})
		if err != nil {
			panic(err)
		}

		log.Printf("%+v", resp)
	}()

	http.HandleFunc("/", webhookHandler)
	http.ListenAndServe(":8000", nil)
}

List

How to deploy

  • Use docker-compose (Strongly Recommend)
mkdir -p /your/app/conf

cd /your/app

# configure conf.yml, please see ./conf/conf.yml
vim conf/conf.yml

# create docker-compose.yml
cat docker-compose.yml
version: '3.1'

services:
  midjourney-apiserver:
    image: hongliang5316/midjourney-apiserver:0.0.2
    hostname: midjourney-apiserver
    restart: always
    volumes:
      - ./conf/conf.yml:/conf/conf.yml
    ports:
      - 8080:8080

  redis:
    image: redis:7
    hostname: redis
    restart: always
    volumes:
      - ./redis_data:/data
    command: redis-server --requirepass test

# run
docker-compse up -d

# check logs
docker-compose logs
  • Manual installation
go install github.com/hongliang5316/midjourney-apiserver/cmd/midjourney-apiserver@v0.0.2

mkdir -p /your/app/conf

cd /your/app

cp `go env GOROOT`/bin/midjourney-apiserver .
mkdir conf
# configure conf.yml, please see ./conf/conf.yml
vim conf/conf.yml
# run
./midjourney-apiserver

List

Status

You can see which api are currently supported by looking at api.proto, and if you have some ideas, feel free to submit issues.

imagine api

imagine.flow.svg

upscale api

upscale.flow.svg

describe api

List

Changelog

The simplest way of getting data is from the commits you write. Even though it doesn't require a machine-readable commit, it is still better to have them in a nice format.

The output then uses commit messages (title + description) to look something like:

v0.0.2 (20/06/2023)

  • Added support for new interfaces
    • Support for Describe grpc api

v0.0.1 (17/06/2023)

  • Complete the basic functions
    • Support for Imagine grpc api
    • Support for Upscale grpc api

List

Directories

Path Synopsis
cmd
internal
pkg
api

Jump to

Keyboard shortcuts

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