Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
83 lines
2.7 KiB
JavaScript
83 lines
2.7 KiB
JavaScript
const axios = require('axios');
|
|
const config = require('./config');
|
|
|
|
async function testLLMEndpoint() {
|
|
console.log('Testing LLM endpoint...');
|
|
console.log(`URL: ${config.LLM_API_URL}`);
|
|
console.log(`Model: ${config.LLM_MODEL}`);
|
|
|
|
const testPrompt = "Tell me a short joke.";
|
|
|
|
try {
|
|
const response = await axios.post(
|
|
config.LLM_API_URL,
|
|
{
|
|
model: config.LLM_MODEL,
|
|
messages: [
|
|
{ role: "user", content: testPrompt }
|
|
],
|
|
stream: true,
|
|
max_tokens: 100
|
|
},
|
|
{
|
|
headers: {
|
|
'Authorization': `Bearer ${config.OPENAI_API_KEY}`,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
responseType: 'stream'
|
|
}
|
|
);
|
|
|
|
console.log('Connection established successfully');
|
|
|
|
let fullResponse = '';
|
|
|
|
response.data.on('data', chunk => {
|
|
const lines = chunk.toString().split('\n');
|
|
for (const line of lines) {
|
|
if (line.trim() === '') continue;
|
|
if (line.trim() === 'data: [DONE]') continue;
|
|
if (!line.startsWith('data: ')) continue;
|
|
|
|
try {
|
|
const jsonData = JSON.parse(line.replace('data: ', ''));
|
|
const content = jsonData.choices[0]?.delta?.content || '';
|
|
fullResponse += content;
|
|
process.stdout.write(content); // Stream the response
|
|
} catch (e) {
|
|
console.error('Error parsing chunk:', e);
|
|
console.error('Raw chunk:', line);
|
|
}
|
|
}
|
|
});
|
|
|
|
response.data.on('end', () => {
|
|
console.log('\n\nFull response received:', fullResponse);
|
|
console.log('\nTest completed successfully');
|
|
});
|
|
|
|
response.data.on('error', (error) => {
|
|
console.error('Stream error:', error);
|
|
});
|
|
|
|
} catch (error) {
|
|
console.error('\nError testing LLM endpoint:', error.message);
|
|
if (error.response) {
|
|
console.error('Response status:', error.response.status);
|
|
console.error('Response headers:', JSON.stringify(error.response.headers, null, 2));
|
|
}
|
|
|
|
// Log safe error properties
|
|
const safeError = {
|
|
message: error.message,
|
|
name: error.name,
|
|
stack: error.stack,
|
|
code: error.code,
|
|
status: error.status
|
|
};
|
|
console.error('\nError details:', JSON.stringify(safeError, null, 2));
|
|
}
|
|
}
|
|
|
|
// Run the test
|
|
testLLMEndpoint();
|