Created
December 7, 2024 08:59
-
-
Save vman/910d3cfafb8b4224e86f43e0ec62da82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static async Task<ClientResult<ChatCompletion>> CallOpenAIAPI(string userQuestion, string modelDeploymentName, AzureOpenAIClient azureOpenAIClient, IList<OpenAI.Chat.ChatMessage> functionMessages = null) | |
{ | |
var chatCompletionOptions = new ChatCompletionOptions(); | |
var messages = new List<OpenAI.Chat.ChatMessage> | |
{ | |
new SystemChatMessage("You are a search assistant that helps find information. Only use the functions and parameters you have been provided with."), | |
new UserChatMessage(userQuestion) | |
}; | |
if (functionMessages != null) | |
{ | |
foreach (var functionMessage in functionMessages) | |
{ | |
messages.Add(functionMessage); | |
} | |
} | |
chatCompletionOptions.Tools.Add(ChatTool.CreateFunctionTool( | |
functionName: "search_microsoft365_documents", | |
functionDescription: "Search the Microsfot 365 documents from user's SharePoint and OneDrive.", | |
functionParameters: BinaryData.FromString("{\"type\": \"object\",\"required\": [\"searchQuery\"],\"properties\": {\"searchQuery\": {\"type\": \"string\",\"description\": \"the text to search in the documents to get the required information\"}}}") | |
)); | |
var chatCompletionResponse = await azureOpenAIClient.GetChatClient(modelDeploymentName).CompleteChatAsync(messages, chatCompletionOptions); | |
return chatCompletionResponse; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment