INNER CODE UNIT · Python

create_completion_json

hyperonym/basaran · basaran/__main__.py:217

def create_completion_json(options, template):
    """Return text completion results in plain JSON."""

    # Tokenize the prompt beforehand to count token usage.
    options["prompt"] = stream_model.tokenize(options["prompt"])
    prompt_tokens = options["prompt"].shape[-1]
    completion_tokens = 0

    # Add data to the corresponding buffer according to the index.
    buffers = {}
    for choice in stream_model(**options):
        completion_tokens += 1
        index = choice["index"]
        if index not in buffers:
            buffers[index] = []
        buffers[index].append(choice)

    # Merge choices with the same index.

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…