Skip to content

Instantly share code, notes, and snippets.

@AlexanderHolmeset
Created July 20, 2023 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexanderHolmeset/2c664fb7b9de11c2d6181825233176e6 to your computer and use it in GitHub Desktop.
Save AlexanderHolmeset/2c664fb7b9de11c2d6181825233176e6 to your computer and use it in GitHub Desktop.
$Question = "How many sick days do i have?"
$AzureOpenAIEndpointURL = "https://sharepointdocumentschat.openai.azure.com/"
$AzureOpenAIEndpointKey = "7256974864a9499499ca4d3e70fa0c7b"
$AzureOpenAIModelDelpoymentName = "ChatGPT4"
$AzureCognitiveSearchURL = "https://sharepointsearchinstance.search.windows.net"
$AzureCognitiveSearchAdminKey = "Wt1mZ0sjkKoXW913d2eJ8xXYJk4JHThk1UK8H0wZoIAzSeDjYTmC"
$Header = @{"api-key" = "$AzureOpenAIEndpointKey"
"ChatGpt_Key" = "$AzureOpenAIEndpointKey "
"ChatGpt_Url" = "$AzureOpenAIEndpointURL"
"content-type" = "application/json"
}
$Body = @"
{
"dataSources": [
{
"type": "AzureCognitiveSearch",
"parameters": {
"endpoint": "$azurecognitivesearchurl",
"key": "$AzureCognitiveSearchAdminKey",
"indexName": "sharepoint-index"
}
}
],
"messages": [
{
"role": "user",
"content": "$Question"
}
]
}
"@
$uri = $AzureOpenAIEndpointURL + "openai/deployments/" + $AzureOpenAIModelDelpoymentName + "/extensions/chat/completions?api-version=2023-06-01-preview"
$meassage = invoke-restmethod -Method POST -Uri $uri -Body $body -Headers $Header
"Question: $Question"
"Answer: $($meassage.CHoices.messages[1].content)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment