Skip to content
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

docs[patch]: Adds docs on passing custom headers to OpenAI + Azure OpenAI models #6446

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
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
42 changes: 42 additions & 0 deletions docs/core_docs/docs/integrations/chat/azure.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,48 @@
"});\n"
]
},
{
"cell_type": "markdown",
"id": "092e7a38",
"metadata": {},
"source": [
"## Custom headers\n",
"\n",
"You can specify custom headers by passing in a `configuration` field:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "43503a94",
"metadata": {},
"outputs": [],
"source": [
"import { AzureChatOpenAI } from \"@langchain/openai\";\n",
"\n",
"const llmWithCustomHeaders = new AzureChatOpenAI({\n",
" azureOpenAIApiKey: process.env.AZURE_OPENAI_API_KEY, // In Node.js defaults to process.env.AZURE_OPENAI_API_KEY\n",
" azureOpenAIApiInstanceName: process.env.AZURE_OPENAI_API_INSTANCE_NAME, // In Node.js defaults to process.env.AZURE_OPENAI_API_INSTANCE_NAME\n",
" azureOpenAIApiDeploymentName: process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME, // In Node.js defaults to process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME\n",
" azureOpenAIApiVersion: process.env.AZURE_OPENAI_API_VERSION, // In Node.js defaults to process.env.AZURE_OPENAI_API_VERSION\n",
" configuration: {\n",
" defaultHeaders: {\n",
" \"x-custom-header\": `SOME_VALUE`,\n",
" },\n",
" },\n",
"});\n",
"\n",
"await llmWithCustomHeaders.invoke(\"Hi there!\");"
]
},
{
"cell_type": "markdown",
"id": "1a6b849d",
"metadata": {},
"source": [
"The `configuration` field also accepts other `ClientOptions` parameters accepted by the official SDK."
]
},
{
"cell_type": "markdown",
"id": "0ac0310c",
Expand Down
37 changes: 34 additions & 3 deletions docs/core_docs/docs/integrations/chat/openai.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,44 @@
},
{
"cell_type": "markdown",
"id": "013b6300",
"id": "20b60ccb",
"metadata": {},
"source": [
"You can also pass other `ClientOptions` parameters accepted by the official SDK here.\n",
"The `configuration` field also accepts other `ClientOptions` parameters accepted by the official SDK.\n",
"\n",
"If you are hosting on Azure OpenAI, see the [dedicated page instead](/docs/integrations/chat/azure).\n",
"\n",
"## Custom headers\n",
"\n",
"You can specify custom headers in the same `configuration` field:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cd612609",
"metadata": {},
"outputs": [],
"source": [
"import { ChatOpenAI } from \"@langchain/openai\";\n",
"\n",
"const llmWithCustomHeaders = new ChatOpenAI({\n",
" temperature: 0.9,\n",
" configuration: {\n",
" defaultHeaders: {\n",
" \"Authorization\": `Bearer SOME_CUSTOM_VALUE`,\n",
" },\n",
" },\n",
"});\n",
"\n",
"await llmWithCustomHeaders.invoke(\"Hi there!\");"
]
},
{
"cell_type": "markdown",
"id": "013b6300",
"metadata": {},
"source": [
"## Calling fine-tuned models\n",
"\n",
"You can call fine-tuned OpenAI models by passing in your corresponding `modelName` parameter.\n",
Expand Down Expand Up @@ -411,7 +442,7 @@
},
{
"cell_type": "markdown",
"id": "bc5ecebd",
"id": "3a5bb5ca-c3ae-4a58-be67-2cd18574b9a3",
"metadata": {},
"source": [
"## Tool calling\n",
Expand Down
Loading