modelslab-chat-generation
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseModelsLab Chat/LLM Generation
ModelsLab 对话/大语言模型生成
Send chat completions to 60+ LLM models through a single OpenAI-compatible endpoint.
通过一个兼容OpenAI的端点,向60余种大语言模型(LLM)发送对话补全请求。
When to Use This Skill
何时使用该功能
- Chat with AI models (DeepSeek, Llama, Gemini, Qwen, Mistral)
- Build conversational AI applications
- Generate text completions with system prompts
- Use function/tool calling with LLMs
- Stream responses for real-time output
- Get structured JSON responses
- 与AI模型对话(DeepSeek、Llama、Gemini、Qwen、Mistral)
- 构建对话式AI应用
- 结合系统提示词生成文本补全内容
- 为大语言模型(LLM)启用函数/工具调用
- 流式响应实现实时输出
- 获取结构化JSON响应
API Endpoint
API端点
Chat Completions:
POST https://modelslab.com/api/v7/llm/chat/completionsThe endpoint follows the OpenAI chat completions format, making it easy to switch from OpenAI or use the OpenAI SDK.
Chat Completions:
POST https://modelslab.com/api/v7/llm/chat/completions该端点遵循OpenAI对话补全格式,方便从OpenAI切换或直接使用OpenAI SDK。
Quick Start
快速开始
python
import requests
def chat(message, api_key, model="meta-llama-3-8B-instruct"):
"""Send a chat completion request.
Args:
message: The user message
api_key: Your ModelsLab API key
model: LLM model ID (use modelslab models search --feature llmaster to find models)
"""
response = requests.post(
"https://modelslab.com/api/v7/llm/chat/completions",
json={
"key": api_key,
"model_id": model,
"messages": [
{"role": "user", "content": message}
],
"max_tokens": 200,
"temperature": 0.7
}
)
data = response.json()
if "choices" in data:
return data["choices"][0]["message"]["content"]
else:
raise Exception(f"Error: {data.get('message', 'Unknown error')}")python
import requests
def chat(message, api_key, model="meta-llama-3-8B-instruct"):
"""Send a chat completion request.
Args:
message: The user message
api_key: Your ModelsLab API key
model: LLM model ID (use modelslab models search --feature llmaster to find models)
"""
response = requests.post(
"https://modelslab.com/api/v7/llm/chat/completions",
json={
"key": api_key,
"model_id": model,
"messages": [
{"role": "user", "content": message}
],
"max_tokens": 200,
"temperature": 0.7
}
)
data = response.json()
if "choices" in data:
return data["choices"][0]["message"]["content"]
else:
raise Exception(f"Error: {data.get('message', 'Unknown error')}")Usage
Usage
reply = chat(
"Explain quantum computing in simple terms.",
"your_api_key"
)
print(reply)
undefinedreply = chat(
"Explain quantum computing in simple terms.",
"your_api_key"
)
print(reply)
undefinedWith System Prompt
结合系统提示词
python
def chat_with_system(system_prompt, message, api_key, model="meta-llama-3-8B-instruct"):
"""Chat with a system prompt for role/behavior control."""
response = requests.post(
"https://modelslab.com/api/v7/llm/chat/completions",
json={
"key": api_key,
"model_id": model,
"messages": [
{"role": "system", "content": system_prompt},
{"role": "user", "content": message}
],
"max_tokens": 500,
"temperature": 0.7
}
)
data = response.json()
if "choices" in data:
return data["choices"][0]["message"]["content"]python
def chat_with_system(system_prompt, message, api_key, model="meta-llama-3-8B-instruct"):
"""Chat with a system prompt for role/behavior control."""
response = requests.post(
"https://modelslab.com/api/v7/llm/chat/completions",
json={
"key": api_key,
"model_id": model,
"messages": [
{"role": "system", "content": system_prompt},
{"role": "user", "content": message}
],
"max_tokens": 500,
"temperature": 0.7
}
)
data = response.json()
if "choices" in data:
return data["choices"][0]["message"]["content"]Usage
Usage
reply = chat_with_system(
"You are a Python expert. Give concise code examples.",
"How do I read a CSV file?",
"your_api_key"
)
undefinedreply = chat_with_system(
"You are a Python expert. Give concise code examples.",
"How do I read a CSV file?",
"your_api_key"
)
undefinedMulti-Turn Conversation
多轮对话
python
def conversation(messages, api_key, model="meta-llama-3-8B-instruct"):
"""Send a multi-turn conversation."""
response = requests.post(
"https://modelslab.com/api/v7/llm/chat/completions",
json={
"key": api_key,
"model_id": model,
"messages": messages,
"max_tokens": 500,
"temperature": 0.7
}
)
return response.json()python
def conversation(messages, api_key, model="meta-llama-3-8B-instruct"):
"""Send a multi-turn conversation."""
response = requests.post(
"https://modelslab.com/api/v7/llm/chat/completions",
json={
"key": api_key,
"model_id": model,
"messages": messages,
"max_tokens": 500,
"temperature": 0.7
}
)
return response.json()Multi-turn example
Multi-turn example
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is Python?"},
{"role": "assistant", "content": "Python is a high-level programming language..."},
{"role": "user", "content": "Show me a hello world example."}
]
result = conversation(messages, "your_api_key")
print(result["choices"][0]["message"]["content"])
undefinedmessages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is Python?"},
{"role": "assistant", "content": "Python is a high-level programming language..."},
{"role": "user", "content": "Show me a hello world example."}
]
result = conversation(messages, "your_api_key")
print(result["choices"][0]["message"]["content"])
undefinedOpenAI SDK Compatibility
兼容OpenAI SDK
You can use the official OpenAI Python SDK by changing the base URL and API key:
python
from openai import OpenAI
client = OpenAI(
base_url="https://modelslab.com/api/v7/llm",
api_key="your_modelslab_api_key"
)
response = client.chat.completions.create(
model="meta-llama-3-8B-instruct",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
max_tokens=100,
temperature=0.7
)
print(response.choices[0].message.content)您可以通过修改基础URL和API密钥,使用官方OpenAI Python SDK:
python
from openai import OpenAI
client = OpenAI(
base_url="https://modelslab.com/api/v7/llm",
api_key="your_modelslab_api_key"
)
response = client.chat.completions.create(
model="meta-llama-3-8B-instruct",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
max_tokens=100,
temperature=0.7
)
print(response.choices[0].message.content)cURL Example
cURL示例
bash
curl -X POST "https://modelslab.com/api/v7/llm/chat/completions" \
-H "Content-Type: application/json" \
-d '{
"key": "your_api_key",
"model_id": "meta-llama-3-8B-instruct",
"messages": [
{"role": "user", "content": "Say hello in one sentence."}
],
"max_tokens": 50,
"temperature": 0.7
}'bash
curl -X POST "https://modelslab.com/api/v7/llm/chat/completions" \
-H "Content-Type: application/json" \
-d '{
"key": "your_api_key",
"model_id": "meta-llama-3-8B-instruct",
"messages": [
{"role": "user", "content": "Say hello in one sentence."}
],
"max_tokens": 50,
"temperature": 0.7
}'Discovering LLM Models
查找大语言模型(LLM)
bash
undefinedbash
undefinedSearch all chat/LLM models
Search all chat/LLM models
modelslab models search --feature llmaster
modelslab models search --feature llmaster
Search by provider
Search by provider
modelslab models search --search "deepseek"
modelslab models search --search "llama"
modelslab models search --search "gemini"
modelslab models search --search "deepseek"
modelslab models search --search "llama"
modelslab models search --search "gemini"
Get model details
Get model details
modelslab models detail --id meta-llama-3-8B-instruct
undefinedmodelslab models detail --id meta-llama-3-8B-instruct
undefinedPopular LLM Model IDs
热门大语言模型(LLM)ID
Meta Llama
Meta Llama
- — Llama 3 8B (fast, efficient)
meta-llama-3-8B-instruct - — Llama 3.3 70B (powerful)
meta-llama-Llama-3.3-70B-Instruct-Turbo - — Llama 3.1 405B (largest)
meta-llama-Meta-Llama-3.1-405B-Instruct-Turbo
- — Llama 3 8B(快速、高效)
meta-llama-3-8B-instruct - — Llama 3.3 70B(功能强大)
meta-llama-Llama-3.3-70B-Instruct-Turbo - — Llama 3.1 405B(参数规模最大)
meta-llama-Meta-Llama-3.1-405B-Instruct-Turbo
DeepSeek
DeepSeek
- — DeepSeek R1 (reasoning)
deepseek-ai-DeepSeek-R1-Distill-Llama-70B - — DeepSeek V3 (general purpose)
deepseek-ai-DeepSeek-V3
- — DeepSeek R1(擅长推理)
deepseek-ai-DeepSeek-R1-Distill-Llama-70B - — DeepSeek V3(通用型)
deepseek-ai-DeepSeek-V3
- — Gemini 2.0 Flash (fast)
gemini-2.0-flash-001 - — Gemini 2.5 Pro (capable)
gemini-2.5-pro
- — Gemini 2.0 Flash(快速响应)
gemini-2.0-flash-001 - — Gemini 2.5 Pro(能力全面)
gemini-2.5-pro
Qwen
Qwen
- — Qwen 2.5 72B
Qwen-Qwen2.5-72B-Instruct-Turbo - — Qwen 2.5 Coder
Qwen-Qwen2.5-Coder-32B-Instruct
- — Qwen 2.5 72B
Qwen-Qwen2.5-72B-Instruct-Turbo - — Qwen 2.5 代码模型
Qwen-Qwen2.5-Coder-32B-Instruct
Mistral
Mistral
- — Mixtral 8x7B
mistralai-Mixtral-8x7B-Instruct-v0.1 - — Mistral Small
mistralai-Mistral-Small-24B-Instruct-2501
- — Mixtral 8x7B
mistralai-Mixtral-8x7B-Instruct-v0.1 - — Mistral Small
mistralai-Mistral-Small-24B-Instruct-2501
Key Parameters
关键参数
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | Yes | LLM model identifier (alias: |
| array | Yes | Array of message objects with |
| float | No | Sampling temperature (0-2, default varies by model) |
| integer | No | Maximum tokens to generate |
| float | No | Nucleus sampling (0-1) |
| integer | No | Top-k sampling |
| float | No | Frequency penalty (-2 to 2) |
| float | No | Presence penalty (-2 to 2) |
| boolean | No | Enable streaming responses (alias: |
| integer | No | Number of completions (1-10) |
| array | No | Stop sequences (max 4) |
| integer | No | Random seed for reproducibility |
| array | No | Function/tool definitions |
| string | No | Tool selection strategy |
| object | No | |
| 参数 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| 字符串 | 是 | 大语言模型(LLM)标识符(别名: |
| 数组 | 是 | 包含 |
| 浮点数 | 否 | 采样温度(0-2,默认值因模型而异) |
| 整数 | 否 | 生成的最大token数 |
| 浮点数 | 否 | 核采样参数(0-1) |
| 整数 | 否 | Top-k采样参数 |
| 浮点数 | 否 | 频率惩罚(-2到2) |
| 浮点数 | 否 | 存在惩罚(-2到2) |
| 布尔值 | 否 | 启用流式响应(别名: |
| 整数 | 否 | 生成补全结果的数量(1-10) |
| 数组 | 否 | 停止序列(最多4个) |
| 整数 | 否 | 用于结果复现的随机种子 |
| 数组 | 否 | 函数/工具定义 |
| 字符串 | 否 | 工具选择策略 |
| 对象 | 否 | 指定为 |
Response Format
响应格式
The response follows the OpenAI chat completions format:
json
{
"id": "gen-...",
"model": "meta-llama-3-8B-instruct",
"object": "chat.completion",
"created": 1771658583,
"choices": [
{
"index": 0,
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
}
}
],
"usage": {
"prompt_tokens": 17,
"completion_tokens": 10,
"total_tokens": 27
}
}响应遵循OpenAI对话补全格式:
json
{
"id": "gen-...",
"model": "meta-llama-3-8B-instruct",
"object": "chat.completion",
"created": 1771658583,
"choices": [
{
"index": 0,
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
}
}
],
"usage": {
"prompt_tokens": 17,
"completion_tokens": 10,
"total_tokens": 27
}
}Error Handling
错误处理
python
def safe_chat(message, api_key, model="meta-llama-3-8B-instruct"):
"""Chat with error handling."""
try:
response = requests.post(
"https://modelslab.com/api/v7/llm/chat/completions",
json={
"key": api_key,
"model_id": model,
"messages": [{"role": "user", "content": message}],
"max_tokens": 200
}
)
data = response.json()
if "choices" in data:
return data["choices"][0]["message"]["content"]
elif data.get("status") == "error":
raise Exception(data.get("message", "Unknown error"))
else:
raise Exception(f"Unexpected response: {data}")
except requests.exceptions.RequestException as e:
raise Exception(f"Network error: {e}")
try:
reply = safe_chat("Hello!", "your_api_key")
print(reply)
except Exception as e:
print(f"Chat failed: {e}")python
def safe_chat(message, api_key, model="meta-llama-3-8B-instruct"):
"""Chat with error handling."""
try:
response = requests.post(
"https://modelslab.com/api/v7/llm/chat/completions",
json={
"key": api_key,
"model_id": model,
"messages": [{"role": "user", "content": message}],
"max_tokens": 200
}
)
data = response.json()
if "choices" in data:
return data["choices"][0]["message"]["content"]
elif data.get("status") == "error":
raise Exception(data.get("message", "Unknown error"))
else:
raise Exception(f"Unexpected response: {data}")
except requests.exceptions.RequestException as e:
raise Exception(f"Network error: {e}")
try:
reply = safe_chat("Hello!", "your_api_key")
print(reply)
except Exception as e:
print(f"Chat failed: {e}")Resources
相关资源
- API Documentation: https://docs.modelslab.com/uncensored-chat-api/overview
- Model Browser: https://modelslab.com/models
- Get API Key: https://modelslab.com/dashboard/api-keys
- CLI Tool: https://github.com/ModelsLab/modelslab-cli
Related Skills
相关功能
- - Find and filter models
modelslab-model-discovery - - Manage API keys and billing
modelslab-account-management - - Generate images from text
modelslab-image-generation
- - 查找和筛选模型
modelslab-model-discovery - - 管理API密钥和账单
modelslab-account-management - - 根据文本生成图像
modelslab-image-generation