mirror of
https://github.com/hpcaitech/ColossalAI.git
synced 2025-06-20 12:43:55 +00:00
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/PyCQA/autoflake: v2.2.1 → v2.3.1](https://github.com/PyCQA/autoflake/compare/v2.2.1...v2.3.1) - [github.com/pycqa/isort: 5.12.0 → 5.13.2](https://github.com/pycqa/isort/compare/5.12.0...5.13.2) - [github.com/psf/black-pre-commit-mirror: 23.9.1 → 24.4.2](https://github.com/psf/black-pre-commit-mirror/compare/23.9.1...24.4.2) - [github.com/pre-commit/mirrors-clang-format: v13.0.1 → v18.1.7](https://github.com/pre-commit/mirrors-clang-format/compare/v13.0.1...v18.1.7) - [github.com/pre-commit/pre-commit-hooks: v4.3.0 → v4.6.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.3.0...v4.6.0) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
31 lines
738 B
Python
31 lines
738 B
Python
"""
|
|
Generation utilities
|
|
"""
|
|
|
|
import json
|
|
from typing import List
|
|
|
|
import requests
|
|
|
|
|
|
def post_http_request(
|
|
prompt: str, api_url: str, n: int = 1, max_tokens: int = 100, temperature: float = 0.0, stream: bool = False
|
|
) -> requests.Response:
|
|
headers = {"User-Agent": "Test Client"}
|
|
pload = {
|
|
"prompt": prompt,
|
|
"n": 1,
|
|
"use_beam_search": False,
|
|
"temperature": temperature,
|
|
"max_tokens": max_tokens,
|
|
"stream": stream,
|
|
}
|
|
response = requests.post(api_url, headers=headers, json=pload, stream=True, timeout=3)
|
|
return response
|
|
|
|
|
|
def get_response(response: requests.Response) -> List[str]:
|
|
data = json.loads(response.content)
|
|
output = data["text"]
|
|
return output
|