#can i see the code

1 messages · Page 1 of 1 (latest)

silk latch
#

Sure

#
Future<Map<String, dynamic>> sendRequest(message) async {
    String content = '';
    int tokens = 0;
    final Map<String, dynamic> payload = {
      "model": "gpt-3.5-turbo",
      "messages": [
        {"role": "user", "content": message}
      ],
      "temperature": 0.7
    };

    final options = Options(
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ${apiConfig.apiKey}',
      },
    );

    final url = "${apiConfig.apiUrl}/chat/completions";
    debugPrint(url);

    try {
      final response = await dio.post(
        url,
        data: jsonEncode(payload),
        options: options,
      );

      if (response.statusCode == 200) {
        content = response.data['choices'][0]['message']['content'];
        tokens = response.data['usage']['total_tokens'];
      }
    } on DioError catch (e) {
      if (e.response?.statusCode == 404) {
        content = 'No se puede encontrar el servidor de AI';
      }
      if (e.response?.statusCode == 401) {
        content = 'Tienes problemas con tu API Key, puede no ser el correcto';
      }
    }

    return {
      'content': content.toString(),
      'tokens': tokens,
    };
  }
#

so i should send the prompt in every message i send it

#

yeah.... a lot of tokens xD

#

yeah yeah, im just finishing my app to make calls to the gpt, but using some personalities in it

#

soon in google play if u are interested uwu