1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

OpenAI API互換のEmbeddings APIをDockerで簡単に構築する方法

Posted at

はじめに

OpenAIのAPIと互換性のあるEmbeddings APIを簡単に構築する方法を紹介します。今回は、engchina/embeddings-api:multilingual-e5-large-instructというDockerイメージを使用して、/v1/embeddingsエンドポイントを提供するAPIを立ち上げます。

必要な環境

  • Dockerがインストールされていること
  • GPUが利用可能な環境

Dockerコンテナの起動

以下のコマンドを実行して、Dockerコンテナを起動します。

docker run -d --name embeddings-api --gpus all -p 7965:7965 engchina/embeddings-api:multilingual-e5-large-instruct

このコマンドでは、以下のことを行っています。

  • -d: コンテナをバックグラウンドで実行
  • --name embeddings-api: コンテナにembeddings-apiという名前を付ける
  • --gpus all: すべてのGPUをコンテナに割り当てる(GPUがない場合はこのオプションを省略可能)
  • -p 7965:7965: ホストの7965番ポートをコンテナの7965番ポートにマッピング
  • engchina/embeddings-api:multilingual-e5-large-instruct: 使用するDockerイメージ

APIの確認

コンテナが起動したら、以下のURLにアクセスしてAPIのドキュメントを確認できます。

http://localhost:7965/docs

このページでは、APIのエンドポイントやパラメータについて詳しく説明されています。

curlコマンドでの確認

以下のcurlコマンドを使用して、/v1/embeddingsエンドポイントにリクエストを送信し、APIが正しく動作しているかを確認します。

curl -X 'POST' \
  'http://localhost:7965/v1/embeddings?model_name=text-embedding-3-large' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "text-embedding-3-large",
  "engine": "string",
  "input": "hi",
  "user": "string",
  "encoding_format": "string"
}'

このリクエストでは、以下のパラメータを指定しています。

  • model: 使用するモデル名(text-embedding-3-large
  • engine: エンジン名(任意の文字列)
  • input: 埋め込みを取得したいテキスト(ここでは"hi"
  • user: ユーザー識別子(任意の文字列)
  • encoding_format: エンコーディングフォーマット(任意の文字列)

まとめ

この記事では、Dockerを使用してOpenAI API互換のEmbeddings APIを簡単に構築する方法を紹介しました。engchina/embeddings-api:multilingual-e5-large-instructイメージを使うことで、手軽に高性能な埋め込みAPIを利用できます。ぜひお試しください!

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?