From aae800e74963202d0c6aa22cfe2f142d0ce89d58 Mon Sep 17 00:00:00 2001 From: octo-patch <266937838+octo-patch@users.noreply.github.com> Date: Thu, 30 Jul 2026 04:45:09 +0000 Subject: [PATCH] Add MiniMax external LLM API provider and model paths --- api.py | 42 ++++++++++++++++++++++++++++++++++++++++++ examples.py | 10 ++++++++++ phi_3_vision_mlx.py | 2 +- 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/api.py b/api.py index 10fc39d..519d0c2 100644 --- a/api.py +++ b/api.py @@ -1,8 +1,50 @@ import os from pathlib import Path +import requests from huggingface_hub import InferenceClient +MINIMAX_MODELS = ("MiniMax-M3", "MiniMax-M2.7") + +MINIMAX_BASE_URLS = { + "global_en": "https://api.minimax.io/v1", + "cn_zh": "https://api.minimaxi.com/v1", +} + +def minimax_api(prompt, history, verbose=True, return_dict=True, api_model="MiniMax-M3", region="global_en"): + """ + Example: + -------- + agent = Agent(toolchain = "responses, history = minimax_api(prompt, history)") + agent('Write a neurology ICU admission note') + """ + history = [] if history is None else history + history = history + [{"role": "user", "content": prompt}] + base_url = MINIMAX_BASE_URLS.get(region, MINIMAX_BASE_URLS["global_en"]) + response = requests.post( + f"{base_url}/chat/completions", + headers={ + "Authorization": f"Bearer {os.environ.get('MINIMAX_API_KEY', '')}", + "Content-Type": "application/json", + }, + json=dict( + model=api_model, + messages=history, + temperature=0.9, + top_p=0.95, + max_tokens=8192, + stream=False, + ), + ) + response.raise_for_status() + result = response.json()["choices"][0]["message"]["content"].strip() + history = history + [{"role": "assistant", "content": result}] + if verbose: + print(f'### Prompt ###\n{prompt}\n### Output ###\n{result}') + if return_dict: + return {'responses':result, 'history':history} + return result + def mistral_api(prompt, history, verbose=True, return_dict=True, api_model="mistralai/Mistral-Nemo-Instruct-2407"): """ Example: diff --git a/examples.py b/examples.py index c362375..03a91ec 100644 --- a/examples.py +++ b/examples.py @@ -73,6 +73,16 @@ agent("The patient's prognosis?") agent.end() +## LLM Backend Hotswap (MiniMax) +agent = pv.Agent(toolchain = "responses, history = minimax_api(prompt, history)") +agent('Write a neurology ICU admission note') +agent.end() + +### Selecting a MiniMax model (MiniMax-M3 is the default; MiniMax-M2.7 is also available) +agent = pv.Agent(toolchain = 'responses, history = minimax_api(prompt, history, api_model="MiniMax-M2.7")') +agent('Write a neurology ICU admission note') +agent.end() + # Misc ## ICL diff --git a/phi_3_vision_mlx.py b/phi_3_vision_mlx.py index a8c9af7..26f92e1 100644 --- a/phi_3_vision_mlx.py +++ b/phi_3_vision_mlx.py @@ -26,7 +26,7 @@ from mlx.utils import tree_flatten, tree_unflatten from PIL import Image -from api import bark_api, mistral_api +from api import bark_api, minimax_api, mistral_api from gte import VDB, GteModel from phi import (LoRALinear, Phi3ForCausalLM, Phi3FProcessor, Phi3VForCausalLM, Phi3VProcessor, Tic, TrainingCallback)