@@ -3,6 +3,7 @@ import { zodResponseFormat } from 'openai/helpers/zod'
33import { LlmProcessOutput , LlmProcessProps , Strategy } from '../../types'
44import { StrategiesZodSchema } from './structures/zod'
55import { stringifyError } from '../errors'
6+ import { timeoutPromise } from '../timing'
67
78export const XAI_MODELS = {
89 grok2latest : 'grok-2-latest' ,
@@ -22,20 +23,24 @@ export async function callGrok(llmInput: LlmProcessProps): Promise<LlmProcessOut
2223 let outputTokens : number | undefined
2324
2425 try {
25- const completion = await apiClient . chat . completions . create ( {
26- model,
27- store : true ,
28- messages : [
29- {
30- role : 'system' ,
31- content :
32- 'You are an expert in cryptocurrencies, DeFi applications and their use cases. Return output in JSON format.'
33- } ,
34- { role : 'user' , content : llmInput . prompt }
35- ] ,
36- response_format : zodResponseFormat ( StrategiesZodSchema , 'strategies' ) ,
37- ...llmInput . llmOptionsOverride
38- } )
26+ const completion = await timeoutPromise (
27+ apiClient . chat . completions . create ( {
28+ model,
29+ store : true ,
30+ messages : [
31+ {
32+ role : 'system' ,
33+ content :
34+ 'You are an expert in cryptocurrencies, DeFi applications and their use cases. Return output in JSON format.'
35+ } ,
36+ { role : 'user' , content : llmInput . prompt }
37+ ] ,
38+ response_format : zodResponseFormat ( StrategiesZodSchema , 'strategies' ) ,
39+ ...llmInput . llmOptionsOverride
40+ } ) ,
41+ llmInput . timeout || 60 ,
42+ llmInput . timeoutMsg
43+ )
3944
4045 const outputContent = completion . choices [ 0 ] . message . content || '{}'
4146 inputTokens = completion . usage ?. prompt_tokens || 0
0 commit comments