MCPcopy
hub / github.com/showlab/Code2Video / request_gpt5

Function request_gpt5

src/gpt_request.py:743–793  ·  view source on GitHub ↗

Makes a request to the gpt-5-chat-2025-08-07 model with retry functionality. Args: prompt (str): The text prompt to send to the model log_id (str, optional): The log ID for tracking requests, defaults to tkb+timestamp max_tokens (int, optional): Maximum tokens for r

(prompt, log_id=None, max_tokens=1000, max_retries=3)

Source from the content-addressed store, hash-verified

741
742
743def request_gpt5(prompt, log_id=None, max_tokens=1000, max_retries=3):
744 """
745 Makes a request to the gpt-5-chat-2025-08-07 model with retry functionality.
746
747 Args:
748 prompt (str): The text prompt to send to the model
749 log_id (str, optional): The log ID for tracking requests, defaults to tkb+timestamp
750 max_tokens (int, optional): Maximum tokens for response, default 1000
751 max_retries (int, optional): Maximum number of retry attempts, default 3
752
753 Returns:
754 dict: The model's response
755 """
756
757 base_url = cfg("gpt5", "base_url")
758 api_version = cfg("gpt5", "api_version")
759 ak = cfg("gpt5", "api_key")
760 model_name = cfg("gpt5", "model")
761
762 client = openai.AzureOpenAI(
763 azure_endpoint=base_url,
764 api_version=api_version,
765 api_key=ak,
766 )
767
768 if log_id is None:
769 log_id = generate_log_id()
770
771 extra_headers = {"X-TT-LOGID": log_id}
772
773 retry_count = 0
774 while retry_count < max_retries:
775 try:
776 completion = client.chat.completions.create(
777 model=model_name,
778 messages=[{"role": "user", "content": prompt}],
779 max_tokens=max_tokens,
780 extra_headers=extra_headers,
781 )
782 return completion
783 except Exception as e:
784 retry_count += 1
785 if retry_count >= max_retries:
786 raise Exception(f"Failed after {max_retries} attempts. Last error: {str(e)}")
787
788 # Exponential backoff with jitter
789 delay = (2**retry_count) * 0.1 + (random.random() * 0.1)
790 print(
791 f"Request failed with error: {str(e)}. Retrying in {delay:.2f} seconds... (Attempt {retry_count}/{max_retries})"
792 )
793 time.sleep(delay)
794
795
796def request_gpt5_token(prompt, log_id=None, max_tokens=1000, max_retries=3):

Callers

nothing calls this directly

Calls 2

cfgFunction · 0.85
generate_log_idFunction · 0.85

Tested by

no test coverage detected