diff --git a/agents/llm_agents/package.json b/agents/llm_agents/package.json index dda56a5d..cc3364f0 100644 --- a/agents/llm_agents/package.json +++ b/agents/llm_agents/package.json @@ -29,7 +29,7 @@ "dependencies": { "@graphai/anthropic_agent": "^0.2.1", "@graphai/gemini_agent": "^0.2.1", - "@graphai/groq_agent": "^0.2.0", + "@graphai/groq_agent": "^0.2.1", "@graphai/openai_agent": "^0.2.1", "@graphai/replicate_agent": "^0.2.0", "@graphai/slashgpt_agent": "^0.2.0" diff --git a/llm_agents/groq_agent/lib/groq_agent.d.ts b/llm_agents/groq_agent/lib/groq_agent.d.ts index 406e885f..b407b479 100644 --- a/llm_agents/groq_agent/lib/groq_agent.d.ts +++ b/llm_agents/groq_agent/lib/groq_agent.d.ts @@ -7,11 +7,16 @@ type GroqInputs = { temperature?: number; max_tokens?: number; tool_choice?: ChatCompletionToolChoiceOption; - stream?: boolean; messages?: Array; } & GraphAILLMInputBase; -export declare const groqAgent: AgentFunction; +}; +export declare const groqAgent: AgentFunction; declare const groqAgentInfo: AgentFunctionInfo; export default groqAgentInfo; diff --git a/llm_agents/groq_agent/lib/groq_agent.js b/llm_agents/groq_agent/lib/groq_agent.js index 4e17fc30..665529ae 100644 --- a/llm_agents/groq_agent/lib/groq_agent.js +++ b/llm_agents/groq_agent/lib/groq_agent.js @@ -4,7 +4,6 @@ exports.groqAgent = void 0; const graphai_1 = require("graphai"); const groq_sdk_1 = require("groq-sdk"); const llm_utils_1 = require("@graphai/llm_utils"); -const groq = process.env.GROQ_API_KEY ? new groq_sdk_1.Groq({ apiKey: process.env.GROQ_API_KEY }) : undefined; // // This agent takes two optional inputs, and following parameters. // inputs: @@ -52,9 +51,15 @@ const convertOpenAIChatCompletion = (response, messages) => { messages, }; }; -const groqAgent = async ({ params, namedInputs, filterParams }) => { - (0, graphai_1.assert)(groq !== undefined, "The GROQ_API_KEY environment variable is missing."); - const { verbose, system, tools, tool_choice, max_tokens, temperature, stream, prompt, messages } = { ...params, ...namedInputs }; +const groqAgent = async ({ params, namedInputs, filterParams, config }) => { + const { verbose, system, tools, tool_choice, max_tokens, temperature, prompt, messages } = { ...params, ...namedInputs }; + const { apiKey, stream, forWeb } = { + ...params, + ...(config || {}), + }; + const key = apiKey ?? (process !== undefined ? process.env.GROQ_API_KEY : undefined); + (0, graphai_1.assert)(key !== undefined, "The GROQ_API_KEY environment variable adn apiKey is missing."); + const groq = new groq_sdk_1.Groq({ apiKey, dangerouslyAllowBrowser: !!forWeb }); const userPrompt = (0, llm_utils_1.getMergeValue)(namedInputs, params, "mergeablePrompts", prompt); const systemPrompt = (0, llm_utils_1.getMergeValue)(namedInputs, params, "mergeableSystem", system); // Notice that we ignore params.system if previous_message exists. diff --git a/llm_agents/groq_agent/package.json b/llm_agents/groq_agent/package.json index 67908eb1..222dc093 100644 --- a/llm_agents/groq_agent/package.json +++ b/llm_agents/groq_agent/package.json @@ -1,6 +1,6 @@ { "name": "@graphai/groq_agent", - "version": "0.2.0", + "version": "0.2.1", "description": "Groq agents for GraphAI.", "main": "lib/index.js", "files": [ diff --git a/llm_agents/groq_agent/src/groq_agent.ts b/llm_agents/groq_agent/src/groq_agent.ts index 4b55aff6..4ae8bc8b 100644 --- a/llm_agents/groq_agent/src/groq_agent.ts +++ b/llm_agents/groq_agent/src/groq_agent.ts @@ -13,18 +13,23 @@ import { import { GraphAILLMInputBase, getMergeValue, getMessages } from "@graphai/llm_utils"; -const groq = process.env.GROQ_API_KEY ? new Groq({ apiKey: process.env.GROQ_API_KEY }) : undefined; - type GroqInputs = { verbose?: boolean; tools?: ChatCompletionTool[]; temperature?: number; max_tokens?: number; tool_choice?: ChatCompletionToolChoiceOption; - stream?: boolean; messages?: Array; } & GraphAILLMInputBase; +type GroqConfig = { + apiKey?: string; + stream?: boolean; + forWeb?: boolean; +}; + +type GroqParams = GroqInputs & GroqConfig & { model: string }; + // // This agent takes two optional inputs, and following parameters. // inputs: @@ -75,9 +80,16 @@ const convertOpenAIChatCompletion = (response: ChatCompletion, messages: ChatCom }; }; -export const groqAgent: AgentFunction = async ({ params, namedInputs, filterParams }) => { - assert(groq !== undefined, "The GROQ_API_KEY environment variable is missing."); - const { verbose, system, tools, tool_choice, max_tokens, temperature, stream, prompt, messages } = { ...params, ...namedInputs }; +export const groqAgent: AgentFunction = async ({ params, namedInputs, filterParams, config }) => { + const { verbose, system, tools, tool_choice, max_tokens, temperature, prompt, messages } = { ...params, ...namedInputs }; + + const { apiKey, stream, forWeb } = { + ...params, + ...(config || {}), + }; + const key = apiKey ?? (process !== undefined ? process.env.GROQ_API_KEY : undefined); + assert(key !== undefined, "The GROQ_API_KEY environment variable adn apiKey is missing."); + const groq = new Groq({ apiKey, dangerouslyAllowBrowser: !!forWeb }); const userPrompt = getMergeValue(namedInputs, params, "mergeablePrompts", prompt); const systemPrompt = getMergeValue(namedInputs, params, "mergeableSystem", system);