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.
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.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 829521129622b85929af63a9afe9ca517032acfe3c8ab1019ae5e7bf8a9e098f |
|
MD5 | c3381133af107ac57bfa67df0fbc3bb5 |
|
BLAKE2b-256 | d552a71c0fe230f73d37d7633ee32c84e8d0a48dd0e349f96652ce83163fb13c |