Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions api.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
10 changes: 10 additions & 0 deletions examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion phi_3_vision_mlx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down