Niansuh commited on
Commit
100ede1
·
verified ·
1 Parent(s): db66062

Update api/utils.py

Browse files
Files changed (1) hide show
  1. api/utils.py +12 -8
api/utils.py CHANGED
@@ -45,10 +45,8 @@ def create_chat_completion_data(
45
  }
46
 
47
  # Function to convert message to dictionary format for API
48
- def message_to_dict(message, model_prefix: Optional[str] = None) -> Dict[str, Any]:
49
  content = message.content if isinstance(message.content, str) else message.content[0]["text"]
50
- if model_prefix:
51
- content = f"{model_prefix} {content}"
52
  if isinstance(message.content, list) and len(message.content) == 2 and "image_url" in message.content[1]:
53
  return {
54
  "role": message.role,
@@ -61,11 +59,17 @@ def message_to_dict(message, model_prefix: Optional[str] = None) -> Dict[str, An
61
  }
62
  return {"role": message.role, "content": content}
63
 
64
- # Function to get agent modes for specific models
65
  def get_agent_modes(model: str) -> Dict[str, Any]:
 
 
 
 
 
 
66
  return {
67
- "agentMode": AGENT_MODE.get(model, {}),
68
- "trendingAgentMode": TRENDING_AGENT_MODE.get(model, {}),
69
  }
70
 
71
  # Process streaming response with headers from config.py
@@ -101,7 +105,7 @@ async def process_streaming_response(request: ChatRequest):
101
  "visitFromDelta": False,
102
  }
103
 
104
- logger.debug(f"Data Payload: {json_data}") # Debugging line to inspect payload
105
  async with httpx.AsyncClient() as client:
106
  try:
107
  async with client.stream(
@@ -158,7 +162,7 @@ async def process_non_streaming_response(request: ChatRequest):
158
  "visitFromDelta": False,
159
  }
160
 
161
- logger.debug(f"Data Payload: {json_data}") # Debugging line to inspect payload
162
  full_response = ""
163
  async with httpx.AsyncClient() as client:
164
  try:
 
45
  }
46
 
47
  # Function to convert message to dictionary format for API
48
+ def message_to_dict(message) -> Dict[str, Any]:
49
  content = message.content if isinstance(message.content, str) else message.content[0]["text"]
 
 
50
  if isinstance(message.content, list) and len(message.content) == 2 and "image_url" in message.content[1]:
51
  return {
52
  "role": message.role,
 
59
  }
60
  return {"role": message.role, "content": content}
61
 
62
+ # Function to retrieve agent modes for a specific model
63
  def get_agent_modes(model: str) -> Dict[str, Any]:
64
+ agent_mode = AGENT_MODE.get(model, {})
65
+ trending_agent_mode = TRENDING_AGENT_MODE.get(model, {})
66
+
67
+ logger.debug(f"Agent Mode for model '{model}': {agent_mode}")
68
+ logger.debug(f"Trending Agent Mode for model '{model}': {trending_agent_mode}")
69
+
70
  return {
71
+ "agentMode": agent_mode,
72
+ "trendingAgentMode": trending_agent_mode,
73
  }
74
 
75
  # Process streaming response with headers from config.py
 
105
  "visitFromDelta": False,
106
  }
107
 
108
+ logger.debug(f"Data Payload: {json_data}") # Inspect payload for accuracy
109
  async with httpx.AsyncClient() as client:
110
  try:
111
  async with client.stream(
 
162
  "visitFromDelta": False,
163
  }
164
 
165
+ logger.debug(f"Data Payload: {json_data}") # Inspect payload for accuracy
166
  full_response = ""
167
  async with httpx.AsyncClient() as client:
168
  try: