Some external utilities to facilitate OpenAI's Utilites
Project description
OpenAI Utility Library Documentation
Overview
This library provides a set of utility functions to interact with the OpenAI API, specifically for querying GPT models and working with text embeddings.
IMPORTANT, READ BELOW:
IMPORTANT: WHEN YOU IMPORT THE PACKAGE, THE PACKAGE NAME IS openai_utils
Requirements
openai
Python packagenumpy
Functions
AskGPT
Description: Queries the GPT model with the provided context and returns the model's response.
Arguments:
model (str)
: The identifier for the GPT model you wish to use.context (list)
: A list of messages that you wish to send to the GPT model. The last message is typically from the user, and previous messages can provide context.
Returns:
str
: The model's response message.
Example:
response = AskGPT("gpt-3.5-turbo", [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Who won the world cup in 2018?"}])
print(response)
GetEmbedding
Description: Generates a text embedding for the given string using the specified model.
Arguments:
String (str)
: The text for which you wish to generate an embedding.
Returns:
list
: A list of floats representing the text's embedding.
Example:
embedding = GetEmbedding("Hello, world!")
print(embedding)
GetEmbeddingDistance
Description: Computes the difference between two embeddings.
Arguments:
Embedding1 (list)
: The first embedding represented as a list of floats.Embedding2 (list)
: The second embedding represented as a list of floats.
Returns:
float
: The absolute difference between the two embeddings.
Example:
embedding1 = GetEmbedding("cat")
embedding2 = GetEmbedding("dog")
distance = GetEmbeddingDistance(embedding1, embedding2)
print(distance)
Configuration
Before using the library, ensure that you have set the api_key
variable to your OpenAI API key.
api_key = "YOUR_API_KEY_HERE"
Notes
Ensure that your OpenAI account has adequate API call limits and that you are aware of potential costs associated with making too many requests. Always consult OpenAI's official documentation for detailed information on models and API usage.
End of Documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for openai_utilties-1.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fceb4fe45f755d5ac727b61d5afada2cf4e6541d3f416da167b70389333c42c5 |
|
MD5 | cdb340d7753ad3d368f74c713cf0b95f |
|
BLAKE2b-256 | 104683e845f86222bb9e3d7730f048178b630f8ac696378fe3baeedb2093ccb5 |