Skip to main content

A simple function to retrieve sentence embeddings from an OpenAI Embeddings-compatible API.

Project description

retrieve-sentence-embeddings

A simple function to retrieve sentence embeddings from an OpenAI Embeddings-compatible API. That includes:

with compatible models.

Features

  • Compatibility: Unlike openai, works on Python 2+ with zero non-Python dependencies.

Installation

pip install retrieve-sentence-embeddings

Usage

# coding=utf-8
from retrieve_sentence_embeddings import retrieve_sentence_embeddings

api_key = u'OPENAI_API_KEY'
base_url = u'https://api.openai.com/v1'
model = u'text-embedding-ada-002'
sentences = [
    u'Hello, world!',
    u'This is a test sentence.',
    u'Embeddings are useful!'
]

sentence_embeddings = retrieve_sentence_embeddings(api_key, base_url, model, sentences)

sentence_embeddings is a List[List[float]], e.g.,

[
    [0.123, -0.982, ...],
    [0.222, 0.088, ...],
    ...
]

Error Handling

If a network error or malformed response is encountered, the exception is propagated.

Contributing

Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

retrieve_sentence_embeddings-0.1.0a0.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

retrieve_sentence_embeddings-0.1.0a0-py2.py3-none-any.whl (4.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file retrieve_sentence_embeddings-0.1.0a0.tar.gz.

File metadata

File hashes

Hashes for retrieve_sentence_embeddings-0.1.0a0.tar.gz
Algorithm Hash digest
SHA256 c0e5f54ff68a24d8c233c0c2ab30b7161d3849ca8a908222577a178efabe0fed
MD5 3815847e674ba2139c1e2c322352ef52
BLAKE2b-256 d595255a27703df5fa9f86b3615c448783cb5467794205e71a31b394ba56cfcc

See more details on using hashes here.

File details

Details for the file retrieve_sentence_embeddings-0.1.0a0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for retrieve_sentence_embeddings-0.1.0a0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b02d95d81dc43830025428e57f5a4fd8496d3e348a8b56ad2707edb417800746
MD5 c408aded50014d26fccd658865b0ddcd
BLAKE2b-256 1b4f18a454c9920d985116bac6c7f59ea1ab0675a062a0abf53dd440065688d3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page