Class GPTChatCompletionServiceImpl

  • All Implemented Interfaces:
    GPTChatCompletionService

    public class GPTChatCompletionServiceImpl
    extends Object
    implements GPTChatCompletionService
    Implements the actual access to the ChatGPT chat API.
    See Also:
    "https://platform.openai.com/docs/api-reference/chat/create", "https://platform.openai.com/docs/guides/chat"
    • Field Detail

      • LOG

        protected static final org.slf4j.Logger LOG
      • PATTERN_TRY_AGAIN

        protected static final Pattern PATTERN_TRY_AGAIN
      • OPENAI_API_KEY

        public static final String OPENAI_API_KEY
        Environment variable where we take the key from, if not configured directly.
        See Also:
        Constant Field Values
      • OPENAI_API_KEY_SYSPROP

        public static final String OPENAI_API_KEY_SYSPROP
        System property where we take the key from, if not configured directly.
        See Also:
        Constant Field Values
      • DEFAULTVALUE_CONNECTIONTIMEOUT

        protected static final int DEFAULTVALUE_CONNECTIONTIMEOUT
        See Also:
        Constant Field Values
      • DEFAULTVALUE_REQUESTTIMEOUT

        protected static final int DEFAULTVALUE_REQUESTTIMEOUT
        See Also:
        Constant Field Values
      • DEFAULTVALUE_REQUESTS_PER_MINUTE

        protected static final int DEFAULTVALUE_REQUESTS_PER_MINUTE
        See Also:
        Constant Field Values
      • DEFAULTVALUE_REQUESTS_PER_HOUR

        protected static final int DEFAULTVALUE_REQUESTS_PER_HOUR
        See Also:
        Constant Field Values
      • DEFAULTVALUE_REQUESTS_PER_DAY

        protected static final int DEFAULTVALUE_REQUESTS_PER_DAY
        See Also:
        Constant Field Values
      • MAXTRIES

        public static final int MAXTRIES
        The maximum number of retries.
        See Also:
        Constant Field Values
      • apiKey

        protected String apiKey
        The OpenAI Key for accessing ChatGPT; system default if not given in request.
      • organizationId

        protected String organizationId
      • defaultModel

        protected String defaultModel
      • highIntelligenceModel

        protected String highIntelligenceModel
      • imageModel

        protected String imageModel
      • chatCompletionUrl

        protected String chatCompletionUrl
      • httpAsyncClient

        protected org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient httpAsyncClient
      • gson

        protected static final com.google.gson.Gson gson
      • requestCounter

        protected final AtomicLong requestCounter
      • limiter

        protected RateLimiter limiter
        Limiter that maps the financial reasons to limit.
      • lastGptLimiterCreationTime

        protected volatile long lastGptLimiterCreationTime
      • gptLimiter

        protected volatile RateLimiter gptLimiter
        If set, this tells the limits of ChatGPT API itself.
      • registry

        protected com.knuddels.jtokkit.api.EncodingRegistry registry
      • enc

        protected com.knuddels.jtokkit.api.Encoding enc
        Tokenizer used for GPT-3.5 and GPT-4.
      • bundleContext

        protected org.osgi.framework.BundleContext bundleContext
      • requestTimeout

        protected int requestTimeout
      • connectionTimeout

        protected int connectionTimeout
      • temperature

        protected Double temperature
      • disabled

        protected boolean disabled
      • maximumTokensPerRequest

        protected Integer maximumTokensPerRequest
      • maximumTokensPerResponse

        protected Integer maximumTokensPerResponse
      • embeddingsLimiter

        protected volatile RateLimiter embeddingsLimiter
        Rate limiter for embeddings. These are a quite inexpensive service (0.13$ per million tokens), so we just introduce a limit that should protect against malfunctions for now.
      • embeddingsUrl

        protected String embeddingsUrl
      • embeddingsModel

        protected String embeddingsModel
    • Constructor Detail

      • GPTChatCompletionServiceImpl

        public GPTChatCompletionServiceImpl()