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)
| 673 | |
| 674 | |
| 675 | def request_o4mini_token(prompt, log_id=None, max_tokens=8000, max_retries=3, thinking=False): |
| 676 | """ |
| 677 | Makes a request to the o4-mini-2025-04-16 model with retry functionality. |
| 678 | |
| 679 | Args: |
| 680 | prompt (str): The text prompt to send to the model |
| 681 | log_id (str, optional): The log ID for tracking requests, defaults to tkb+timestamp |
| 682 | max_tokens (int, optional): Maximum tokens for response, default 8000 |
| 683 | max_retries (int, optional): Maximum number of retry attempts, default 3 |
| 684 | thinking (bool, optional): Whether to enable thinking mode, default False |
| 685 | |
| 686 | Returns: |
| 687 | dict: The model's response |
| 688 | """ |
| 689 | base_url = cfg("gpt4omini", "base_url") |
| 690 | api_version = cfg("gpt4omini", "api_version") |
| 691 | ak = cfg("gpt4omini", "api_key") |
| 692 | model_name = cfg("gpt4omini", "model") |
| 693 | |
| 694 | client = openai.AzureOpenAI( |
| 695 | azure_endpoint=base_url, |
| 696 | api_version=api_version, |
| 697 | api_key=ak, |
| 698 | ) |
| 699 | |
| 700 | if log_id is None: |
| 701 | log_id = generate_log_id() |
| 702 | |
| 703 | extra_headers = {"X-TT-LOGID": log_id} |
| 704 | |
| 705 | usage_info = {"prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 0} |
| 706 | |
| 707 | # Configure extra_body for thinking if enabled |
| 708 | extra_body = None |
| 709 | if thinking: |
| 710 | extra_body = {"thinking": {"type": "enabled", "budget_tokens": 2000}} |
| 711 | |
| 712 | retry_count = 0 |
| 713 | while retry_count < max_retries: |
| 714 | try: |
| 715 | completion = client.chat.completions.create( |
| 716 | model=model_name, |
| 717 | messages=[{"role": "user", "content": prompt}], |
| 718 | max_tokens=max_tokens, |
| 719 | extra_headers=extra_headers, |
| 720 | extra_body=extra_body, |
| 721 | ) |
| 722 | |
| 723 | if completion.usage: |
| 724 | usage_info["prompt_tokens"] = completion.usage.prompt_tokens |
| 725 | usage_info["completion_tokens"] = completion.usage.completion_tokens |
| 726 | usage_info["total_tokens"] = completion.usage.total_tokens |
| 727 | return completion, usage_info |
| 728 | |
| 729 | except Exception as e: |
| 730 | retry_count += 1 |
| 731 | if retry_count >= max_retries: |
| 732 | raise Exception(f"Failed after {max_retries} attempts. Last error: {str(e)}") |
nothing calls this directly
no test coverage detected