Can I use Azure OpenAI On Your Data in Flutter environment?

Tom Chow 115 Reputation points
2024-07-31T07:01:34.04+00:00

I want to integrate Azure OpenAI "On Your Data" into my mobile Flutter environment. I need packages similar to Azure.AI.OpenAI and OpenAI.Chat, but it seems they aren't available for Flutter. Besides calling the API, I need custom configurations for chat agent behavior, temperature, strictness, and the Azure AI Search endpoint. Using C#, I needed to include #pragma warning disable AOAI001 for execution due to it being in preview. Do I need to include it in my flutter environment to work as well?

Is integrating Azure OpenAI "On Your Data" into Flutter feasible? If it can be integrated into other environments beyond Python, C#, Java, and JavaScript, is there a guide available?

I saw the sample code in Azure OpenAI Studio, the possible solution will be using the JSON as it includes the necessary parameters for data sources (Azure AI Search) and authentication, etc. Would that be one of the solution?

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,080 questions
0 comments No comments
{count} votes

Accepted answer
  1. Azar 29,520 Reputation points MVP Volunteer Moderator
    2024-07-31T09:50:45.04+00:00

    Hi there Tom Chow

    Thanks for using QandA platform.

    Thatts an interesting question and I believe yesIntegrating Azure OpenAI "On Your Data" into a Flutter environment is possible, but it needs calling the REST API directly since specific packages like Azure.AI.OpenAI and OpenAI.Chat are not available for Flutter (I guess). You can do this by using Flutter's HTTP package to make API requests and handle responses.

    1. for ex you can use the http package in Flutter to send requests to the Azure OpenAI API. You can configure chat agent through the JSON payload in your requests.
    2. and structure your JSON payload to include parameters for Azure AI Search, data sources, and other configurations. like below
    import 'package:http/http.dart' as http;
    import 'dart:convert';
    Future<void> callAzureOpenAI() async {
      final String endpoint = 'https://<your-openai-endpoint>/openai/deployments/<deployment-id>/chat/completions?api-version=2023-05-15';
      final String apiKey = '<your-api-key>';
      final Map<String, dynamic> requestBody = {
        "messages": [
          {"role": "system", "content": "You are a helpful assistant."},
          {"role": "user", "content": "Tell me a joke."}
        ],
        "max_tokens": 50,
        "temperature": 0.7,
        "top_p": 1.0
      };
      final response = await http.post(
        Uri.parse(endpoint),
        headers: {
          'Content-Type': 'application/json',
          'Authorization': 'Bearer $apiKey',
        },
        body: json.encode(requestBody),
      );
      if (response.statusCode == 200) {
        final Map<String, dynamic> responseData = json.decode(response.body);
        print(responseData['choices'][0]['message']['content']);
      } else {
        print('Request failed with status: ${response.statusCode}.');
      }
    }
    
    

    And I don't think there are any docs on this but have a look at this doc for some additional info

    https://learn.microsoft.com/en-us/azure/ai-services/openai/

    If this helps kindly accept the response thanks much.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.