Created
October 29, 2023 10:43
-
-
Save arafatkatze/054cd8c58c4d1fcf1d2ee61c67f736dd to your computer and use it in GitHub Desktop.
A simple text to show how long it takes for streaming to start based on the prompt length sent to Claude API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from anthropic import Anthropic | |
import time | |
anthropic = Anthropic(api_key="claude-api-key") | |
prompt_lengths = [100, 1000, 10000, 50000] | |
for prompt_length in prompt_lengths: | |
# generate a prompt of the desired length | |
prompt = "Human: " + "cars are great " * (prompt_length // 5) + "write an essay on cars" | |
prompt += "\n\nAssistant:" | |
start_time = time.time() # Record the time before the stream starts | |
stream = anthropic.completions.create( | |
model="claude-2", | |
max_tokens_to_sample=100, | |
prompt=prompt, | |
stream=True | |
) | |
stream_start_time = time.time() # Record the time after the stream starts | |
text = "" | |
for data in stream: | |
diff = data.completion # incremental text | |
text += diff | |
# print(diff, end="") | |
end_time = time.time() # Record the time after the stream ends | |
print(f"\nFor prompt length {prompt_length}:") | |
print(f"Time taken to start the stream: {stream_start_time - start_time} seconds") | |
print(f"Time taken for the stream to finish: {end_time - stream_start_time} seconds") | |
print("\n") |
This is an interesting fact @arafatkatze. I didn't know that the prompt length also affects the response time for the resulting output.
@deepak2431 That's an important one. Its harder to notice in GPT 4 api coz of the token limits being much lower(only 8 K) and also coz its faster but the token size's correlation with time to respond is a thing I have seen in most LLMs I tried.
This is also true for Mistral/LLama2 when I am running them hosted locally.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example response from my local testing