"typical": self.typical,
        }
        if stop is not None:
            data["stop_sequence"] = stop
        response = requests.post(
            f"{clean_url(self.endpoint)}/api/v1/generate", json=data
        )
        response.raise_for_status()
        json_response = response.json()
        if (
            "results" in json_response
            and len(json_response["results"]) > 0
            and "text" in json_response["results"][0]
        ):
            text = json_response["results"][0]["text"].strip()
            if stop is not None:
                for sequence in stop:
                    if text.endswith(sequence):
                        text = text[: -len(sequence)].rstrip()
            return text
        else:
            raise ValueError(
                f"Unexpected response format from Kobold API:  {json_response}"
            )