Esempio n. 1
0
    def update(
        cls,
        api_key=None,
        api_base=None,
        idempotency_key=None,
        request_id=None,
        api_version=None,
        organization=None,
        **params,
    ):
        # TODO max
        engine_id = params.get("id")
        replicas = params.get("replicas")

        engine = EngineAPIResource(id=id)

        requestor = api_requestor.APIRequestor(
            api_key,
            api_base=api_base,
            api_version=api_version,
            organization=organization,
        )
        url = cls.class_url(engine)
        headers = util.populate_headers(idempotency_key, request_id)
        response, _, api_key = requestor.request("post", url, params, headers)
Esempio n. 2
0
 def cancel(cls, id, api_key=None, request_id=None, **params):
     base = cls.class_url()
     extn = quote_plus(id)
     url = "%s/%s/cancel" % (base, extn)
     instance = cls(id, api_key, **params)
     headers = util.populate_headers(request_id=request_id)
     return instance.request("post", url, headers=headers)
Esempio n. 3
0
    def create(cls,
               api_key=None,
               api_base=None,
               idempotency_key=None,
               request_id=None,
               api_version=None,
               organization=None,
               **params):
        requestor = api_requestor.APIRequestor(
            api_key,
            api_base=api_base,
            api_version=api_version,
            organization=organization,
        )
        url = cls.class_url()
        headers = util.populate_headers(idempotency_key, request_id)
        response, _, api_key = requestor.request("post", url, params, headers)

        return util.convert_to_openai_object(
            response,
            api_key,
            api_version,
            organization,
            plain_old_data=cls.plain_old_data,
        )
Esempio n. 4
0
    def save(self, idempotency_key=None, request_id=None):
        updated_params = self.serialize(None)
        headers = util.populate_headers(idempotency_key, request_id)

        if updated_params:
            self.refresh_from(
                self.request("post", self.instance_url(), updated_params,
                             headers))
        else:
            util.logger.debug("Trying to save already saved object %r", self)
        return self
 def nested_resource_request(
     cls,
     method,
     url,
     api_key=None,
     idempotency_key=None,
     request_id=None,
     api_version=None,
     organization=None,
     **params
 ):
     requestor = api_requestor.APIRequestor(
         api_key, api_version=api_version, organization=organization
     )
     headers = util.populate_headers(idempotency_key, request_id)
     response, _, api_key = requestor.request(method, url, params, headers)
     return util.convert_to_openai_object(
         response, api_key, api_version, organization
     )
Esempio n. 6
0
 def _static_request(cls,
                     method_,
                     url_,
                     api_key=None,
                     idempotency_key=None,
                     request_id=None,
                     api_version=None,
                     organization=None,
                     **params):
     requestor = api_requestor.APIRequestor(
         api_key,
         api_version=api_version,
         organization=organization,
         api_base=self.api_base,
     )
     headers = util.populate_headers(idempotency_key, request_id)
     response, _, api_key = requestor.request(method_, url_, params,
                                              headers)
     return util.convert_to_openai_object(response, api_key, api_version,
                                          organization)
Esempio n. 7
0
 def list(cls,
          api_key=None,
          request_id=None,
          api_version=None,
          organization=None,
          api_base=None,
          **params):
     headers = util.populate_headers(request_id=request_id)
     requestor = api_requestor.APIRequestor(
         api_key,
         api_base=api_base or cls.api_base(),
         api_version=api_version,
         organization=organization,
     )
     url = cls.class_url()
     response, _, api_key = requestor.request("get", url, params, headers)
     openai_object = util.convert_to_openai_object(response, api_key,
                                                   api_version,
                                                   organization)
     openai_object._retrieve_params = params
     return openai_object
Esempio n. 8
0
    def _request(self,
                 method_,
                 url_,
                 api_key=None,
                 idempotency_key=None,
                 openai_version=None,
                 openai_account=None,
                 **params):
        api_key = api_key or self.api_key
        openai_version = openai_version or self.openai_version
        openai_account = openai_account or self.openai_account

        requestor = api_requestor.APIRequestor(api_key,
                                               api_version=openai_version,
                                               account=openai_account)
        headers = util.populate_headers(idempotency_key)
        response, api_key = requestor.request(method_, url_, params, headers)
        openai_object = util.convert_to_openai_object(response, api_key,
                                                      openai_version,
                                                      openai_account)
        return openai_object
Esempio n. 9
0
    def create(
        cls,
        api_key=None,
        api_base=None,
        idempotency_key=None,
        request_id=None,
        api_version=None,
        organization=None,
        **params,
    ):
        """
        Create a new instance of this model.

        Parameters:
        timeout (float): the number of seconds to wait on the promise returned by the API, where 0 means wait forever.
        """
        engine = params.pop("engine", None)
        timeout = params.pop("timeout", None)
        stream = params.get("stream", False)
        if engine is None and cls.engine_required:
            raise error.InvalidRequestError(
                "Must provide an 'engine' parameter to create a %s" % cls,
                "engine")

        if timeout is None:
            # No special timeout handling
            pass
        elif timeout > 0:
            # API only supports timeouts up to MAX_TIMEOUT
            params["timeout"] = min(timeout, MAX_TIMEOUT)
            timeout = (timeout - params["timeout"]) or None
        elif timeout == 0:
            params["timeout"] = MAX_TIMEOUT

        requestor = api_requestor.APIRequestor(
            api_key,
            api_base=api_base,
            api_version=api_version,
            organization=organization,
        )
        url = cls.class_url(engine)
        headers = util.populate_headers(idempotency_key, request_id)
        response, _, api_key = requestor.request("post",
                                                 url,
                                                 params,
                                                 headers,
                                                 stream=stream)

        if stream:
            return (util.convert_to_openai_object(
                line,
                api_key,
                api_version,
                organization,
                engine=engine,
                plain_old_data=cls.plain_old_data,
            ) for line in response)
        else:
            obj = util.convert_to_openai_object(
                response,
                api_key,
                api_version,
                organization,
                engine=engine,
                plain_old_data=cls.plain_old_data,
            )

            if timeout is not None:
                obj.wait(timeout=timeout or None)

        return obj
Esempio n. 10
0
 def refresh(self, request_id=None):
     headers = util.populate_headers(request_id=request_id)
     self.refresh_from(self.request("get", self.instance_url(), headers=headers))
     return self
Esempio n. 11
0
 def verify(self, idempotency_key=None, request_id=None, **params):
     url = self.instance_url() + "/verify"
     headers = util.populate_headers(idempotency_key, request_id)
     self.refresh_from(self.request("post", url, params, headers))
     return self