Skip to content

Commit

Permalink
Merge pull request #866 from isamu/groq_agent_config
Browse files Browse the repository at this point in the history
Groq agent config
  • Loading branch information
isamu authored Dec 30, 2024
2 parents 56f25e0 + e434794 commit e02347f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion agents/llm_agents/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 8 additions & 3 deletions llm_agents/groq_agent/lib/groq_agent.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ type GroqInputs = {
temperature?: number;
max_tokens?: number;
tool_choice?: ChatCompletionToolChoiceOption;
stream?: boolean;
messages?: Array<ChatCompletionMessageParam>;
} & GraphAILLMInputBase;
export declare const groqAgent: AgentFunction<GroqInputs & {
type GroqConfig = {
apiKey?: string;
stream?: boolean;
forWeb?: boolean;
};
type GroqParams = GroqInputs & GroqConfig & {
model: string;
}, any, GroqInputs>;
};
export declare const groqAgent: AgentFunction<GroqParams, any, GroqInputs, GroqConfig>;
declare const groqAgentInfo: AgentFunctionInfo;
export default groqAgentInfo;
13 changes: 9 additions & 4 deletions llm_agents/groq_agent/lib/groq_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion llm_agents/groq_agent/package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
24 changes: 18 additions & 6 deletions llm_agents/groq_agent/src/groq_agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChatCompletionMessageParam>;
} & 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:
Expand Down Expand Up @@ -75,9 +80,16 @@ const convertOpenAIChatCompletion = (response: ChatCompletion, messages: ChatCom
};
};

export const groqAgent: AgentFunction<GroqInputs & { model: string }, any, GroqInputs> = 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<GroqParams, any, GroqInputs, GroqConfig> = 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);
Expand Down

0 comments on commit e02347f

Please sign in to comment.