/
githubmirror
/
workgpt
Обзор
Документация
Войти
/
githubmirror
/
workgpt
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/chat-agents/logger.ts
46 строк
1 KB
Alex MacCaw
Add new openai functions (#1)
15 июн 2023, 08:07
Не верифицирован
15 июн 2023, 08:07
01ae0c2
Код
Авторство
О чём код?
import chalk, { ColorName } from 'chalk' import { ChatFunction, ChatMessage } from './types' export function logChatFunction( direction: 'incoming' | 'outgoing', chatFunction: ChatFunction ) { const message = prefixLines( `${direction === 'outgoing' ? '>>>' : '<<<'} functions: `.padEnd(20), JSON.stringify(chatFunction, null, 2) ) console.log(chalk.white(message)) } export function logChatMessage( direction: 'incoming' | 'outgoing', message: ChatMessage ): void { const color = getColor(message.role) const log = prefixLines( `${direction === 'outgoing' ? '>>>' : '<<<'} ${message.role}: `.padEnd(20), JSON.stringify(message, null, 2) ) console.log(chalk[color](log)) } function getColor(role: string): ColorName { switch (role) { case 'function': return 'green' case 'assistant': return 'blue' case 'user': return 'red' default: return 'white' } } function prefixLines(prefix: string, text: string): string { return text .split('\n') .map((line) => `${prefix}${line}`) .join('\n') }