merlin-node是一個Node.js客戶端軟件包,可輕鬆與Merlin API進行交互,使用戶可以訪問各種機器學習模型以進行視覺和語言任務。此讀數將指導您完成merlin-node的安裝,配置和使用。
要安裝merlin-node軟件包,請在終端中運行以下命令:
npm install merlin-node --save或者,如果您喜歡使用yarn :
yarn add merlin-node在使用merlin-node之前,您需要設置Merlin API提供的API密鑰。此密鑰對於身份驗證和授權您的請求是必需的。
import { Merlin } from 'merlin-node' ;
const apiKey = '<API_KEY>' ; // Replace with your API key
const merlin = new Merlin ( { merlinConfig : { apiKey : apiKey } } ) ;要使用merlin-node ,將基於視覺的模型和DALL-E等基於視覺的模型,您可以按照給定的示例從文本描述中生成圖像:
import { Merlin } from 'merlin-node' ;
const merlin = new Merlin ( { merlinConfig : { apiKey : '<API_KEY>' } } ) ;
async function generateImage ( ) {
try {
const response = await merlin . images . generate ( {
prompt : 'This is a picture of a dog' ,
model : 'dall-e-2' , // or 'leonardo' for the Leonardo model
size : '256x256' ,
response_format : 'b64_json' ,
} ) ;
console . log ( JSON . stringify ( response , null , 2 ) ) ;
} catch ( error ) {
console . error ( 'Error generating image:' , error ) ;
}
}
generateImage ( ) ;此代碼設置了一個函數,以根據指定的提示,型號和大小請求生成圖像。
對於OpenAI,Mistral,Gemini,Anthropic等語言模型, merlin-node提供了一個簡單的界面,如下所示:
import { Merlin } from 'merlin-node' ;
const merlin = new Merlin ( { merlinConfig : { apiKey : 'MERLIN_API_KEY_HERE' } } ) ;
async function createCompletion ( ) {
try {
const completion = await merlin . chat . completions . create ( {
messages : [ { role : 'system' , content : 'You are a helpful assistant.' } ] ,
model : 'gpt-3.5-turbo' , // Adjust model as needed
} ) ;
console . log ( completion . choices [ 0 ] ) ;
} catch ( error ) {
console . error ( 'Error creating completion:' , error ) ;
}
}
createCompletion ( ) ;該片段演示瞭如何發送系統消息並從指定的語言模型中獲得完成。
有關快速問題或與merlin-api社區互動,請加入我們的Discord服務器。
有關詳細的查詢或私人事務,請通過電子郵件與Merlin團隊聯繫:
請對您遇到的簡化支持流程的問題提供清晰而詳細的說明。
在Twitter @foyerwork上關注我們,以獲取定期更新,提示和社區重點。
在LinkedIn上與我們聯繫,以獲取更多專業的參與和公司新聞。
遇到錯誤還是想為merlin-api提出新功能?直接在我們的GitHub存儲庫上籌集票:
merlin節點github repo
打開一個問題:
New Issue 。如果您發現安全漏洞或應立即解決的問題:
訪問我們的主頁以獲取全面的文檔和API指南。
要獲得額外的支持,請探索我們主頁上列出的資源。
我們致力於為您提供充分利用merlin-api所需的支持。不要猶豫,解決您可能有任何問題或問題。
注意:用Merlin API的實際API鍵替換<API_KEY> 。