monra commited on
Commit
724f683
1 Parent(s): ebe8c94

Fix: context

Browse files
g4f/Provider/Providers/Yqcloud.py CHANGED
@@ -10,7 +10,8 @@ model = [
10
  supports_stream = True
11
  needs_auth = False
12
 
13
- def _create_completion(model: str, messages: list, stream: bool, **kwargs):
 
14
 
15
  headers = {
16
  'authority': 'api.aichatos.cloud',
@@ -20,18 +21,19 @@ def _create_completion(model: str, messages: list, stream: bool, **kwargs):
20
  }
21
 
22
  json_data = {
23
- 'prompt': 'always respond in english | %s' % messages[-1]['content'],
24
- 'userId': f'#/chat/{int(time.time() * 1000)}',
25
  'network': True,
26
  'apikey': '',
27
  'system': '',
28
  'withoutContext': False,
29
  }
30
-
31
- response = requests.post('https://api.aichatos.cloud/api/generateStream', headers=headers, json=json_data, stream=True)
32
  for token in response.iter_content(chunk_size=2046):
33
- if not b'always respond in english' in token:
34
- yield (token.decode('utf-8'))
35
 
36
  params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
37
- '(%s)' % ', '.join([f"{name}: {get_type_hints(_create_completion)[name].__name__}" for name in _create_completion.__code__.co_varnames[:_create_completion.__code__.co_argcount]])
 
 
10
  supports_stream = True
11
  needs_auth = False
12
 
13
+
14
+ def _create_completion(model: str, messages: list, stream: bool, chatId: str, **kwargs):
15
 
16
  headers = {
17
  'authority': 'api.aichatos.cloud',
 
21
  }
22
 
23
  json_data = {
24
+ 'prompt': messages[-1]['content'],
25
+ 'userId': f'#/chat/{chatId}',
26
  'network': True,
27
  'apikey': '',
28
  'system': '',
29
  'withoutContext': False,
30
  }
31
+ response = requests.post('https://api.aichatos.cloud/api/generateStream',
32
+ headers=headers, json=json_data, stream=True)
33
  for token in response.iter_content(chunk_size=2046):
34
+ yield (token.decode('utf-8'))
35
+
36
 
37
  params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
38
+ '(%s)' % ', '.join(
39
+ [f"{name}: {get_type_hints(_create_completion)[name].__name__}" for name in _create_completion.__code__.co_varnames[:_create_completion.__code__.co_argcount]])
server/backend.py CHANGED
@@ -40,7 +40,8 @@ class Backend_Api:
40
  """
41
  max_retries = 3
42
  retries = 0
43
-
 
44
  while retries < max_retries:
45
  try:
46
  jailbreak = request.json['jailbreak']
@@ -48,8 +49,8 @@ class Backend_Api:
48
  messages = build_messages(jailbreak)
49
 
50
  # Generate response
51
- response = ChatCompletion.create(model=model, stream=True,
52
- messages=messages, provider=g4f.Provider.Forefront)
53
 
54
  return self.app.response_class(generate_stream(response, jailbreak), mimetype='text/event-stream')
55
 
 
40
  """
41
  max_retries = 3
42
  retries = 0
43
+ conversation_id = request.json['conversation_id']
44
+
45
  while retries < max_retries:
46
  try:
47
  jailbreak = request.json['jailbreak']
 
49
  messages = build_messages(jailbreak)
50
 
51
  # Generate response
52
+ response = ChatCompletion.create(model=model, stream=True, chatId=conversation_id,
53
+ messages=messages, provider=g4f.Provider.Yqcloud)
54
 
55
  return self.app.response_class(generate_stream(response, jailbreak), mimetype='text/event-stream')
56