open-learning-exchange/planet

View on GitHub
chatapi/src/utils/chat.utils.ts

Summary

Maintainability
A
45 mins
Test Coverage
import { aiChatStream, aiChatNonStream } from './chat-helpers.utils';

import { AIProvider } from '../models/ai-providers.model';
import { ChatMessage } from '../models/chat-message.model';

export async function aiChat(
  messages: ChatMessage[],
  aiProvider: AIProvider,
  assistant: boolean,
  context?: any,
  stream?: boolean,
  callback?: (response: string) => void
): Promise<string> {
  if (stream) {
    return await aiChatStream(messages, aiProvider, assistant, callback);
  } else {
    return await aiChatNonStream(messages, aiProvider, assistant, context);
  }
}