feat: add method to list models

This commit is contained in:
KernelDeimos 2024-08-22 20:27:51 -04:00
parent 702618f81d
commit fd86934bc9
4 changed files with 25 additions and 0 deletions

View File

@ -28,6 +28,11 @@ class AIInterfaceService extends BaseService {
col_interfaces.set('puter-chat-completion', {
description: 'Chatbot.',
methods: {
list: {
description: 'List supported models',
result: { type: 'json' },
parameters: {},
},
complete: {
description: 'Get completions for a chat log.',
parameters: {

View File

@ -26,6 +26,12 @@ class ClaudeService extends BaseService {
static IMPLEMENTS = {
['puter-chat-completion']: {
async list () {
return [
'claude-3-5-sonnet-20240620',
'claude-3-haiku-20240307',
];
},
async complete ({ messages, stream, model }) {
const adapted_messages = [];

View File

@ -23,6 +23,12 @@ class OpenAICompletionService extends BaseService {
static IMPLEMENTS = {
['puter-chat-completion']: {
async list () {
return [
'gpt-4o',
'gpt-4o-mini',
];
},
async complete ({ messages, test_mode, stream, model }) {
if ( test_mode ) {
const { LoremIpsum } = require('lorem-ipsum');

View File

@ -22,6 +22,14 @@ class TogetherAIService extends BaseService {
static IMPLEMENTS = {
['puter-chat-completion']: {
async list () {
let models = this.modules.kv.get(`${this.kvkey}:models`);
if ( models ) return models;
models = await this.together.models.list();
this.modules.kv.set(
`${this.kvkey}:models`, models, { EX: 5*60 });
return models;
},
async complete ({ messages, stream, model }) {
console.log('model?', model);
const completion = await this.together.chat.completions.create({