Files
puter/src/backend/src/modules/puterai/AIInterfaceService.js
T
KernelDeimos aa3dcea462 refactor: central controller for all LLM services
Adds AIChatService, an implementor of puter-chat-completion which can
delegate to other implementors (implementors that have registered with
AIChatService at initialization) based on details of the request.

Makes AIChatService the test implementation. AIChatService then
delegates to FakeChatService when in test mode.

Adds `models()` method to puter-chat-completion. This method, instead of
returning only the names of supported models, includes other details
such as the cost and maximum output size.

Implements `models()` on Claude and XAI.

Registers Claude and XAI with AIChatService.
2024-11-22 15:52:37 -05:00

119 lines
3.9 KiB
JavaScript

const BaseService = require("../../services/BaseService");
class AIInterfaceService extends BaseService {
async ['__on_driver.register.interfaces'] () {
const svc_registry = this.services.get('registry');
const col_interfaces = svc_registry.get('interfaces');
col_interfaces.set('puter-ocr', {
description: 'Optical character recognition',
methods: {
recognize: {
description: 'Recognize text in an image or document.',
parameters: {
source: {
type: 'file',
},
},
result: {
type: {
$: 'stream',
content_type: 'image',
}
},
},
}
});
col_interfaces.set('puter-chat-completion', {
description: 'Chatbot.',
methods: {
models: {
description: 'List supported models and their details.',
result: { type: 'json' },
parameters: {},
},
list: {
description: 'List supported models',
result: { type: 'json' },
parameters: {},
},
complete: {
description: 'Get completions for a chat log.',
parameters: {
messages: { type: 'json' },
vision: { type: 'flag' },
stream: { type: 'flag' },
model: { type: 'string' },
},
result: { type: 'json' },
}
}
});
col_interfaces.set('puter-image-generation', {
description: 'AI Image Generation.',
methods: {
generate: {
description: 'Generate an image from a prompt.',
parameters: {
prompt: { type: 'string' },
},
result_choices: [
{
names: ['image'],
type: {
$: 'stream',
content_type: 'image',
}
},
{
names: ['url'],
type: {
$: 'string:url:web',
content_type: 'image',
}
},
],
result: {
description: 'URL of the generated image.',
type: 'string'
}
}
}
});
col_interfaces.set('puter-tts', {
description: 'Text-to-speech.',
methods: {
list_voices: {
description: 'List available voices.',
parameters: {},
},
synthesize: {
description: 'Synthesize speech from text.',
parameters: {
text: { type: 'string' },
voice: { type: 'string' },
language: { type: 'string' },
ssml: { type: 'flag' },
},
result_choices: [
{
names: ['audio'],
type: {
$: 'stream',
content_type: 'audio',
}
},
]
},
}
})
}
}
module.exports = {
AIInterfaceService
};