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> 。