From 5242a048afa1a83e3fb0495cab0a798ab4c99b91 Mon Sep 17 00:00:00 2001 From: Syeed-MD-Talha Date: Tue, 5 Aug 2025 11:14:37 +0600 Subject: [PATCH] docs: Add Groq API integration to models tutorial notebook - Add Groq section with OpenAI-compatible client setup - Include basic usage example and AgentChat integration - Add feature compatibility list and API key setup instructions - Follow existing documentation patterns for external providers --- .../tutorial/models.ipynb | 62 ++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/python/docs/src/user-guide/agentchat-user-guide/tutorial/models.ipynb b/python/docs/src/user-guide/agentchat-user-guide/tutorial/models.ipynb index 0d1bdf26ba80..a54af20b13d1 100644 --- a/python/docs/src/user-guide/agentchat-user-guide/tutorial/models.ipynb +++ b/python/docs/src/user-guide/agentchat-user-guide/tutorial/models.ipynb @@ -576,11 +576,69 @@ "source": [ "Read more about the [Semantic Kernel Adapter](../../../reference/python/autogen_ext.models.semantic_kernel.rst)." ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Groq (experimental)\n", + "\n", + "[Groq](https://groq.com/) provides ultra-fast inference for open-source LLMs through their cloud API. Groq offers an [OpenAI-compatible API](https://console.groq.com/docs/quickstart), so you can use the {py:class}`~autogen_ext.models.openai.OpenAIChatCompletionClient` with Groq's endpoints.\n", + "\n", + "You will need to obtain an [API key](https://console.groq.com/keys) from Groq.\n", + "\n", + "This endpoint supports the following OpenAI client library features:\n", + "* Chat completions\n", + "* Model selection\n", + "* Temperature/sampling\n", + "* Streaming\n", + "* JSON mode\n", + "* Function calling (tools)\n", + "\n", + "**Note**: While some model providers may offer OpenAI-compatible APIs, they may still have minor differences. For example, the `finish_reason` field may be different in the response." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "finish_reason='stop' content='The capital of France is Paris.' usage=RequestUsage(prompt_tokens=17, completion_tokens=8) cached=False logprobs=None thought=None\n" + ] + } + ], + "source": [ + "import os\n", + "from autogen_core.models import UserMessage\n", + "from autogen_ext.models.openai import OpenAIChatCompletionClient\n", + "\n", + "# Create Groq model client\n", + "model_client = OpenAIChatCompletionClient(\n", + " model=\"llama3-8b-8192\", # or other Groq models like \"mixtral-8x7b-32768\"\n", + " base_url=\"https://api.groq.com/openai/v1\",\n", + " # api_key=\"GROQ_API_KEY\", \n", + " model_info={\n", + " \"vision\": False,\n", + " \"function_calling\": True,\n", + " \"json_output\": True,\n", + " \"family\": \"unknown\",\n", + " \"structured_output\": True,\n", + " },\n", + ")\n", + "\n", + "response = await model_client.create([UserMessage(content=\"What is the capital of France?\", source=\"user\")])\n", + "print(response)\n", + "await model_client.close()" + ] } ], "metadata": { "kernelspec": { - "display_name": ".venv", + "display_name": "autogen", "language": "python", "name": "python3" }, @@ -594,7 +652,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.10.0" } }, "nbformat": 4,