This file contains hidden or 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
    
  
  
    
  | /// Gets a "weather forecast" from the OpenAI completions endpoint | |
| static Future<CompletionsResponse> getNewForecast() async { | |
| debugPrint('Getting a new weather forecast'); | |
| CompletionsRequest request = CompletionsRequest( | |
| model: 'text-curie-001', | |
| prompt: 'Today's forecast is', | |
| maxTokens: 9, | |
| temperature: 0.6, | |
| ); | 
  
    
      This file contains hidden or 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
    
  
  
    
  | // The headers for the completions endpoint, which are the same for all requests | |
| static final Map<String, String> headers = { | |
| 'Content-Type': 'application/json', | |
| 'Authorization': 'Bearer $openAIApiKey', | |
| }; | 
  
    
      This file contains hidden or 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
    
  
  
    
  | // The completions endpoint | |
| static final Uri completionsEndpoint = Uri.parse('https://api.openai.com/v1/completions'); | 
  
    
      This file contains hidden or 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
    
  
  
    
  | /// Returns a [CompletionResponse] from the JSON obtained from the | |
| /// completions endpoint. | |
| factory CompletionsResponse.fromResponse(Response response) { | |
| // Get the response body in JSON format | |
| Map<String, dynamic> responseBody = json.decode(response.body); | |
| // Parse out information from the response | |
| Map<String, dynamic> usage = responseBody['usage']; | |
| // Parse out the choices | 
  
    
      This file contains hidden or 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
    
  
  
    
  | class CompletionsResponse { | |
| final String? id; | |
| final String object; | |
| final int? created; | |
| final String? model; | |
| final List<dynamic>? choices; // This list contains the completions | |
| final Map<String, dynamic>? usage; | |
| final int? promptTokens; | |
| final int? completionTokens; | |
| final int? totalTokens; | 
  
    
      This file contains hidden or 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
    
  
  
    
  | String toJson() { | |
| Map<String, dynamic> jsonBody = { | |
| 'model': model, | |
| 'prompt': prompt, | |
| 'max_tokens': maxTokens, | |
| }; | |
| if (temperature != null) { | |
| jsonBody.addAll({'temperature': temperature}); | |
| } | 
  
    
      This file contains hidden or 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
    
  
  
    
  | /// Represents the parameters used in the body of a request to the OpenAI completions endpoint. | |
| class CompletionsRequest { | |
| final String model; | |
| final String prompt; | |
| final int maxTokens; | |
| final double? temperature; | |
| final int? topP; | |
| final int? n; | |
| final bool? stream; | |
| final int? longprobs; | 
  
    
      This file contains hidden or 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
    
  
  
    
  | /// View for [DailyForecastRoute] for watch-sized devices while the watch | |
| /// is in an active mode. | |
| class DailyForecastViewWatchActive extends StatelessWidget { | |
| final DailyForecastController state; | |
| const DailyForecastViewWatchActive(this.state, {Key? key}) : super(key: key); | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | 
  
    
      This file contains hidden or 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
    
  
  
    
  | /// View for [DailyForecastRoute] for watch-sized devices while the watch | |
| /// is in an ambient mode. | |
| class DailyForecastViewWatchAmbient extends StatelessWidget { | |
| final DailyForecastController state; | |
| const DailyForecastViewWatchAmbient(this.state, {Key? key}) : super(key: key); | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | 
  
    
      This file contains hidden or 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
    
  
  
    
  | AmbientMode( | |
| builder: (BuildContext context, WearMode mode, child) { | |
| return mode == WearMode.active | |
| ? DailyForecastViewWatchActive(state) | |
| : DailyForecastViewWatchAmbient(state); | |
| }, | |
| ); |