Quardo commited on
Commit
5974345
1 Parent(s): 899e654

Updated space

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -21,11 +21,11 @@ import os
21
  # --- === CONFIG === ---
22
 
23
  ENV_HANDLE = "env"#or "url on env"
24
- IMAGE_HANDLE = "url"# or "base64"
25
  API_BASE = "env"# or "openai"
26
  api_key = os.environ['OPENAI_API_KEY']
27
  base_url = os.environ.get('OPENAI_BASE_URL', "https://api.openai.com/v1")
28
- def_models = '["gpt-4", "gpt-4-0125-preview", "gpt-4-0314", "gpt-4-0613", "gpt-4-1106-preview", "gpt-4-1106-vision-preview", "gpt-4-32k-0314", "gpt-4-turbo", "gpt-4-turbo-2024-04-09", "gpt-4-turbo-preview", "gpt-4-vision-preview", "gpt-4o", "gpt-4o-2024-05-13", "gpt-4o-mini", "gpt-4o-mini-2024-07-18"]'
29
  fakeToolPrompt = """[System: You have ability to generate images, via tools provided to you by system.
30
  To call a tool you need to write a json in a empty line; like writing it at the end of message.
31
  To generate a image; you need to follow this example JSON:
@@ -379,7 +379,7 @@ def handleMultimodalData(model, role, data):
379
  pass
380
  elif isinstance(data, str):
381
  return {"role": role, "content": data}
382
- elif hasattr(data, 'files') and data.files and len(data.files) > 0 and model in {"gpt-4-1106-vision-preview", "gpt-4-vision-preview", "gpt-4-turbo", "gpt-4o", "gpt-4o-2024-05-13", "gpt-4o-mini", "gpt-4o-mini-2024-07-18"}:
383
  result, handler, hasFoundFile = [], ["[System: This message contains files; the system will be splitting it.]"], False
384
  for file in data.files:
385
  if file.mime_type.startswith("image/"):
@@ -401,7 +401,7 @@ def handleMultimodalData(model, role, data):
401
  return {"role": role, "content": [{"type": "text", "text": "\n\n".join(handler)}] + result}
402
  else:
403
  return {"role": role, "content": [{"type": "text", "text": data.text}] + result}
404
- elif hasattr(data, 'files') and data.files and len(data.files) > 0 and not (model in {"gpt-4-1106-vision-preview", "gpt-4-vision-preview", "gpt-4-turbo", "gpt-4o", "gpt-4o-2024-05-13", "gpt-4o-mini", "gpt-4o-mini-2024-07-18"}):
405
  handler, hasFoundFile = ["[System: This message contains files; the system will be splitting it.]"], False
406
  for file in data.files:
407
  if file.mime_type.startswith("text/") or file.mime_type.startswith("application/"):
 
21
  # --- === CONFIG === ---
22
 
23
  ENV_HANDLE = "env"#or "url on env"
24
+ IMAGE_HANDLE = "base64"# or "url"
25
  API_BASE = "env"# or "openai"
26
  api_key = os.environ['OPENAI_API_KEY']
27
  base_url = os.environ.get('OPENAI_BASE_URL', "https://api.openai.com/v1")
28
+ def_models = '["gpt-4", "gpt-4-0125-preview", "gpt-4-0314", "gpt-4-0613", "gpt-4-1106-preview", "gpt-4-1106-vision-preview", "gpt-4-32k-0314", "gpt-4-turbo", "gpt-4-turbo-2024-04-09", "gpt-4-turbo-preview", "gpt-4-vision-preview", "chatgpt-4o-latest", "gpt-4o", "gpt-4o-2024-05-13", "gpt-4o-2024-08-06", "gpt-4o-mini", "gpt-4o-mini-2024-07-18"]'
29
  fakeToolPrompt = """[System: You have ability to generate images, via tools provided to you by system.
30
  To call a tool you need to write a json in a empty line; like writing it at the end of message.
31
  To generate a image; you need to follow this example JSON:
 
379
  pass
380
  elif isinstance(data, str):
381
  return {"role": role, "content": data}
382
+ elif hasattr(data, 'files') and data.files and len(data.files) > 0 and model in {"gpt-4-1106-vision-preview", "gpt-4-vision-preview", "gpt-4-turbo", "chatgpt-4o-latest", "gpt-4o", "gpt-4o-2024-05-13", "gpt-4o-2024-08-06", "gpt-4o-mini", "gpt-4o-mini-2024-07-18"}:
383
  result, handler, hasFoundFile = [], ["[System: This message contains files; the system will be splitting it.]"], False
384
  for file in data.files:
385
  if file.mime_type.startswith("image/"):
 
401
  return {"role": role, "content": [{"type": "text", "text": "\n\n".join(handler)}] + result}
402
  else:
403
  return {"role": role, "content": [{"type": "text", "text": data.text}] + result}
404
+ elif hasattr(data, 'files') and data.files and len(data.files) > 0 and not (model in {"gpt-4-1106-vision-preview", "gpt-4-vision-preview", "gpt-4-turbo", "chatgpt-4o-latest", "gpt-4o", "gpt-4o-2024-05-13", "gpt-4o-2024-08-06", "gpt-4o-mini", "gpt-4o-mini-2024-07-18"}):
405
  handler, hasFoundFile = ["[System: This message contains files; the system will be splitting it.]"], False
406
  for file in data.files:
407
  if file.mime_type.startswith("text/") or file.mime_type.startswith("application/"):