File tree Expand file tree Collapse file tree 5 files changed +23
-8
lines changed
Expand file tree Collapse file tree 5 files changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -6,3 +6,4 @@ export * from './utils/llm/grok'
66export * from './utils/llm/structures/zod'
77export * from './utils/prompts'
88export * from './utils/strategies'
9+ export * from './utils/errors'
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ export type LlmProcessOutput = {
4949 model : string
5050 }
5151 response : Strategy [ ] | null
52+ error ?: string | null
5253}
5354
5455export type ProcessAddressProps = {
Original file line number Diff line number Diff line change 1+ export function stringifyError ( error : unknown ) : string {
2+ return error instanceof Error ? error . message : JSON . stringify ( error )
3+ }
Original file line number Diff line number Diff line change 11import { GoogleGenerativeAI , Schema , SchemaType } from '@google/generative-ai'
22import { LlmProcessOutput , LlmProcessProps , Strategy } from '../../types'
3+ import { stringifyError } from '../errors'
34
45export const GEMINI_MODELS = {
56 // TODO: more pre-config models
@@ -57,6 +58,7 @@ const schema = {
5758
5859export async function callGemini ( llmInput : LlmProcessProps ) : Promise < LlmProcessOutput > {
5960 let output = null
61+ let error = null
6062 const model = llmInput . model || GEMINI_MODELS . gemini20flashExp
6163
6264 try {
@@ -74,10 +76,12 @@ export async function callGemini(llmInput: LlmProcessProps): Promise<LlmProcessO
7476
7577 try {
7678 output = JSON . parse ( content || '[]' ) as Strategy [ ]
77- } catch ( error ) {
78- console . error ( 'Invalid JSON in Gemini AI output: ' , error )
79+ } catch ( err ) {
80+ error = stringifyError ( err )
81+ console . error ( `Invalid JSON in Gemini AI output: ${ error } ` )
7982 }
80- } catch ( error ) {
83+ } catch ( err ) {
84+ error = stringifyError ( err )
8185 console . error ( `Error querying Gemini AI: ${ error } ` )
8286 }
8387
@@ -86,6 +90,7 @@ export async function callGemini(llmInput: LlmProcessProps): Promise<LlmProcessO
8690 provider : 'Google' ,
8791 model
8892 } ,
89- response : output
93+ response : output ,
94+ error
9095 }
9196}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import OpenAI from 'openai'
22import { zodResponseFormat } from 'openai/helpers/zod'
33import { LlmProcessOutput , LlmProcessProps , Strategy } from '../../types'
44import { StrategiesZodSchema } from './structures/zod'
5+ import { stringifyError } from '../errors'
56
67export const XAI_MODELS = {
78 grok2latest : 'grok-2-latest'
@@ -14,6 +15,7 @@ const apiClient = new OpenAI({
1415
1516export async function callGrok ( llmInput : LlmProcessProps ) : Promise < LlmProcessOutput > {
1617 let output = null
18+ let error = null
1719 const model = llmInput . model || XAI_MODELS . grok2latest
1820
1921 try {
@@ -36,10 +38,12 @@ export async function callGrok(llmInput: LlmProcessProps): Promise<LlmProcessOut
3638 try {
3739 const parsed = JSON . parse ( outputContent ) as { strategies : Strategy [ ] }
3840 output = parsed . strategies || [ ]
39- } catch ( error ) {
40- console . error ( 'Invalid JSON in Grok output: ' , error )
41+ } catch ( err ) {
42+ error = stringifyError ( err )
43+ console . error ( `Invalid JSON in Grok output: ${ error } ` )
4144 }
42- } catch ( error ) {
45+ } catch ( err ) {
46+ error = stringifyError ( err )
4347 console . error ( `Error querying Grok: ${ error } ` )
4448 }
4549
@@ -48,6 +52,7 @@ export async function callGrok(llmInput: LlmProcessProps): Promise<LlmProcessOut
4852 provider : 'xAI' ,
4953 model
5054 } ,
51- response : output
55+ response : output ,
56+ error
5257 }
5358}
You can’t perform that action at this time.
0 commit comments