mm1 / src /models /provider.py
TheRealHubertus's picture
Upload 49 files
82372e5 verified
Raw
History Blame Contribute Delete
1.52 kB
from __future__ import annotations
import os
def generate_with_hosted_model(prompt: str) -> tuple[str | None, str | None]:
token = os.getenv("HF_TOKEN", "").strip()
model_id = os.getenv("HF_MODEL_ID", "Qwen/Qwen3-Coder-30B-A3B-Instruct").strip()
if not token:
return None, "HF_TOKEN is not configured."
try:
from huggingface_hub import InferenceClient
client = InferenceClient(model=model_id, token=token)
response = client.chat.completions.create(
messages=[
{
"role": "system",
"content": "You are MM1's external under-32B hosted model. Use only the sanitized task. Do not ask for private profile context.",
},
{"role": "user", "content": prompt},
],
max_tokens=700,
)
content = response.choices[0].message.content
return content, None
except Exception as exc:
return None, f"Hosted model call failed: {exc.__class__.__name__}: {exc}"
def provider_status() -> dict[str, str]:
return {
"MM1_MODE": os.getenv("MM1_MODE", "local"),
"MODEL_PROVIDER": os.getenv("MODEL_PROVIDER", "hf"),
"HF_MODEL_ID": os.getenv("HF_MODEL_ID", "Qwen/Qwen3-Coder-30B-A3B-Instruct"),
"MOCK_MODE": os.getenv("MOCK_MODE", "false"),
"CODEX_RUNTIME_MODE": os.getenv("CODEX_RUNTIME_MODE", "true"),
"HACKATHON_COMPLIANT_MODE": os.getenv("HACKATHON_COMPLIANT_MODE", "false"),
}