跳至主要內容

v0

概觀

屬性詳細資訊
說明v0 提供針對程式碼產生最佳化的 AI 模型,特別適合建立 Next.js 應用程式、React 元件與現代 Web 開發。
LiteLLM 提供者路由v0/
提供者文件連結v0 API 文件 ↗
Base URLhttps://api.v0.dev/v1
支援的操作/chat/completions


https://v0.dev/docs/v0-model-api

我們支援所有 v0 模型,只要在傳送 completion 請求時將 v0/ 設為前綴即可

可用模型

模型說明上下文視窗Max Output
v0/v0-1.5-lg用於進階程式碼產生與推理的大型模型512,000 tokens512,000 tokens
v0/v0-1.5-md用於日常程式碼產生工作的中型模型128,000 tokens128,000 tokens
v0/v0-1.0-md舊版中型模型128,000 tokens128,000 tokens

必要變數

Environment Variables
os.environ["V0_API_KEY"] = ""  # your v0 API key from v0.dev

注意:v0 API 存取需要 Premium 或 Team 方案。請前往 v0.dev/chat/settings/billing 升級。

用法 - LiteLLM Python SDK

非串流

v0 Non-streaming Completion
import os
import litellm
from litellm import completion

os.environ["V0_API_KEY"] = "" # your v0 API key

messages = [{"content": "Create a React button component with hover effects", "role": "user"}]

# v0 call
response = completion(
model="v0/v0-1.5-md",
messages=messages
)

print(response)

串流

v0 Streaming Completion
import os
import litellm
from litellm import completion

os.environ["V0_API_KEY"] = "" # your v0 API key

messages = [{"content": "Create a React button component with hover effects", "role": "user"}]

# v0 call with streaming
response = completion(
model="v0/v0-1.5-md",
messages=messages,
stream=True
)

for chunk in response:
print(chunk)

影像/多模態支援

所有 v0 模型都支援影像輸入,讓您可以將圖片與文字一併傳送:

v0 Vision/Multimodal
import os
import litellm
from litellm import completion

os.environ["V0_API_KEY"] = "" # your v0 API key

messages = [{
"role": "user",
"content": [
{
"type": "text",
"text": "Recreate this UI design in React"
},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/ui-design.png"
}
}
]
}]

response = completion(
model="v0/v0-1.5-lg",
messages=messages
)

print(response)

函式呼叫

v0 支援用於結構化輸出的函式呼叫:

v0 Function Calling
import os
import litellm
from litellm import completion

os.environ["V0_API_KEY"] = "" # your v0 API key

tools = [
{
"type": "function",
"function": {
"name": "create_component",
"description": "Create a React component",
"parameters": {
"type": "object",
"properties": {
"component_name": {
"type": "string",
"description": "The name of the component"
},
"props": {
"type": "array",
"items": {"type": "string"},
"description": "List of component props"
}
},
"required": ["component_name"]
}
}
}
]

response = completion(
model="v0/v0-1.5-md",
messages=[{"role": "user", "content": "Create a Button component with onClick and disabled props"}],
tools=tools,
tool_choice="auto"
)

print(response)

用法 - LiteLLM Proxy

將下列內容加入您的 LiteLLM Proxy 設定檔:

config.yaml
model_list:
- model_name: v0-large
litellm_params:
model: v0/v0-1.5-lg
api_key: os.environ/V0_API_KEY

- model_name: v0-medium
litellm_params:
model: v0/v0-1.5-md
api_key: os.environ/V0_API_KEY

- model_name: v0-legacy
litellm_params:
model: v0/v0-1.0-md
api_key: os.environ/V0_API_KEY

啟動您的 LiteLLM Proxy 伺服器:

Start LiteLLM Proxy
litellm --config config.yaml

# RUNNING on http://0.0.0.0:4000
v0 via Proxy - Non-streaming
from openai import OpenAI

# Initialize client with your proxy URL
client = OpenAI(
base_url="http://localhost:4000", # Your proxy URL
api_key="your-proxy-api-key" # Your proxy API key
)

# Non-streaming response
response = client.chat.completions.create(
model="v0-medium",
messages=[{"role": "user", "content": "Create a React card component"}]
)

print(response.choices[0].message.content)
v0 via Proxy - Streaming
from openai import OpenAI

# Initialize client with your proxy URL
client = OpenAI(
base_url="http://localhost:4000", # Your proxy URL
api_key="your-proxy-api-key" # Your proxy API key
)

# Streaming response
response = client.chat.completions.create(
model="v0-medium",
messages=[{"role": "user", "content": "Create a React card component"}],
stream=True
)

for chunk in response:
if chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content, end="")

如需有關使用 LiteLLM Proxy 的更詳細資訊,請參閱 LiteLLM Proxy 文件

支援的 OpenAI 參數

v0 支援以下與 OpenAI 相容的參數:

參數類型說明
messagesarray必要。具有 'role' 與 'content' 的訊息物件陣列
modelstring必要。模型 ID (v0-1.5-lg, v0-1.5-md, v0-1.0-md)
streamboolean選用。啟用串流回應
toolsarray選用。可用工具/函式清單
tool_choicestring/object選用。控制工具/函式呼叫

注意:與完整的 OpenAI API 相比,v0 支援的參數集合較少。像 temperaturemax_tokenstop_p 等參數不受支援。

進階用法

自訂 API Base

如果您使用的是自訂的 v0 部署:

Custom API Base
import litellm

response = litellm.completion(
model="v0/v0-1.5-md",
messages=[{"role": "user", "content": "Hello"}],
api_base="https://your-custom-v0-endpoint.com/v1",
api_key="your-api-key"
)

定價

v0 模型需要 Premium 或 Team 訂閱。請前往 v0.dev/chat/settings/billing 取得目前定價資訊。

其他資源