openai-python
Auto-generated from openai/openai-python by Mutable.ai Auto WikiRevise
openai-python | |
---|---|
GitHub Repository | |
Developer | openai |
Written in | Python |
Stars | 19k |
Watchers | 260 |
Created | 10/25/2020 |
Last updated | 04/03/2024 |
License | Apache License 2.0 |
Homepage | pypi.orgprojectopenai |
Repository | openai/openai-python |
Auto Wiki | |
Revision | |
Software Version | 0.0.8Basic |
Generated from | Commit f0bdef |
Generated at | 04/03/2024 |
The openai-python
repository contains the official Python client library for the OpenAI API, providing a comprehensive set of classes and methods for interacting with various OpenAI services. This library allows developers to easily integrate OpenAI's powerful language models, image generation, audio processing, and other AI capabilities into their applications.
The most important functionality of this repository is centered around the …/openai
directory, which contains the core classes and resources for the OpenAI Python client. This includes:
-
API Resource Interactions: The
…/resources
directory provides classes for interacting with various OpenAI API resources, such as Chat and Completions, Audio Processing, Image Generation and Manipulation, Fine-Tuning, and Content Moderation. These classes handle the construction of API requests, the parsing of responses, and the management of asynchronous and streaming operations. -
Utility Functions and Types: The
…/_utils
and…/types
directories contain a wide range of utility functions and data models used throughout the library, covering areas such as Type Handling and Transformation, Date and Time Parsing, String Manipulation, File Handling, and Synchronous and Asynchronous Iteration. -
Command-Line Interface: The
…/cli
directory provides a command-line interface (CLI) for interacting with the OpenAI API, allowing users to perform various operations such as generating text completions, managing files, and working with image generation. The CLI Architecture and CLI Commands sections cover the implementation of this functionality. -
Beta Features: The
…/beta
and…/beta
directories contain the implementation of the beta features in the OpenAI Python library, including Assistants and Threads, which provide advanced functionality for building interactive AI applications.
The OpenAI Python client library is built on top of the httpx
library, which provides a modern, asynchronous HTTP client for Python. The library makes extensive use of type annotations and Pydantic models to ensure type-safe interactions with the OpenAI API, and it provides both synchronous and asynchronous interfaces for maximum flexibility.
The key design choices of the library include:
- Modular Architecture: The codebase is organized into well-defined modules and directories, each focusing on a specific set of functionality, making the library easy to navigate and extend.
- Separation of Concerns: The library separates the concerns of API resource interactions, data models, utility functions, and command-line interface, promoting maintainability and testability.
- Asynchronous Support: The library provides both synchronous and asynchronous interfaces for interacting with the OpenAI API, allowing developers to choose the approach that best fits their application's needs.
- Streaming and Raw Responses: The library supports both streaming and raw response handling for certain API resources, giving developers the flexibility to choose the most appropriate response format for their use case.
API Resource InteractionsRevise
References: src/openai/resources
The …/
directory contains the core functionality of the OpenAI Python client library, providing a comprehensive set of classes and methods for interacting with various OpenAI API resources.
Chat and CompletionsRevise
References: src/openai/resources/chat
The Chat
and AsyncChat
classes in …/chat.py
provide the main synchronous and asynchronous interfaces for interacting with the OpenAI Chat API. These classes expose a completions
property that returns Completions
and AsyncCompletions
objects, respectively, which handle the actual creation of chat completions.
Audio ProcessingRevise
References: src/openai/resources/audio
The openai-python/src/openai/resources/audio
directory contains the implementation of various classes and functions related to audio processing and manipulation in the OpenAI Python library. The main functionality includes:
Image Generation and ManipulationRevise
References: openai-python
The …/images
directory contains the core functionality for image-related operations in the OpenAI Python library. The Images
and AsyncImages
classes provide methods for creating image variations, editing images, and generating images from prompts using OpenAI's DALL-E models.
Fine-TuningRevise
References: src/openai/resources/fine_tuning
The FineTuning
and AsyncFineTuning
classes in the …/fine_tuning.py
file provide a synchronous and asynchronous interface, respectively, for interacting with the OpenAI fine-tuning API. These classes expose properties that give access to the following functionality:
Beta FeaturesRevise
References: src/openai/resources/beta
The Beta
and AsyncBeta
classes in the …/beta.py
file serve as the entry points for interacting with the OpenAI API's beta features, including Assistants and Threads.
Content ModerationRevise
References: openai-python
The …/moderations
directory contains the Moderations
and AsyncModerations
classes, which provide a way to classify text as potentially harmful using OpenAI's content moderation models.
Utility Functions and TypesRevise
References: src/openai/_utils
, src/openai/types
The …/_utils
directory contains a collection of utility functions and classes that provide various functionality to the OpenAI Python library. The main areas of functionality include:
Type Handling and TransformationRevise
References: src/openai/_utils
The …/_utils
directory provides a collection of utility functions and classes that support various data type handling and transformation tasks throughout the OpenAI Python library.
Date and Time ParsingRevise
References: src/openai/_utils
The …/__init__.py
file includes the parse_date()
and parse_datetime()
functions, which are used to parse date and datetime strings, respectively. These functions are likely used to handle date and time data in the OpenAI API responses or input parameters.
String ManipulationRevise
References: src/openai/_utils
The …/__init__.py
file provides utility functions for manipulating strings in the OpenAI Python library. The key functionality in this area includes:
File HandlingRevise
References: src/openai/_utils
The …/__init__.py
file provides several utility functions for working with files in the OpenAI Python library. The key functionality in this area includes:
Type Annotations and ExtractionRevise
References: openai-python
The …/_typing.py
file provides a set of utility functions for working with Python's type system and type annotations. These functions are used throughout the OpenAI Python library to handle various type-related tasks, such as validating input types, extracting type information, and resolving generic type variables.
Synchronous and Asynchronous IterationRevise
References: openai-python
The …/_streams.py
file provides the consume_sync_iterator()
and consume_async_iterator()
functions, which are used to consume synchronous and asynchronous iterators, respectively, in the OpenAI Python library.
Command-Line InterfaceRevise
References: src/openai/cli
The command-line interface (CLI) for the OpenAI Python library provides a unified interface for interacting with the various OpenAI APIs, including chat, audio, completions, files, images, and models.
CLI ArchitectureRevise
References: src/openai/cli
, src/openai/cli/_cli.py
, src/openai/cli/_errors.py
, src/openai/cli/_models.py
The …/cli
directory contains the implementation of the command-line interface (CLI) for the OpenAI Python library. The main entry point is the _cli.py
file, which defines the Arguments
class to handle the command-line arguments and the _main()
function to set up the HTTP client, configure the OpenAI API client, and call the appropriate command function.
CLI CommandsRevise
References: src/openai/cli/_api
, src/openai/cli/_api/_main.py
, src/openai/cli/_api/chat
, src/openai/cli/_api/audio.py
, src/openai/cli/_api/completions.py
, src/openai/cli/_api/files.py
, src/openai/cli/_api/image.py
, src/openai/cli/_api/models.py
The CLI Commands subsection covers the implementation of the various CLI commands for interacting with the OpenAI API, including chat, audio, completions, files, images, and models.
CLI ToolsRevise
References: src/openai/cli/_tools
, src/openai/cli/_tools/_main.py
, src/openai/cli/_tools/fine_tunes.py
, src/openai/cli/_tools/migrate.py
The …/_tools
directory provides the command-line interface (CLI) tools for the OpenAI Python library. This subsection covers the implementation of these CLI tools, including the fine-tuning data preparation tool and the Grit CLI migration tool.
Beta FeaturesRevise
References: src/openai/resources/beta
, src/openai/types/beta
The OpenAI Python library provides a comprehensive set of classes and methods for interacting with the OpenAI API's beta features, including the Beta API, Threads, and Assistants. These features are implemented in the …/
directory and the …/
directory.
AssistantsRevise
The Assistants
and AsyncAssistants
classes, defined in …/assistants.py
, provide the core functionality for managing OpenAI Assistants. These classes allow users to create, retrieve, update, list, and delete OpenAI Assistants.
Fine-TuningRevise
The OpenAI Python library provides a comprehensive set of classes and methods for interacting with the OpenAI fine-tuning API. The fine-tuning functionality is implemented in the …/
directory and the associated data models are defined in the …/
directory.
Fine-Tuning Job ManagementRevise
References: src/openai/resources/fine_tuning/jobs.py
, src/openai/types/fine_tuning/job_create_params.py
, src/openai/types/fine_tuning/job_list_params.py
The Jobs
and AsyncJobs
classes in …/jobs.py
provide the core functionality for managing fine-tuning jobs in the OpenAI Python library.
Fine-Tuning Job EventsRevise
References: src/openai/resources/fine_tuning/fine_tuning.py
, src/openai/types/fine_tuning/fine_tuning_job_event.py
, src/openai/types/fine_tuning/job_list_events_params.py
The FineTuning
and AsyncFineTuning
classes in …/fine_tuning.py
provide a synchronous and asynchronous interface, respectively, for interacting with the OpenAI fine-tuning API. These classes expose properties that give access to fine-tuning job-related functionality, including the ability to list events for a specific fine-tuning job.
Fine-Tuning Job Data ModelsRevise
References: src/openai/types/fine_tuning/fine_tuning_job.py
The FineTuningJob
class in …/fine_tuning_job.py
represents the details of a fine-tuning job in the OpenAI Python library. This class encapsulates the key information about a fine-tuning job, including its status, the base model being fine-tuned, the training and validation files, and the resulting fine-tuned model.
Audio ProcessingRevise
References: src/openai/resources/audio
, src/openai/types/audio
The OpenAI Python library provides a comprehensive set of classes and methods for interacting with various audio-related API resources, including transcription, translation, and speech generation.
Transcription and TranslationRevise
References: src/openai/types/audio/transcription.py
, src/openai/types/audio/translation.py
, src/openai/types/audio/transcription_create_params.py
, src/openai/types/audio/translation_create_params.py
The Transcription
and Translation
classes in the …/audio
directory define the data models used to represent the results of audio transcription and translation operations performed by the OpenAI API.
Speech GenerationRevise
References: src/openai/types/audio/speech_create_params.py
The SpeechCreateParams
class, defined in …/speech_create_params.py
, represents the parameters required to create speech using the OpenAI Text-to-Speech (TTS) API. This class is a TypedDict
that defines the following fields: