import { Adaline } from '@adaline/client';
import type {
Deployment,
DeploymentPrompt,
DeploymentPromptConfig,
DeploymentPromptVariables
} from '@adaline/api';
import { Gateway } from '@adaline/gateway';
import { OpenAI } from '@adaline/openai';
import { Anthropic } from '@adaline/anthropic';
const adaline = new Adaline();
const gateway = new Gateway();
async function useDeployment() {
// Get deployment from Adaline
const deployment: Deployment = await adaline.getLatestDeployment({
promptId: 'prompt_abc123',
deploymentEnvironmentId: 'environment_abc123'
});
// Access deployed prompt configuration
const prompt: DeploymentPrompt = deployment.prompt;
const config: DeploymentPromptConfig = prompt.config;
const variables: DeploymentPromptVariables[] = prompt.variables;
// Log configuration
console.log('Deployed Prompt Configuration:');
console.log(` Provider: ${config.providerName}`);
console.log(` Model: ${config.model}`);
console.log(` Settings:`, config.settings);
console.log(` Messages: ${prompt.messages.length}`);
console.log(` Tools: ${prompt.tools.length}`);
console.log(` Variables: ${variables.map(v => v.name).join(', ')}`);
// Create provider and model based on deployment config
let model;
if (config.providerName === 'openai') {
const openai = new OpenAI();
model = openai.chatModel({
modelName: config.model,
apiKey: process.env.OPENAI_API_KEY!
});
} else if (config.providerName === 'anthropic') {
const anthropic = new Anthropic();
model = anthropic.chatModel({
modelName: config.model,
apiKey: process.env.ANTHROPIC_API_KEY!
});
}
const gatewayMessages = [
...prompt.messages,
// Transform messages to replace variables with their values, etc.
];
// Call LLM using Adaline Gateway
const response = await gateway.completeChat({
model,
config: config.settings,
messages: gatewayMessages,
tools: prompt.tools
});
// Log response details
console.log('Gateway Response:');
console.log(JSON.stringify(response, null, 2));
// Return the first message (in response) content value
return response.response.messages[0].content[0].value;
}