
區(qū)塊鏈API推薦,快速開發(fā)去中心化應(yīng)用
方式1:HTTP
$API_KEY替換為你的API 密鑰
curl --location 'https://api.lingyiwanwu.com/v1/chat/completions' \
--header 'Authorization: Bearer $API_KEY" \ //API 密鑰
--header 'Content-Type: application/json' \
--data '{
"temperature": 0.3,
"model": "yi-large-rag",
"stream": false,
"max_tokens": 3000,
"messages": [
{
"role": "user",
"content": "How is the weather in Los Angeles today?"
}
]
}'
響應(yīng)
{
"id": "cmpl-ea89ae83",
"object": "chat.completion",
"created": 5785971,
"model": "yi-large-rag",
"usage": {
"completion_tokens": 113,
"prompt_tokens": 896,
"total_tokens": 1009
},
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Today in Los Angeles, the weather is currently overcast with a temperature of 17°C. The forecast for the day indicates a high of 23°C and a low of 15°C, with sunny conditions expected at times. The humidity is currently at a comfortable level, and the chance of rain is 0% throughout the day. Winds are expected to be light, with an average speed of 3 to 4 mph. Overall, it looks like a pleasant day with a mix of sun and clouds."
},
"quote": [
{
"num": 1,
"url": "https://weather.com/weather/today/",
"title": "Los Angeles weather today"
},
{
"num": 2,
"url": "https://weather.com/weather/tenday/l/Los+Angeles+CA?canonicalCityId=84c64154109916077c8d3c2352410aaae5f6eeff682000e3a7470e38976128c2",
"title": "The Weather Channel: 10-Day Weather Forecast for Los Angeles, CA"
},
{
"num": 3,
"url": "https://www.accuweather.com/en/us/los+angeles/90012/weather-forecast/347625",
"title": "AccuWeather: Los Angeles, CA Weather Forecast"
},
{
"num": 4,
"url": "https://www.theweathernetwork.com/en/city/us/california/los+angeles/current",
"title": "The Weather Network: Los Angeles, CA"
},
{
"num": 5,
"url": "https://www.theweathernetwork.com/us/weather/california/los-angeles",
"title": "The Weather Network: Current Weather - Los Angeles"
},
{
"num": 6,
"url": "https://www.timeanddate.com/weather/usa/los-angeles",
"title": "Time and Date: Weather for Los Angeles, California, USA"
}
],
"finish_reason": "stop"
}
]
}
方式2:SDK
零一萬物 API 在設(shè)計上完美兼容 OpenAI 的 Python SDK,只需要簡單配置即可使用。
安裝 OpenAI SDK。請確保使用的 Python 版本至少為 3.7.1,OpenAI SDK 版本不低于 1.0.0。
1pip install openai
代碼示例
import openai
from openai import OpenAI
API_BASE = "https://api.lingyiwanwu.com/v1"
API_KEY = "your key"http:// 填入你的API 密鑰
client = OpenAI(
api_key=API_KEY,
base_url=API_BASE
)
completion = client.chat.completions.create(
model="yi-large",
messages=[{"role": "user", "content": "Hi, who are you?"}]
)
print(completion)
Q:如何找到零一萬物API
A:冪簡集成是國內(nèi)領(lǐng)先的API集成管理平臺,專注于為開發(fā)者提供全面、高效、易用的API集成解決方案。冪簡API平臺可以通過以下兩種方式找到所需API:通過關(guān)鍵詞搜索API(例如,輸入’零一萬物API‘這類品類詞,更容易找到結(jié)果)、或者從API hub分類頁進入尋找。
Q:為什么要限速?
A:
Q:我的回答為什么被截斷了?
A:當(dāng)您在回復(fù)中看到 "finish_reason":"length"
,這意味著模型生成的內(nèi)容因超出 max_tokens 限制或達到了模型的最大上下文長度。為了避免輸出被截斷,建議在調(diào)用 API 時適當(dāng)提高 max_tokens 的數(shù)值。
Q: 怎樣在 LangChain 和 LlamaIndex 中使用 Yi Model API?
A: 對于 LangChain,你需要從 langchain_openai 庫導(dǎo)入 ChatOpenAI,并設(shè)置相應(yīng)的 api_base、api_key 和 model 參數(shù)。對于 LlamaIndex,你需要從 llama_index.llms.openai_like和llama_index.core.llms 導(dǎo)入 OpenAILike 和 ChatMessage,并設(shè)置相應(yīng)的 api_base、api_key 和 model 參數(shù)。
Q:提供AI大模型 API的服務(wù)商除零一萬物API,還有其他替代服務(wù)商也提供類似api服務(wù),例如:
A:360多模態(tài)大語言模型、語音大模型服務(wù)MiniMax-稀宇科技、通用大模型開放平臺-華藏、訊飛星火認知大模型
更多競品可以在冪簡集成開放平臺中找到。
Q:零一萬物API秘鑰還適用于哪些api?
A:List models、Create chat completion
本文總結(jié)了如何獲取零一萬物API密鑰的分步指南,從注冊申請到成功獲取密鑰,為開發(fā)者提供了明確的操作步驟。同時,還概述了在獲取和使用零一萬物API密鑰時可能需要注意的關(guān)鍵點,如API的使用規(guī)定、密鑰的安全保管等,幫助開發(fā)者順暢地將零一萬物API集成到其應(yīng)用中。