kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
fix: tests
rodzic
f24169cf6b
commit
566ce1fd7a
|
@ -219,12 +219,17 @@ export abstract class BaseChatCompletion<
|
||||||
let output: any
|
let output: any
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
const debugInfo: any = {
|
||||||
|
...this._modelParams,
|
||||||
|
messages
|
||||||
|
}
|
||||||
|
|
||||||
|
if (functions) {
|
||||||
|
debugInfo.functions = functions.map((f: any) => f?.name).filter(Boolean)
|
||||||
|
}
|
||||||
|
|
||||||
this._logger.info(
|
this._logger.info(
|
||||||
{
|
debugInfo,
|
||||||
...this._modelParams,
|
|
||||||
messages,
|
|
||||||
functions: functions.map((f) => f.name)
|
|
||||||
},
|
|
||||||
`>>> Task createChatCompletion "${this.nameForHuman}"`
|
`>>> Task createChatCompletion "${this.nameForHuman}"`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
108
src/logger.ts
108
src/logger.ts
|
@ -1,11 +1,111 @@
|
||||||
import * as pino from 'pino'
|
import { pino } from 'pino'
|
||||||
import pretty from 'pino-pretty'
|
import pinoPretty from 'pino-pretty'
|
||||||
|
|
||||||
export const defaultLogger = pino.pino(
|
export type Level = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace'
|
||||||
|
export type LevelWithSilent = Level | 'silent'
|
||||||
|
|
||||||
|
interface LogFn {
|
||||||
|
<T extends object>(obj: T, msg?: string, ...args: any[]): void
|
||||||
|
(obj: unknown, msg?: string, ...args: any[]): void
|
||||||
|
(msg: string, ...args: any[]): void
|
||||||
|
}
|
||||||
|
|
||||||
|
// these types are taken from `pino`
|
||||||
|
export interface Logger {
|
||||||
|
/**
|
||||||
|
* Set this property to the desired logging level. In order of priority, available levels are:
|
||||||
|
*
|
||||||
|
* - 'fatal'
|
||||||
|
* - 'error'
|
||||||
|
* - 'warn'
|
||||||
|
* - 'info'
|
||||||
|
* - 'debug'
|
||||||
|
* - 'trace'
|
||||||
|
*
|
||||||
|
* The logging level is a __minimum__ level. For instance if `logger.level` is `'info'` then all `'fatal'`, `'error'`, `'warn'`,
|
||||||
|
* and `'info'` logs will be enabled.
|
||||||
|
*
|
||||||
|
* You can pass `'silent'` to disable logging.
|
||||||
|
*/
|
||||||
|
level: LevelWithSilent | string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log at `'fatal'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
|
||||||
|
* If more args follows `msg`, these will be used to format `msg` using `util.format`.
|
||||||
|
*
|
||||||
|
* @typeParam T: the interface of the object being serialized. Default is object.
|
||||||
|
* @param obj: object to be serialized
|
||||||
|
* @param msg: the log message to write
|
||||||
|
* @param ...args: format string values when `msg` is a format string
|
||||||
|
*/
|
||||||
|
fatal: LogFn
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log at `'error'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
|
||||||
|
* If more args follows `msg`, these will be used to format `msg` using `util.format`.
|
||||||
|
*
|
||||||
|
* @typeParam T: the interface of the object being serialized. Default is object.
|
||||||
|
* @param obj: object to be serialized
|
||||||
|
* @param msg: the log message to write
|
||||||
|
* @param ...args: format string values when `msg` is a format string
|
||||||
|
*/
|
||||||
|
error: LogFn
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log at `'warn'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
|
||||||
|
* If more args follows `msg`, these will be used to format `msg` using `util.format`.
|
||||||
|
*
|
||||||
|
* @typeParam T: the interface of the object being serialized. Default is object.
|
||||||
|
* @param obj: object to be serialized
|
||||||
|
* @param msg: the log message to write
|
||||||
|
* @param ...args: format string values when `msg` is a format string
|
||||||
|
*/
|
||||||
|
warn: LogFn
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log at `'info'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
|
||||||
|
* If more args follows `msg`, these will be used to format `msg` using `util.format`.
|
||||||
|
*
|
||||||
|
* @typeParam T: the interface of the object being serialized. Default is object.
|
||||||
|
* @param obj: object to be serialized
|
||||||
|
* @param msg: the log message to write
|
||||||
|
* @param ...args: format string values when `msg` is a format string
|
||||||
|
*/
|
||||||
|
info: LogFn
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log at `'debug'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
|
||||||
|
* If more args follows `msg`, these will be used to format `msg` using `util.format`.
|
||||||
|
*
|
||||||
|
* @typeParam T: the interface of the object being serialized. Default is object.
|
||||||
|
* @param obj: object to be serialized
|
||||||
|
* @param msg: the log message to write
|
||||||
|
* @param ...args: format string values when `msg` is a format string
|
||||||
|
*/
|
||||||
|
debug: LogFn
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log at `'trace'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line.
|
||||||
|
* If more args follows `msg`, these will be used to format `msg` using `util.format`.
|
||||||
|
*
|
||||||
|
* @typeParam T: the interface of the object being serialized. Default is object.
|
||||||
|
* @param obj: object to be serialized
|
||||||
|
* @param msg: the log message to write
|
||||||
|
* @param ...args: format string values when `msg` is a format string
|
||||||
|
*/
|
||||||
|
trace: LogFn
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Noop function.
|
||||||
|
*/
|
||||||
|
silent: LogFn
|
||||||
|
}
|
||||||
|
|
||||||
|
export const defaultLogger: Logger = pino(
|
||||||
{
|
{
|
||||||
level: process.env.LOG_LEVEL || 'info'
|
level: process.env.LOG_LEVEL || 'info'
|
||||||
},
|
},
|
||||||
pretty({
|
pinoPretty({
|
||||||
sync: true,
|
sync: true,
|
||||||
colorize: true
|
colorize: true
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,11 +2,11 @@ import * as openai from '@agentic/openai-fetch'
|
||||||
import * as anthropic from '@anthropic-ai/sdk'
|
import * as anthropic from '@anthropic-ai/sdk'
|
||||||
import ky from 'ky'
|
import ky from 'ky'
|
||||||
import type { Options as RetryOptions } from 'p-retry'
|
import type { Options as RetryOptions } from 'p-retry'
|
||||||
import type { Logger } from 'pino'
|
|
||||||
import type { JsonObject, JsonValue } from 'type-fest'
|
import type { JsonObject, JsonValue } from 'type-fest'
|
||||||
import { SafeParseReturnType, ZodType, ZodTypeAny, output, z } from 'zod'
|
import { SafeParseReturnType, ZodType, ZodTypeAny, output, z } from 'zod'
|
||||||
|
|
||||||
import type { Agentic } from './agentic'
|
import type { Agentic } from './agentic'
|
||||||
|
import type { Logger } from './logger'
|
||||||
import type { BaseTask } from './task'
|
import type { BaseTask } from './task'
|
||||||
|
|
||||||
export { openai }
|
export { openai }
|
||||||
|
|
|
@ -32,6 +32,10 @@ test('OpenAIChatCompletion - tools - calculator', async (t) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
test('OpenAIChatCompletion - tools - weather', async (t) => {
|
test('OpenAIChatCompletion - tools - weather', async (t) => {
|
||||||
|
if (!process.env.WEATHER_API_KEY) {
|
||||||
|
return t.pass()
|
||||||
|
}
|
||||||
|
|
||||||
t.timeout(2 * 60 * 1000)
|
t.timeout(2 * 60 * 1000)
|
||||||
const agentic = createTestAgenticRuntime()
|
const agentic = createTestAgenticRuntime()
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue