本文由 大侠(AhcaoZhu)原创,转载请声明。
链接: https://blog.csdn.net/Ahcao2008
摘要
全文介绍系统内置 openai ——ChatGPT的API python库:模块、函数、类及类的方法和属性。
它通过代码抓取并经AI智能翻译和人工校对。
是一部不可多得的权威字典类工具书。它是系列集的一部分。后续陆续发布、敬请关注。【原创:AhcaoZhu大侠】
- 由于模块较大,且很多相关库也是既多且复杂,所以分为多集。本文很简单明了地给出图,便于读者有个概貌了解。
- 接下来,笔者还要介绍 OpenAI API 的安装,一个简单的例子,以及本文的N多续集:即对主包的展开、一直到主要的类的介绍、以及以前没有介绍过的相关的模块,例如:aiohttp 模块。
模块图
首先给出模块的一级结构,即简明结构。
openai
◆os
openai.error
openai.util
openai.version
openai.openai_response
openai.api_requestor
openai.openai_object
openai.datalib
openai.api_resources
openai
◆os
openai.error
openai.util
◆logging
◆re
◆sys
openai.version
openai.openai_response
openai.api_requestor
◆asyncio
◆json
◆platform
◆threading
◆warnings
◆aiohttp
◆requests
openai.openai_object
openai.datalib
◆numpy
◆pandas
openai.api_resources
openai.api_resources.abstract
openai.api_resources.abstract.api_resource
openai.api_resources.abstract.createable_api_resource
openai.api_resources.abstract.deletable_api_resource
openai.api_resources.abstract.listable_api_resource
openai.api_resources.abstract.updateable_api_resource
openai.api_resources.abstract.engine_api_resource
openai.api_resources.audio
openai.api_resources.chat_completion
◆time
openai.api_resources.completion
openai.api_resources.customer
openai.api_resources.deployment
openai.api_resources.edit
openai.api_resources.embedding
◆base64
openai.api_resources.engine
openai.api_resources.error_object
openai.api_resources.file
openai.api_resources.fine_tune
openai.api_resources.image
openai.api_resources.model
openai.api_resources.moderation
类关系图
同样地,我这里给出类关系简图,即类所属模块为 OpenAI API包及从属模块才展示,其它相关模块(requirements清单)并不在这里展示,而是另分单独文章逐一介绍。
分析:从上图及以下数据可以看出:OpenAI-API包的类对象结构并不是太复杂,主要分为异常处理、词典类、以及枚举。但是同样不可忽视的是:从模块图中可以看出,
openai.api_resources
将是重点。
◆object
◆BaseException
◆Exception
openai.datalib.MissingDependencyError
openai.error.OpenAIError
openai.error.APIConnectionError
openai.error.APIError
openai.error.AuthenticationError
openai.error.InvalidAPIType
openai.error.InvalidRequestError
openai.error.PermissionError
openai.error.RateLimitError
openai.error.ServiceUnavailableError
openai.error.SignatureVerificationError
openai.error.Timeout
openai.error.TryAgain
◆dict
openai.openai_object.OpenAIObject
openai.api_resources.abstract.api_resource.APIResource
openai.api_resources.abstract.createable_api_resource.CreateableAPIResource
openai.api_resources.abstract.listable_api_resource.ListableAPIResource
openai.api_resources.abstract.createable_api_resource.CreateableAPIResource
openai.api_resources.engine.Engine
openai.api_resources.file.File
openai.api_resources.fine_tune.FineTune
openai.api_resources.model.Model
openai.api_resources.deployment.Deployment
openai.api_resources.abstract.deletable_api_resource.DeletableAPIResource
openai.api_resources.abstract.createable_api_resource.CreateableAPIResource
openai.api_resources.abstract.listable_api_resource.ListableAPIResource
openai.api_resources.abstract.engine_api_resource.EngineAPIResource
openai.api_resources.chat_completion.ChatCompletion
openai.api_resources.completion.Completion
openai.api_resources.edit.Edit
openai.api_resources.embedding.Embedding
openai.api_resources.abstract.listable_api_resource.ListableAPIResource
openai.api_resources.abstract.updateable_api_resource.UpdateableAPIResource
openai.api_resources.abstract.listable_api_resource.ListableAPIResource
openai.api_resources.audio.Audio
openai.api_resources.image.Image
openai.api_resources.customer.Customer
openai.api_resources.error_object.ErrorObject
openai.api_resources.moderation.Moderation
◆Enum
ApiType
复杂结构如下(图形略,过于复杂)
◆object
◆BaseException
◆Exception
◆EOFError
◆asyncio.streams.IncompleteReadError
◆LookupError
◆IndexError
◆ValueError
◆OSError
◆aiohttp.client_exceptions.ClientError
◆aiohttp.client_exceptions.ClientConnectionError
◆aiohttp.client_exceptions.ClientOSError
◆aiohttp.client_exceptions.ClientConnectorError
◆aiohttp.client_exceptions.ClientProxyConnectionError
◆aiohttp.client_exceptions.ClientSSLError
◆aiohttp.client_exceptions.ClientConnectorCertificateError
◆aiohttp.client_exceptions.ClientConnectorSSLError
◆aiohttp.client_exceptions.ServerConnectionError
◆aiohttp.client_exceptions.ServerDisconnectedError
◆aiohttp.client_exceptions.ServerFingerprintMismatch
◆aiohttp.client_exceptions.ServerTimeoutError
◆aiohttp.client_exceptions.ClientPayloadError
◆aiohttp.client_exceptions.ClientResponseError
◆aiohttp.client_exceptions.ClientHttpProxyError
◆aiohttp.client_exceptions.ContentTypeError
◆aiohttp.client_exceptions.TooManyRedirects
◆aiohttp.client_exceptions.WSServerHandshakeError
◆aiohttp.client_exceptions.InvalidURL
◆requests.exceptions.RequestException
◆requests.exceptions.ConnectionError
◆requests.exceptions.ConnectTimeout
◆requests.exceptions.HTTPError
◆requests.exceptions.InvalidJSONError
◆requests.exceptions.JSONDecodeError
◆requests.exceptions.Timeout
◆requests.exceptions.ConnectionError
◆requests.exceptions.ReadTimeout
◆requests.exceptions.TooManyRedirects
◆requests.exceptions.URLRequired
◆ssl.SSLError
◆aiohttp.client_exceptions.ClientError
◆ssl.SSLCertVerificationError
◆aiohttp.client_exceptions.ClientError
◆aiohttp.client_exceptions.ClientError
◆json.decoder.JSONDecodeError
◆OSError
◆numpy.AxisError
◆OSError
◆RuntimeError
◆asyncio.events.SendfileNotAvailableError
◆numpy.TooHardError
◆threading.BrokenBarrierError
◆ValueError
◆Warning
◆DeprecationWarning
◆numpy.ModuleDeprecationWarning
◆requests.exceptions.RequestsWarning
◆requests.exceptions.FileModeWarning
◆requests.exceptions.RequestsDependencyWarning
◆RuntimeWarning
◆aiohttp.multipart.BadContentDispositionHeader
◆aiohttp.multipart.BadContentDispositionParam
◆numpy.ComplexWarning
◆UserWarning
◆numpy.RankWarning
◆numpy.VisibleDeprecationWarning
◆requests.exceptions.RequestsWarning
◆urllib3.exceptions.HTTPWarning
◆urllib3.exceptions.DependencyWarning
◆aiohttp.client_exceptions.ClientError
◆aiohttp.http_websocket.WebSocketError
◆aiohttp.streams.EofStream
◆asyncio.queues.QueueEmpty
◆asyncio.queues.QueueFull
◆asyncio.streams.LimitOverrunError
◆concurrent.futures._base.Error
◆asyncio.base_futures.InvalidStateError
◆concurrent.futures._base.CancelledError
◆concurrent.futures._base.TimeoutError
◆aiohttp.client_exceptions.ClientError
openai.datalib.MissingDependencyError
openai.error.OpenAIError
openai.error.APIConnectionError
openai.error.APIError
openai.error.AuthenticationError
openai.error.InvalidAPIType
openai.error.InvalidRequestError
openai.error.PermissionError
openai.error.RateLimitError
openai.error.ServiceUnavailableError
openai.error.SignatureVerificationError
openai.error.Timeout
openai.error.TryAgain
◆re.error
◆warnings._OptionError
◆ContextVar
◆_asyncio.Future
◆_asyncio.Task
◆_frozen_importlib.BuiltinImporter
◆_thread.RLock
◆_thread._local
◆_weakrefset.WeakSet
◆abc.ABC
◆aiohttp.abc.AbstractResolver
◆aiohttp.resolver.AsyncResolver
◆aiohttp.resolver.ThreadedResolver
◆aiohttp.payload.Payload
◆aiohttp.multipart.MultipartWriter
◆aiohttp.payload.AsyncIterablePayload
◆aiohttp.payload.BytesPayload
◆aiohttp.payload.JsonPayload
◆aiohttp.payload.StringPayload
◆aiohttp.payload.StringIOPayload
◆aiohttp.payload.IOBasePayload
◆aiohttp.payload.BufferedReaderPayload
◆aiohttp.payload.BytesIOPayload
◆aiohttp.payload.TextIOPayload
◆os.PathLike
◆pandas.core.strings.base.BaseStringArrayMethods
◆pandas.core.strings.object_array.ObjectStringArrayMixin
◆pandas.core.accessor.DirNamesMixin
◆pandas.core.base.PandasObject
◆pandas.core.arraylike.OpsMixin
◆pandas.core.base.IndexOpsMixin
◆pandas.core.indexes.base.Index
◆pandas.core.indexes.extension.ExtensionIndex
◆pandas.core.indexes.extension.NDArrayBackedExtensionIndex
◆pandas.core.indexes.category.CategoricalIndex
◆pandas.core.indexes.datetimelike.DatetimeIndexOpsMixin
◆pandas.core.indexes.datetimelike.DatetimeTimedeltaMixin
◆pandas.core.indexes.datetimes.DatetimeIndex
◆pandas.core.indexes.timedeltas.TimedeltaIndex
◆pandas.core.indexes.period.PeriodIndex
◆pandas.core.indexes.interval.IntervalIndex
◆pandas.core.indexes.multi.MultiIndex
◆pandas.core.indexes.numeric.NumericIndex
◆pandas.core.indexes.numeric.Float64Index
◆pandas.core.indexes.numeric.IntegerIndex
◆pandas.core.indexes.numeric.Int64Index
◆pandas.core.indexes.numeric.UInt64Index
◆pandas.core.indexes.range.RangeIndex
◆pandas.core.series.Series
◆pandas.core.indexing.IndexingMixin
◆pandas.core.accessor.DirNamesMixin
◆pandas.core.arrays.base.ExtensionArray
◆pandas._libs.arrays.NDArrayBacked
◆pandas.core.arrays._mixins.NDArrayBackedExtensionArray
◆pandas.core.arrays.categorical.Categorical
◆pandas.core.generic.NDFrame
◆pandas.core.arraylike.OpsMixin
◆pandas.core.frame.DataFrame
◆aiohttp._frozenlist.FrozenList
◆aiohttp.signals.Signal
◆aiohttp.client.ClientSession
◆aiohttp.client.ClientTimeout
◆aiohttp.client_reqrep.ClientRequest
◆aiohttp.client_reqrep.Fingerprint
◆aiohttp.client_reqrep.RequestInfo
◆aiohttp.client_ws.ClientWebSocketResponse
◆aiohttp.connector.BaseConnector
◆aiohttp.connector.NamedPipeConnector
◆aiohttp.connector.TCPConnector
◆aiohttp.connector.UnixConnector
◆aiohttp.formdata.FormData
◆aiohttp.helpers.HeadersMixin
◆aiohttp.client_reqrep.ClientResponse
◆aiohttp.multipart.BodyPartReader
◆aiohttp.multipart.MultipartReader
◆aiohttp.payload.payload_type
◆aiohttp.payload_streamer.streamer
◆aiohttp.streams.AsyncStreamReaderMixin
◆aiohttp.streams.StreamReader
◆aiohttp.tracing.TraceConfig
◆aiohttp.tracing.TraceConnectionCreateEndParams
◆aiohttp.tracing.TraceConnectionCreateStartParams
◆aiohttp.tracing.TraceConnectionQueuedEndParams
◆aiohttp.tracing.TraceConnectionQueuedStartParams
◆aiohttp.tracing.TraceConnectionReuseconnParams
◆aiohttp.tracing.TraceDnsCacheHitParams
◆aiohttp.tracing.TraceDnsCacheMissParams
◆aiohttp.tracing.TraceDnsResolveHostEndParams
◆aiohttp.tracing.TraceDnsResolveHostStartParams
◆aiohttp.tracing.TraceRequestChunkSentParams
◆aiohttp.tracing.TraceRequestEndParams
◆aiohttp.tracing.TraceRequestExceptionParams
◆aiohttp.tracing.TraceRequestRedirectParams
◆aiohttp.tracing.TraceRequestStartParams
◆aiohttp.tracing.TraceResponseChunkReceivedParams
◆asyncio.events.AbstractEventLoop
◆asyncio.base_events.BaseEventLoop
◆asyncio.proactor_events.BaseProactorEventLoop
◆asyncio.windows_events.ProactorEventLoop
◆asyncio.selector_events.BaseSelectorEventLoop
◆asyncio.windows_events._WindowsSelectorEventLoop
◆asyncio.events.AbstractEventLoopPolicy
◆asyncio.events.BaseDefaultEventLoopPolicy
◆asyncio.windows_events.WindowsProactorEventLoopPolicy
◆asyncio.windows_events.WindowsSelectorEventLoopPolicy
◆asyncio.events.AbstractServer
◆asyncio.events.Handle
◆asyncio.events.TimerHandle
◆asyncio.locks.Event
◆asyncio.locks._ContextManagerMixin
◆asyncio.locks.Condition
◆asyncio.locks.Lock
◆asyncio.locks.Semaphore
◆asyncio.locks.BoundedSemaphore
◆asyncio.protocols.BaseProtocol
◆asyncio.protocols.BufferedProtocol
◆asyncio.protocols.DatagramProtocol
◆asyncio.protocols.Protocol
◆asyncio.streams.FlowControlMixin
◆asyncio.streams.StreamReaderProtocol
◆asyncio.protocols.SubprocessProtocol
◆asyncio.queues.Queue
◆asyncio.queues.LifoQueue
◆asyncio.queues.PriorityQueue
◆asyncio.streams.StreamReader
◆asyncio.streams.StreamWriter
◆asyncio.transports.BaseTransport
◆asyncio.transports.DatagramTransport
◆asyncio.transports.ReadTransport
◆asyncio.transports.Transport
◆asyncio.transports.SubprocessTransport
◆asyncio.transports.WriteTransport
◆asyncio.transports.ReadTransport
◆asyncio.windows_events.IocpProactor
◆collections.abc.Container
◆collections.abc.Iterable
◆collections.abc.Sized
◆aiohttp.abc.AbstractCookieJar
◆aiohttp.cookiejar.CookieJar
◆aiohttp.cookiejar.DummyCookieJar
◆collections.abc.Collection
◆collections.abc.Mapping
◆aiohttp.helpers.ChainMapProxy
◆collections.abc.MutableMapping
◆os._Environ
◆collections.deque
◆complex
◆numpy.generic
◆numpy.bool_
◆numpy.datetime64
◆numpy.flexible
◆numpy.character
◆bytes
◆numpy.bytes_
◆str
◆numpy.str_
◆numpy.void
◆numpy.record
◆numpy.number
◆numpy.inexact
◆numpy.complexfloating
◆numpy.clongdouble
◆numpy.complex128
◆numpy.complex64
◆numpy.floating
◆numpy.float16
◆numpy.float32
◆numpy.float64
◆numpy.longdouble
◆numpy.integer
◆numpy.signedinteger
◆numpy.int16
◆numpy.int32
◆numpy.int64
◆numpy.int8
◆numpy.intc
◆numpy.timedelta64
◆numpy.unsignedinteger
◆numpy.uint16
◆numpy.uint32
◆numpy.uint64
◆numpy.uint8
◆numpy.uintc
◆numpy.object_
◆contextlib.ContextDecorator
◆numpy.errstate
◆pandas._config.config.option_context
◆datetime.date
◆datetime.datetime
◆pandas._libs.tslibs.base.ABCTimestamp
◆pandas._libs.tslibs.timestamps._Timestamp
◆pandas._libs.tslibs.timestamps.Timestamp
◆datetime.timedelta
◆pandas._libs.tslibs.timedeltas._Timedelta
◆pandas._libs.tslibs.timedeltas.Timedelta
◆dict
openai.openai_object.OpenAIObject
openai.api_resources.abstract.api_resource.APIResource
openai.api_resources.abstract.createable_api_resource.CreateableAPIResource
openai.api_resources.abstract.listable_api_resource.ListableAPIResource
openai.api_resources.abstract.createable_api_resource.CreateableAPIResource
openai.api_resources.engine.Engine
openai.api_resources.file.File
openai.api_resources.fine_tune.FineTune
openai.api_resources.model.Model
openai.api_resources.deployment.Deployment
openai.api_resources.abstract.deletable_api_resource.DeletableAPIResource
openai.api_resources.abstract.createable_api_resource.CreateableAPIResource
openai.api_resources.abstract.listable_api_resource.ListableAPIResource
openai.api_resources.abstract.engine_api_resource.EngineAPIResource
openai.api_resources.chat_completion.ChatCompletion
openai.api_resources.completion.Completion
openai.api_resources.edit.Edit
openai.api_resources.embedding.Embedding
openai.api_resources.abstract.listable_api_resource.ListableAPIResource
openai.api_resources.abstract.updateable_api_resource.UpdateableAPIResource
openai.api_resources.abstract.listable_api_resource.ListableAPIResource
openai.api_resources.audio.Audio
openai.api_resources.image.Image
openai.api_resources.customer.Customer
openai.api_resources.error_object.ErrorObject
openai.api_resources.moderation.Moderation
◆float
◆numpy.generic
◆itertools.count
◆itertools.islice
◆json.decoder.JSONDecoder
◆json.encoder.JSONEncoder
◆logging.BufferingFormatter
◆logging.Filter
◆logging.Filterer
◆logging.Handler
◆logging.NullHandler
◆logging.StreamHandler
◆logging.FileHandler
◆logging._StderrHandler
◆logging.Logger
◆logging.RootLogger
◆logging.Formatter
◆logging.LogRecord
◆logging.LoggerAdapter
◆logging.Manager
◆logging.PercentStyle
◆logging.StrFormatStyle
◆logging.StringTemplateStyle
◆logging.PlaceHolder
◆nt.DirEntry
◆numpy.DataSource
◆numpy.MachAr
◆numpy.broadcast
◆numpy.busdaycalendar
◆numpy.dtype
◆numpy.finfo
◆numpy.flatiter
◆numpy.format_parser
◆numpy.generic
◆numpy.iinfo
◆numpy.ndarray
◆numpy.chararray
◆numpy.matrix
◆numpy.memmap
◆numpy.recarray
◆numpy.ndenumerate
◆numpy.ndindex
◆numpy.nditer
◆numpy.poly1d
◆numpy.ufunc
◆numpy.vectorize
openai.api_requestor.APIRequestor
openai.openai_response.OpenAIResponse
◆os._wrap_close
◆pandas._libs.interval.IntervalMixin
◆pandas._libs.interval.Interval
◆pandas._libs.tslibs.offsets.BaseOffset
◆pandas._libs.tslibs.offsets.RelativeDeltaOffset
◆pandas._libs.tslibs.offsets.DateOffset
◆pandas._libs.tslibs.period.PeriodMixin
◆pandas._libs.tslibs.period._Period
◆pandas._libs.tslibs.period.Period
◆pandas.core.accessor.DirNamesMixin
◆pandas.core.accessor.PandasDelegate
◆pandas.core.accessor.DirNamesMixin
◆pandas.core.arraylike.OpsMixin
◆pandas.core.dtypes.base.ExtensionDtype
◆pandas.core.arrays.masked.BaseMaskedDtype
◆pandas.core.arrays.boolean.BooleanDtype
◆pandas.core.arrays.numeric.NumericDtype
◆pandas.core.arrays.floating.FloatingDtype
◆pandas.core.arrays.floating.Float32Dtype
◆pandas.core.arrays.floating.Float64Dtype
◆pandas.core.arrays.integer._IntegerDtype
◆pandas.core.arrays.integer.Int16Dtype
◆pandas.core.arrays.integer.Int32Dtype
◆pandas.core.arrays.integer.Int64Dtype
◆pandas.core.arrays.integer.Int8Dtype
◆pandas.core.arrays.integer.UInt16Dtype
◆pandas.core.arrays.integer.UInt32Dtype
◆pandas.core.arrays.integer.UInt64Dtype
◆pandas.core.arrays.integer.UInt8Dtype
◆pandas.core.arrays.sparse.dtype.SparseDtype
◆pandas.core.arrays.string_.StringDtype
◆pandas.core.dtypes.dtypes.PandasExtensionDtype
◆pandas._libs.tslibs.dtypes.PeriodDtypeBase
◆pandas.core.dtypes.dtypes.PeriodDtype
◆pandas.core.dtypes.dtypes.CategoricalDtype
◆pandas.core.dtypes.dtypes.DatetimeTZDtype
◆pandas.core.dtypes.dtypes.IntervalDtype
◆pandas.core.flags.Flags
◆pandas.core.groupby.grouper.Grouper
◆pandas.core.indexing.IndexingMixin
◆pandas.io.excel._base.ExcelFile
◆pandas.io.excel._base.ExcelWriter
◆pandas.io.pytables.HDFStore
◆re.Match
◆re.Pattern
◆re.Scanner
◆requests.models.RequestHooksMixin
◆requests.models.Request
◆requests.models.RequestEncodingMixin
◆requests.models.PreparedRequest
◆requests.models.Response
◆requests.sessions.SessionRedirectMixin
◆requests.sessions.Session
◆string.Template
◆threading.Barrier
◆threading.Condition
◆threading.Event
◆threading.Semaphore
◆threading.BoundedSemaphore
◆threading.Thread
◆threading.Timer
◆threading._DummyThread
◆threading._MainThread
◆threading._RLock
◆tuple
◆aiohttp.helpers.BasicAuth
◆aiohttp.helpers.BasicAuth
◆aiohttp.http_websocket._WSMessageBase
◆aiohttp.http_websocket.WSMessage
◆aiohttp.http_writer.HttpVersion
◆nt.times_result
◆nt.uname_result
◆os.stat_result
◆os.statvfs_result
◆os.terminal_size
◆pandas.core.groupby.generic.NamedAgg
◆platform.uname_result
◆time.struct_time
◆typing.Generic
◆aiohttp.streams.DataQueue
◆aiohttp.streams.FlowControlDataQueue
◆collections.abc.Container
◆collections.abc.Iterable
◆warnings.WarningMessage
◆warnings.catch_warnings
◆Enum
◆int
◆IntEnum
◆WSCloseCode
◆WSMsgType
◆IntFlag
◆RegexFlag
ApiType
◆Flag
◆int
结束
- 敬请期待:
- OpenAI API 的安装
- 基于 OpenAI API 开发的一个简单的例子
- OpenAI API包的子模块展开
- OpenAI API包有依赖对象(requirements)清单模块的展开