Chat
To perform a basic chat completion:
import PropulsionAI from 'propulsionai';
import {
ModelChatResponse,
ModelChatParams
} from 'propulsionai/resources/models';
const p8n = new PropulsionAI({
bearerToken: process.env['PROPULSIONAI_BEARER_TOKEN'] as string,
});
async function main() {
try {
let deployment_tag: string = '<deployment_tag>';
let params: ModelChatParams = {
messages: [
{
role: 'system',
content: "You are an amazing poet.",
},
{
role: 'user',
content: "Can you write a poem about Tesla, the innovator?",
},
],
model: 'auto',
stream: false,
wait: true,
};
let response: ModelChatResponse;
try{
response = await p8n.models.ep(deployment_tag, params);
}catch(e){
console.log('Error:', e);
return;
}
console.log("Task ID:", response.task_id);
if(response.choices) {
response.choices.forEach((choice) => {
console.log(`${choice.message?.role}: ${choice.message?.content}`);
});
}
} catch (error) {
console.error('Error during model call:', error);
}
}
main();
Last updated