项目文件夹

文件
wehub-resource-sync a0c8464e58
Build Package / build (ubuntu-latest) (push) Failing after 1s
CodeQL / Analyze (python) (push) Failing after 1s
Core Typecheck / core-typecheck (push) Failing after 1s
Linting / lint (push) Failing after 1s
llama-dev tests / test-llama-dev (push) Failing after 1s
Publish Sub-Package to PyPI if Needed / publish_subpackage_if_needed (push) Has been skipped
Sync Docs to Developer Hub / sync-docs (push) Failing after 0s
Build Package / build (windows-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:26:52 +08:00

75 行
1.5 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Grok 4\n",
"\n",
"Grok from xAI uses an OpenAI-compatible API, so you can use it with the OpenAILike integration class."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install llama-index-llms-openai-like"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"grok_api_key = \"xai-xxxxxxxx\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello World! 🌍 That's the universal greeting for programmers everywhere. What adventure brings you here today? 😊\n"
]
}
],
"source": [
"from llama_index.llms.openai_like import OpenAILike\n",
"\n",
"llm = OpenAILike(\n",
" model=\"grok-4-0709\",\n",
" api_base=\"https://api.x.ai/v1\",\n",
" api_key=grok_api_key,\n",
" context_window=128000,\n",
" is_chat_model=True,\n",
" is_function_calling_model=False,\n",
")\n",
"\n",
"response = llm.complete(\"Hello World!\")\n",
"print(str(response))"
]
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}