Niansuh commited on
Commit
f215350
·
verified ·
1 Parent(s): 42eb0f4

Update api/utils.py

Browse files
Files changed (1) hide show
  1. api/utils.py +14 -12
api/utils.py CHANGED
@@ -7,7 +7,7 @@ import uuid
7
  import httpx
8
  from api import validate
9
  from api.config import MODEL_MAPPING, headers, AGENT_MODE, TRENDING_AGENT_MODE
10
- from fastapi import Depends
11
  from fastapi.security import HTTPAuthorizationCredentials
12
 
13
  from api.config import APP_SECRET, BASE_URL
@@ -41,24 +41,26 @@ def verify_app_secret(credentials: HTTPAuthorizationCredentials = Depends(securi
41
  return credentials.credentials
42
 
43
  def message_to_dict(message):
44
- """
45
- Convert a Message object to a dictionary.
46
- Mask the content to prevent logging sensitive information.
47
- """
48
  if isinstance(message.content, str):
49
- masked_content = "[HIDDEN]"
50
  elif isinstance(message.content, list) and len(message.content) == 2:
51
- masked_content = "[HIDDEN]"
 
 
 
 
 
 
 
 
52
  else:
53
- masked_content = "[HIDDEN]"
54
-
55
- return {"role": message.role, "content": masked_content}
56
 
57
  async def process_streaming_response(request: ChatRequest):
58
  agent_mode = AGENT_MODE.get(request.model, {})
59
  trending_agent_mode = TRENDING_AGENT_MODE.get(request.model, {})
60
 
61
- # Log only non-sensitive information
62
  logger.info(
63
  f"Streaming request for model: '{request.model}', "
64
  f"agent mode: {agent_mode}, trending agent mode: {trending_agent_mode}"
@@ -124,7 +126,7 @@ async def process_non_streaming_response(request: ChatRequest):
124
  agent_mode = AGENT_MODE.get(request.model, {})
125
  trending_agent_mode = TRENDING_AGENT_MODE.get(request.model, {})
126
 
127
- # Log only non-sensitive information
128
  logger.info(
129
  f"Non-streaming request for model: '{request.model}', "
130
  f"agent mode: {agent_mode}, trending agent mode: {trending_agent_mode}"
 
7
  import httpx
8
  from api import validate
9
  from api.config import MODEL_MAPPING, headers, AGENT_MODE, TRENDING_AGENT_MODE
10
+ from fastapi import Depends, security
11
  from fastapi.security import HTTPAuthorizationCredentials
12
 
13
  from api.config import APP_SECRET, BASE_URL
 
41
  return credentials.credentials
42
 
43
  def message_to_dict(message):
 
 
 
 
44
  if isinstance(message.content, str):
45
+ return {"role": message.role, "content": message.content}
46
  elif isinstance(message.content, list) and len(message.content) == 2:
47
+ return {
48
+ "role": message.role,
49
+ "content": message.content[0]["text"],
50
+ "data": {
51
+ "imageBase64": message.content[1]["image_url"]["url"],
52
+ "fileText": "",
53
+ "title": "snapshot",
54
+ },
55
+ }
56
  else:
57
+ return {"role": message.role, "content": message.content}
 
 
58
 
59
  async def process_streaming_response(request: ChatRequest):
60
  agent_mode = AGENT_MODE.get(request.model, {})
61
  trending_agent_mode = TRENDING_AGENT_MODE.get(request.model, {})
62
 
63
+ # Log reduced information
64
  logger.info(
65
  f"Streaming request for model: '{request.model}', "
66
  f"agent mode: {agent_mode}, trending agent mode: {trending_agent_mode}"
 
126
  agent_mode = AGENT_MODE.get(request.model, {})
127
  trending_agent_mode = TRENDING_AGENT_MODE.get(request.model, {})
128
 
129
+ # Log reduced information
130
  logger.info(
131
  f"Non-streaming request for model: '{request.model}', "
132
  f"agent mode: {agent_mode}, trending agent mode: {trending_agent_mode}"