Skip to content

docs: Add Groq API integration to models tutorial notebook #6893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -594,7 +652,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.10.0"
}
},
"nbformat": 4,
Expand Down