|
1 | 1 | # Groq
|
2 | 2 |
|
3 |
| -The [Groq API](https://wow.groq.com) supports the OpenAI format, which makes it easy to integrate with promptfoo as a variation of the `openai` provider. |
| 3 | +The [Groq API](https://wow.groq.com) is integrated into promptfoo using the Groq SDK, providing a native experience for using Groq models in your evaluations. Groq offers high-performance inference for various large language models. |
4 | 4 |
|
5 |
| -## Prerequisites |
| 5 | +## Setup |
6 | 6 |
|
7 |
| -Before you begin, make sure you have a Groq API key. You can obtain one from the [Groq Console](https://console.groq.com/) and set it as the `GROQ_API_KEY` environment variable. |
| 7 | +To use Groq, you need to set up your API key: |
8 | 8 |
|
9 |
| -## Configuration |
10 |
| - |
11 |
| -To use the Groq API with Promptfoo, you need to configure the provider in your promptfoo configuration file. |
| 9 | +1. Create a Groq API key in the [Groq Console](https://console.groq.com/). |
| 10 | +2. Set the `GROQ_API_KEY` environment variable: |
12 | 11 |
|
13 |
| -Here's an example configuration: |
14 |
| - |
15 |
| -```yaml |
16 |
| -providers: |
17 |
| - - id: openai:chat:mixtral-8x7b-32768 |
18 |
| - config: |
19 |
| - apiBaseUrl: https://api.groq.com/openai/v1 |
20 |
| - apiKeyEnvar: GROQ_API_KEY |
21 |
| - - id: openai:chat:llama2-70b-4096 |
22 |
| - config: |
23 |
| - apiBaseUrl: https://api.groq.com/openai/v1 |
24 |
| - apiKeyEnvar: GROQ_API_KEY |
| 12 | +```sh |
| 13 | +export GROQ_API_KEY=your_api_key_here |
25 | 14 | ```
|
26 | 15 |
|
27 |
| -In this configuration: |
| 16 | +Alternatively, you can specify the `apiKey` in the provider configuration (see below). |
28 | 17 |
|
29 |
| -- `id` specifies the provider ID in the format `openai:chat:<model>`. Replace `<model>` with the desired Groq model. |
30 |
| -- `config.apiBaseUrl` points it to the Groq API. |
31 |
| -- `config.apiKeyEnvar` specifies the environment variable that holds your Groq API key. |
| 18 | +## Configuration |
32 | 19 |
|
33 |
| -You can also directly specify the API key in the configuration using the `apiKey` field instead of `apiKeyEnvar`: |
| 20 | +Configure the Groq provider in your promptfoo configuration file: |
34 | 21 |
|
35 | 22 | ```yaml
|
36 | 23 | providers:
|
37 |
| - - id: openai:chat:mixtral-8x7b-32768 |
| 24 | + - id: groq:llama3-groq-70b-8192-tool-use-preview |
38 | 25 | config:
|
39 |
| - apiBaseUrl: https://api.groq.com/openai/v1 |
40 |
| - apiKey: gsk_abc123_your_groq_api_key |
| 26 | + temperature: 0.7 |
| 27 | + max_tokens: 100 |
| 28 | + tools: |
| 29 | + - type: function |
| 30 | + function: |
| 31 | + name: get_weather |
| 32 | + description: 'Get the current weather in a given location' |
| 33 | + parameters: |
| 34 | + type: object |
| 35 | + properties: |
| 36 | + location: |
| 37 | + type: string |
| 38 | + description: 'The city and state, e.g. San Francisco, CA' |
| 39 | + unit: |
| 40 | + type: string |
| 41 | + enum: [celsius, fahrenheit] |
| 42 | + required: [location] |
| 43 | + tool_choice: auto |
41 | 44 | ```
|
42 | 45 |
|
| 46 | +Key configuration options: |
| 47 | +
|
| 48 | +- `temperature`: Controls randomness in output (0.0 to 1.0) |
| 49 | +- `max_tokens`: Maximum number of tokens in the response |
| 50 | +- `tools`: Defines functions the model can use (for tool use/function calling) |
| 51 | +- `tool_choice`: Specifies how the model should choose tools ('auto', 'none', or a specific tool) |
| 52 | + |
43 | 53 | ## Supported Models
|
44 | 54 |
|
45 |
| -As of the time of writing, the Groq API supports the following models: |
| 55 | +Groq supports a variety of models, including: |
46 | 56 |
|
47 |
| -- `mixtral-8x7b-32768` |
| 57 | +- `gemma-7b-it` |
| 58 | +- `gemma2-9b-it` |
| 59 | +- `llama-3.1-405b-reasoning` |
| 60 | +- `llama-3.1-70b-versatile` |
| 61 | +- `llama-3.1-8b-instant` |
48 | 62 | - `llama2-70b-4096`
|
| 63 | +- `llama3-70b-8192` |
| 64 | +- `llama3-8b-8192` |
| 65 | +- `llama3-groq-70b-8192-tool-use-preview` (recommended for tool use) |
| 66 | +- `llama3-groq-8b-8192-tool-use-preview` (recommended for tool use) |
| 67 | +- `mixtral-8x7b-32768` |
49 | 68 |
|
50 |
| -You can find the latest list of supported models in the [Groq Console documentation](https://console.groq.com/docs/models). |
| 69 | +For the most up-to-date list and detailed information about each model, refer to the [Groq Console documentation](https://console.groq.com/docs/models). |
51 | 70 |
|
52 | 71 | ## Using the Provider
|
53 | 72 |
|
54 |
| -Once you have configured the Groq provider, you can use it in your Promptfoo tests just like any other OpenAI-compatible provider. Specify the provider ID in your test configuration, and Promptfoo will send the requests to the Groq API. |
55 |
| - |
56 |
| -Here's an example test configuration: |
| 73 | +Specify the Groq provider in your test configuration: |
57 | 74 |
|
58 | 75 | ```yaml
|
59 |
| -prompts: |
60 |
| - - 'Answer this as concisely as possible: {{question}}' |
61 |
| -
|
62 | 76 | providers:
|
63 |
| - - id: openai:chat:mixtral-8x7b-32768 |
64 |
| - config: |
65 |
| - apiBaseUrl: https://api.groq.com/openai/v1 |
66 |
| - apiKeyEnvar: GROQ_API_KEY |
67 |
| - - id: openai:chat:llama2-70b-4096 |
| 77 | + - id: groq:llama3-groq-70b-8192-tool-use-preview |
68 | 78 | config:
|
69 |
| - apiBaseUrl: https://api.groq.com/openai/v1 |
70 |
| - apiKeyEnvar: GROQ_API_KEY |
| 79 | + temperature: 0.5 |
| 80 | + max_tokens: 150 |
| 81 | +
|
| 82 | +prompts: |
| 83 | + - Tell me about the weather in {{city}} in the default unit for the location. |
71 | 84 |
|
72 | 85 | tests:
|
73 | 86 | - vars:
|
74 |
| - question: What is the capital of France? |
75 |
| - assert: |
76 |
| - - type: equals |
77 |
| - value: Paris |
| 87 | + city: Boston |
| 88 | + - vars: |
| 89 | + city: New York |
78 | 90 | ```
|
79 | 91 |
|
80 |
| -In this example, the test will be run against both the `mixtral-8x7b-32768` and `llama2-70b-4096` models using the Groq API. |
| 92 | +## Tool Use (Function Calling) |
81 | 93 |
|
82 |
| -## Additional Configuration |
83 |
| - |
84 |
| -The Groq provider supports additional configuration options, such as `temperature`, `max_tokens`, etc. You can specify these options under the `config` field for each provider. |
85 |
| - |
86 |
| -For example: |
| 94 | +Groq supports tool use, allowing models to call predefined functions. Configure tools in your provider settings: |
87 | 95 |
|
88 | 96 | ```yaml
|
89 | 97 | providers:
|
90 |
| - - id: openai:chat:mixtral-8x7b-32768 |
| 98 | + - id: groq:llama3-groq-70b-8192-tool-use-preview |
91 | 99 | config:
|
92 |
| - apiBaseUrl: https://api.groq.com/openai/v1 |
93 |
| - apiKeyEnvar: GROQ_API_KEY |
94 |
| - temperature: 0.7 |
95 |
| - max_tokens: 100 |
| 100 | + tools: |
| 101 | + - type: function |
| 102 | + function: |
| 103 | + name: get_weather |
| 104 | + description: 'Get the current weather in a given location' |
| 105 | + parameters: |
| 106 | + type: object |
| 107 | + properties: |
| 108 | + location: |
| 109 | + type: string |
| 110 | + description: 'The city and state, e.g. San Francisco, CA' |
| 111 | + unit: |
| 112 | + type: string |
| 113 | + enum: [celsius, fahrenheit] |
| 114 | + required: [location] |
| 115 | + tool_choice: auto |
96 | 116 | ```
|
97 | 117 |
|
98 |
| -Refer to the [Groq OpenAI compatibility docs](https://console.groq.com/docs/openai) as well as the [OpenAI documentation](https://platform.openai.com/docs/api-reference/completions/create) for the full list of supported configuration options. |
| 118 | +For complex tools or ambiguous queries, use the `llama3-groq-70b-8192-tool-use-preview` model. |
| 119 | + |
| 120 | +## Additional Capabilities |
| 121 | + |
| 122 | +- **Caching**: Groq provider caches previous LLM requests by default for improved performance. |
| 123 | +- **Token Usage Tracking**: Provides detailed information on token usage for each request. |
| 124 | +- **Cost Calculation**: Automatically calculates the cost of each request based on token usage and the specific model used. |
0 commit comments