Flutter calls chatgpt interface configuration

Since chatgpt is officially https, we need our server to also support https:

	server {
    
      
        listen 443 ssl;
        server_name xxx.com;  
		
        ssl_certificate C:\\proxy\\cert\\xxx.crt;  
        ssl_certificate_key C:\\proxy\\cert\\xxx.key;  
        ssl_session_cache shared:SSL:1m;  
        ssl_session_timeout 5m;  
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
		
		proxy_ssl_server_name on;
	
	
        location /v1/ {
    
    
            proxy_pass https://api.openai.com/v1/;
        }
    }

Of course, you need to have a foreign server, otherwise your server will not be able to access openai. I suggest that you buy a server with bidding instances, which is cheaper.

On the Flutter side you can write an interface like this:

  Future chatGPT(String prompt) async {
    // https://api.openai.com/v1/completions
    var dio = Dio(BaseOptions(
        baseUrl: 'https://chat.dong.cool',
        connectTimeout: 5000,
        receiveTimeout: 60000,
        headers: {
          HttpHeaders.authorizationHeader:
              'Bearer sk-LfVpMpJzn8BpPUbjDnvAT3BlbkFJG08LPxf9euMv2ImA',
          HttpHeaders.contentTypeHeader: 'application/json'
        }));

    return await dio.post('/v1/completions', data: {
      "prompt": prompt,
      "temperature": 0.7,
      "top_p": 1,
      "model": "text-davinci-003",
      "max_tokens": 2048,
      "frequency_penalty": 0,
      "presence_penalty": 0.6,
      "stop": ["Human:", "AI:"]
    });
  }

Guess you like

Origin blog.csdn.net/weixin_29003023/article/details/131315662