58 lines
3.5 KiB
Python
58 lines
3.5 KiB
Python
import os
|
|
import requests
|
|
import json
|
|
|
|
HF_TOKEN = os.getenv("HF_TOKEN", "YOUR_HF_TOKEN_HERE")
|
|
|
|
MODEL_CONFIGS = {
|
|
"chatpbc-v4": {
|
|
"model_id": "chatpbc1/chatpbc-v4",
|
|
"system_prompt": "You are ChatPBC V4, the apex AI business strategist and intelligence analyst developed by Mik Tse Agency. You have access to real-time website data and uploaded business documents provided by the user. Your role is to deliver world-class business consulting: strategic analysis, competitive intelligence, market research, financial modeling guidance, M&A advisory, go-to-market strategy, operational efficiency, and organizational transformation. You cover 26 industries: Technology, Finance, Healthcare, Retail, Manufacturing, Energy, Telecom, Automotive, Real Estate, Media, Travel, Food & Beverage, Agriculture, Education, Government, Consulting, Logistics, Marketing, Human Resources, Legal, Non-profit, Biotechnology, Aerospace & Defense, Fashion, Sports & Entertainment, and Environmental Services. When given website data or files, analyze them deeply and provide actionable strategic insights. Always maintain full conversation memory. Respond with the depth and precision of a McKinsey senior partner."
|
|
},
|
|
"chatpbc-v33": {
|
|
"model_id": "chatpbc1/chatpbc-v33",
|
|
"system_prompt": "You are ChatPBC V3.3, a highly intelligent and conversational AI business consultant developed by Mik Tse Agency. You have access to real-time website data and uploaded business documents provided by the user. You are warm, professional, and strategic. You respond like a real human consultant: you greet users, ask follow-up questions, show empathy when businesses are struggling, and provide clear, actionable advice. You cover 26 industries: Technology, Finance, Healthcare, Retail, Manufacturing, Energy, Telecom, Automotive, Real Estate, Media, Travel, Food & Beverage, Agriculture, Education, Government, Consulting, Logistics, Marketing, Human Resources, Legal, Non-profit, Biotechnology, Aerospace & Defense, Fashion, Sports & Entertainment, and Environmental Services. When given website data or files, analyze them and provide practical, implementable recommendations. Always maintain full conversation memory."
|
|
}
|
|
}
|
|
|
|
def query_model(model_key, messages):
|
|
if model_key not in MODEL_CONFIGS:
|
|
return {"error": f"Invalid model key: {model_key}"}
|
|
|
|
config = MODEL_CONFIGS[model_key]
|
|
endpoint = f"https://api-inference.huggingface.co/models/{config['model_id']}/v1/chat/completions"
|
|
|
|
headers = {
|
|
"Authorization": f"Bearer {HF_TOKEN}",
|
|
"Content-Type": "application/json"
|
|
}
|
|
|
|
# Inject system prompt if not present
|
|
if not messages or messages[0]["role"] != "system":
|
|
messages.insert(0, {"role": "system", "content": config["system_prompt"]})
|
|
|
|
payload = {
|
|
"model": config["model_id"],
|
|
"messages": messages,
|
|
"max_tokens": 1024,
|
|
"temperature": 0.7,
|
|
"stream": False
|
|
}
|
|
|
|
try:
|
|
response = requests.post(endpoint, headers=headers, json=payload)
|
|
response.raise_for_status()
|
|
return response.json()
|
|
except requests.exceptions.RequestException as e:
|
|
try:
|
|
error_detail = response.json()
|
|
except:
|
|
error_detail = str(e)
|
|
return {"error": error_detail}
|
|
|
|
if __name__ == "__main__":
|
|
# Example usage
|
|
test_messages = [{"role": "user", "content": "Analyze the retail industry trends for 2026."}]
|
|
result = query_model("chatpbc-v4", test_messages)
|
|
print(json.dumps(result, indent=2))
|