MCPcopy Create free account
hub / github.com/showlab/Code2Video / request_o4mini

Function request_o4mini

src/gpt_request.py:616–672  ·  view source on GitHub ↗

Makes a request to the o4-mini-2025-04-16 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 resp

(prompt, log_id=None, max_tokens=8000, max_retries=3, thinking=False)

Source from the content-addressed store, hash-verified

614
615
616def request_o4mini(prompt, log_id=None, max_tokens=8000, max_retries=3, thinking=False):
617 """
618 Makes a request to the o4-mini-2025-04-16 model with retry functionality.
619
620 Args:
621 prompt (str): The text prompt to send to the model
622 log_id (str, optional): The log ID for tracking requests, defaults to tkb+timestamp
623 max_tokens (int, optional): Maximum tokens for response, default 8000
624 max_retries (int, optional): Maximum number of retry attempts, default 3
625 thinking (bool, optional): Whether to enable thinking mode, default False
626
627 Returns:
628 dict: The model's response
629 """
630 base_url = cfg("gpt4omini", "base_url")
631 api_version = cfg("gpt4omini", "api_version")
632 ak = cfg("gpt4omini", "api_key")
633 model_name = cfg("gpt4omini", "model")
634
635 client = openai.AzureOpenAI(
636 azure_endpoint=base_url,
637 api_version=api_version,
638 api_key=ak,
639 )
640
641 if log_id is None:
642 log_id = generate_log_id()
643
644 extra_headers = {"X-TT-LOGID": log_id}
645
646 # Configure extra_body for thinking if enabled
647 extra_body = None
648 if thinking:
649 extra_body = {"thinking": {"type": "enabled", "budget_tokens": 2000}}
650
651 retry_count = 0
652 while retry_count < max_retries:
653 try:
654 completion = client.chat.completions.create(
655 model=model_name,
656 messages=[{"role": "user", "content": prompt}],
657 max_tokens=max_tokens,
658 extra_headers=extra_headers,
659 extra_body=extra_body,
660 )
661 return completion
662 except Exception as e:
663 retry_count += 1
664 if retry_count >= max_retries:
665 raise Exception(f"Failed after {max_retries} attempts. Last error: {str(e)}")
666
667 # Exponential backoff with jitter
668 delay = (2**retry_count) * 0.1 + (random.random() * 0.1)
669 print(
670 f"Request failed with error: {str(e)}. Retrying in {delay:.2f} seconds... (Attempt {retry_count}/{max_retries})"
671 )
672 time.sleep(delay)
673

Callers

nothing calls this directly

Calls 2

cfgFunction · 0.85
generate_log_idFunction · 0.85

Tested by

no test coverage detected