2、進(jìn)入工作臺(tái)并訪問(wèn)API key管理菜單

3. 發(fā)起請(qǐ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

零一萬(wàn)物 API 在設(shè)計(jì)上完美兼容 OpenAI 的 Python SDK,只需要簡(jiǎn)單配置即可使用。

安裝 OpenAI SDK。請(qǐng)確保使用的 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)

5. 常見(jiàn)問(wèn)題

Q:如何找到零一萬(wàn)物API

A:冪簡(jiǎn)集成是國(guó)內(nèi)領(lǐng)先的API集成管理平臺(tái),專注于為開(kāi)發(fā)者提供全面、高效、易用的API集成解決方案。冪簡(jiǎn)API平臺(tái)可以通過(guò)以下兩種方式找到所需API:通過(guò)關(guān)鍵詞搜索API(例如,輸入’零一萬(wàn)物API‘這類品類詞,更容易找到結(jié)果)、或者從API hub分類頁(yè)進(jìn)入尋找。

Q:為什么要限速?

A:

  1. 防止濫用:速率限制有助于防止API被濫用或誤用。例如,惡意攻擊可能通過(guò)向API發(fā)送大量請(qǐng)求,試圖使其過(guò)載或造成服務(wù)中斷。通過(guò)設(shè)置限速,可以幫助平臺(tái)用戶免受此類攻擊的影響。
  2. 公平訪問(wèn):速率限制確保所有用戶都能使用API且響應(yīng)迅速。如果沒(méi)有這些限制,少數(shù)用戶可能會(huì)消耗過(guò)多資源,從而降低其他用戶的體驗(yàn)。根據(jù)用戶的實(shí)際需求合理配置限速策略,零一萬(wàn)物 API 平臺(tái)可以保證大多數(shù)用戶可以擁有最佳的使用體驗(yàn)。
  3. 基礎(chǔ)設(shè)施管理:速率限制有助于管理API基礎(chǔ)設(shè)施的整體負(fù)載,這對(duì)于保持服務(wù)的可靠性和性能至關(guān)重要。特別是在需求突然激增的情況下,通過(guò)控制用戶發(fā)送請(qǐng)求的頻率,API服務(wù)的提供方可以更好地管理資源,避免性能瓶頸或服務(wù)中斷。

Q:我的回答為什么被截?cái)嗔耍?/strong>

A:當(dāng)您在回復(fù)中看到 "finish_reason":"length",這意味著模型生成的內(nèi)容因超出 max_tokens 限制或達(dá)到了模型的最大上下文長(zhǎng)度。為了避免輸出被截?cái)啵ㄗh在調(diào)用 API 時(shí)適當(dāng)提高 max_tokens 的數(shù)值。

Q: 怎樣在 LangChain 和 LlamaIndex 中使用 Yi Model API?

A: 對(duì)于 LangChain,你需要從 langchain_openai 庫(kù)導(dǎo)入 ChatOpenAI,并設(shè)置相應(yīng)的 api_base、api_key 和 model 參數(shù)。對(duì)于 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ù)商除零一萬(wàn)物API,還有其他替代服務(wù)商也提供類似api服務(wù),例如:

A:360多模態(tài)大語(yǔ)言模型語(yǔ)音大模型服務(wù)MiniMax-稀宇科技通用大模型開(kāi)放平臺(tái)-華藏訊飛星火認(rèn)知大模型

更多競(jìng)品可以在冪簡(jiǎn)集成開(kāi)放平臺(tái)中找到。

Q:零一萬(wàn)物API秘鑰還適用于哪些api?

A:List modelsCreate chat completion

6.  總結(jié)

本文總結(jié)了如何獲取零一萬(wàn)物API密鑰的分步指南,從注冊(cè)申請(qǐng)到成功獲取密鑰,為開(kāi)發(fā)者提供了明確的操作步驟。同時(shí),還概述了在獲取和使用零一萬(wàn)物API密鑰時(shí)可能需要注意的關(guān)鍵點(diǎn),如API的使用規(guī)定、密鑰的安全保管等,幫助開(kāi)發(fā)者順暢地將零一萬(wàn)物API集成到其應(yīng)用中。

#你可能也喜歡這些API文章!

我們有何不同?

API服務(wù)商零注冊(cè)

多API并行試用

數(shù)據(jù)驅(qū)動(dòng)選型,提升決策效率

查看全部API→
??

熱門(mén)場(chǎng)景實(shí)測(cè),選對(duì)API

#AI文本生成大模型API

對(duì)比大模型API的內(nèi)容創(chuàng)意新穎性、情感共鳴力、商業(yè)轉(zhuǎn)化潛力

25個(gè)渠道
一鍵對(duì)比試用API 限時(shí)免費(fèi)

#AI深度推理大模型API

對(duì)比大模型API的邏輯推理準(zhǔn)確性、分析深度、可視化建議合理性

10個(gè)渠道
一鍵對(duì)比試用API 限時(shí)免費(fèi)