AchyuthGamer commited on
Commit
2f4bdc8
1 Parent(s): 7aed88e

Create AiService.py

Browse files
Files changed (1) hide show
  1. g4f/Provider/Providers/AiService.py +40 -0
g4f/Provider/Providers/AiService.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+ from ...typing import get_type_hints
4
+
5
+ url = "https://aiservice.vercel.app/api/chat/answer"
6
+ model = ['gpt-3.5-turbo']
7
+ supports_stream = False
8
+ needs_auth = False
9
+
10
+
11
+ def _create_completion(model: str, messages: list, stream: bool, **kwargs):
12
+ base = ''
13
+ for message in messages:
14
+ base += '%s: %s\n' % (message['role'], message['content'])
15
+ base += 'assistant:'
16
+
17
+ headers = {
18
+ "accept": "*/*",
19
+ "content-type": "text/plain;charset=UTF-8",
20
+ "sec-fetch-dest": "empty",
21
+ "sec-fetch-mode": "cors",
22
+ "sec-fetch-site": "same-origin",
23
+ "Referer": "https://aiservice.vercel.app/chat",
24
+ }
25
+ data = {
26
+ "input": base
27
+ }
28
+ response = requests.post(url, headers=headers, json=data)
29
+ if response.status_code == 200:
30
+ _json = response.json()
31
+ yield _json['data']
32
+ else:
33
+ print(f"Error Occurred::{response.status_code}")
34
+ return None
35
+
36
+
37
+
38
+ params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
39
+ '(%s)' % ', '.join(
40
+ [f"{name}: {get_type_hints(_create_completion)[name].__name__}" for name in _create_completion.__code__.co_varnames[:_create_completion.__code__.co_argcount]])