Skip to main content

OpenAI Utility Library

This library provides a set of utility functions to interact with OpenAI's API, focusing on generating chat responses, creating text embeddings, formatting response data, and generating images from prompts. It leverages the OpenAI Python client to facilitate these tasks.

Table of Contents

Installation

To use this library, you need to have Python installed on your system. You also need to install the OpenAI Python client. You can do this by running the following command in your terminal:

pip install openai

Usage

To use the functions provided by this library, you need to import the library and then call the desired function. Here's a basic example:

import openai_utility_library as oai

# Generate a chat response
context = "Hello, how can I help you today?"
response = oai.generate_chat_response(context)
print(response)

# Create a text embedding
input_string = "This is a sample text."
embedding = oai.create_text_embedding(input_string)
print(embedding)

# Format response data
formatted_data = oai.format_response_data(response)
print(formatted_data)

# Generate an image from a prompt
prompt = "A beautiful sunset over the ocean."
image = oai.generate_image_from_prompt(prompt)
print(image)

Functions

generate_chat_response

This function generates a chat response based on the provided context. It supports both string and list inputs for the context.

  • Parameters:
    • context: The context for the chat response. Can be a string or a list of message objects.
    • model: The model to use for generating the response. Default is "gpt-3.5-turbo-1106".
    • temperature: The temperature for the model. Default is 1.
  • Returns: The generated chat response as a string.

create_text_embedding

This function creates a text embedding for the given input string.

  • Parameters:
    • input_string: The string for which to create the text embedding.
  • Returns: A list representing the text embedding.

format_response_data

This function formats the response data from OpenAI's API into a more readable format.

  • Parameters:
    • response: The response object from OpenAI's API.
  • Returns: A dictionary containing the formatted response data.

generate_image_from_prompt

This function generates an image based on the provided prompt.

  • Parameters:
    • prompt: The prompt for generating the image.
    • quality: The quality of the generated image. Default is 'standard'.
  • Returns: The generated image.

Examples

For detailed examples on how to use each function, refer to the Usage section.

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue if you find any bugs or have suggestions for improvements.

License

This library is licensed under the MIT License. See the LICENSE file for more details.

Metadata

Release files for openai-utilties 3.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openai-utilties 3.6
File Size Uploaded
openai-utilties-3.6.tar.gz 3.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openai-utilties 3.6
File Interpreter ABI Platform
openai_utilties-3.6-py3-none-any.whl Python 3 none any Details

Total release size: 6.5 kB

Release files / openai-utilties-3.6.tar.gz

Download URL openai-utilties-3.6.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
299f08bdd08f2e733ab7ff76f56ab49aecc65161d6a5861a9261f861ad969448
BLAKE2b-256 checksum
How to use checksums
4094eab4be337d9f5b4d5400192b35a4fabbecc3b937a782b25e57ba1df34d03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.7

Release files / openai_utilties-3.6-py3-none-any.whl

Download URL openai_utilties-3.6-py3-none-any.whl
Size 3.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bfd9f80f90a99e6b83db993718fc895317df8dca7b91b5278b345aaa848542ff
BLAKE2b-256 checksum
How to use checksums
fb6fbdbb5e900891033851b90f7ebe843a2cee8e3ef2f46d6d16e9cc1b25f45d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.7

Release history Release notifications | RSS feed

This release

3.6 This release

2 release files

3.5

2 release files

3.4

2 release files

3.3

2 release files

3.2

2 release files

3.1

2 release files

3.0

2 release files

2.9

2 release files

2.8

2 release files

2.7

2 release files

2.6

2 release files

2.5

2 release files

2.4

2 release files

2.3

2 release files

2.1

2 release files

2.0

2 release files

1.9

2 release files

1.8

2 release files

1.7

2 release files

1.6

2 release files

1.5

2 release files

1.4

2 release files

1.3

2 release files

1.2

2 release files

1.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page