diff --git a/src/lib/agents/search/researcher/actions/webSearch.ts b/src/lib/agents/search/researcher/actions/webSearch.ts index 4d60b79f2..bb3576cad 100644 --- a/src/lib/agents/search/researcher/actions/webSearch.ts +++ b/src/lib/agents/search/researcher/actions/webSearch.ts @@ -4,7 +4,6 @@ import { searchSearxng } from '@/lib/searxng'; import { Chunk, SearchResultsResearchBlock } from '@/lib/types'; const actionSchema = z.object({ - type: z.literal('web_search'), queries: z .array(z.string()) .describe('An array of search queries to perform web searches for.'), diff --git a/src/lib/models/providers/groq/groqLLM.ts b/src/lib/models/providers/groq/groqLLM.ts index dfcb2942c..df9babc18 100644 --- a/src/lib/models/providers/groq/groqLLM.ts +++ b/src/lib/models/providers/groq/groqLLM.ts @@ -1,5 +1,42 @@ +import { repairJson } from '@toolsycc/json-repair'; +import { GenerateObjectInput } from '../../types'; import OpenAILLM from '../openai/openaiLLM'; -class GroqLLM extends OpenAILLM {} +class GroqLLM extends OpenAILLM { + async generateObject(input: GenerateObjectInput): Promise { + const response = await this.openAIClient.chat.completions.create({ + messages: this.convertToOpenAIMessages(input.messages), + model: this.config.model, + temperature: + input.options?.temperature ?? this.config.options?.temperature ?? 1.0, + top_p: input.options?.topP ?? this.config.options?.topP, + max_completion_tokens: + input.options?.maxTokens ?? this.config.options?.maxTokens, + stop: input.options?.stopSequences ?? this.config.options?.stopSequences, + frequency_penalty: + input.options?.frequencyPenalty ?? + this.config.options?.frequencyPenalty, + presence_penalty: + input.options?.presencePenalty ?? this.config.options?.presencePenalty, + response_format: { type: 'json_object' }, + }); + + if (response.choices && response.choices.length > 0) { + try { + return input.schema.parse( + JSON.parse( + repairJson(response.choices[0].message.content || '', { + extractJson: true, + }) as string, + ), + ) as T; + } catch (err) { + throw new Error(`Error parsing response from Groq: ${err}`); + } + } + + throw new Error('No response from Groq'); + } +} export default GroqLLM;