Arslan1997 commited on
Commit
2cac7a0
·
1 Parent(s): 5f5c108

added new dspy

Browse files
Files changed (2) hide show
  1. app.py +11 -16
  2. src/schemas/model_settings_schema.py +2 -2
app.py CHANGED
@@ -321,7 +321,7 @@ default_lm = MODEL_OBJECTS[DEFAULT_MODEL_CONFIG['model']]
321
 
322
  # lm = dspy.LM('openai/gpt-4o-mini', api_key=os.getenv("OPENAI_API_KEY"))
323
 
324
- dspy.configure(lm=default_lm, async_max_workers=100)
325
 
326
 
327
 
@@ -345,27 +345,22 @@ def get_session_lm(session_state):
345
 
346
  model_name = model_config.get("model", DEFAULT_MODEL_CONFIG["model"])
347
 
348
- if 'gpt-5' or 'o1' not in model_name:
 
 
 
349
 
350
- MODEL_OBJECTS[model_name].__dict__['kwargs']['max_tokens'] = model_config.get("max_tokens", DEFAULT_MODEL_CONFIG["max_tokens"])
351
-
352
- MODEL_OBJECTS[model_name].__dict__['kwargs']['temperature'] = model_config.get("temperature", DEFAULT_MODEL_CONFIG["temperature"])
353
-
354
- elif 'gpt-5' or 'o1' in model_name and provider =='openai':
355
-
356
- # MODEL_OBJECTS[model_name].__dict__['kwargs']['max_completion_tokens'] = model_config.get("max_tokens", DEFAULT_MODEL_CONFIG["max_tokens"])
357
  if 'gpt-5' in model_name:
358
  MODEL_OBJECTS[model_name].__dict__['kwargs']['max_tokens'] = 16_000
359
  if 'o1' in model_name:
360
  MODEL_OBJECTS[model_name].__dict__['kwargs']['max_tokens'] = 20_000
361
-
362
  MODEL_OBJECTS[model_name].__dict__['kwargs']['temperature'] = 1.0
363
-
364
  else:
365
-
366
  MODEL_OBJECTS[model_name].__dict__['kwargs']['max_tokens'] = model_config.get("max_tokens", DEFAULT_MODEL_CONFIG["max_tokens"])
367
-
368
- MODEL_OBJECTS[model_name].__dict__['kwargs']['temperature'] = model_config.get("temperature", DEFAULT_MODEL_CONFIG["temperature"])
369
 
370
 
371
 
@@ -715,7 +710,7 @@ async def chat_with_agent(
715
 
716
  response = await asyncio.wait_for(
717
 
718
- agent.forward(enhanced_query, ",".join(agent_list)),
719
 
720
  timeout=REQUEST_TIMEOUT_SECONDS
721
 
@@ -765,7 +760,7 @@ async def chat_with_agent(
765
 
766
  response = await asyncio.wait_for(
767
 
768
- agent.forward(enhanced_query, agent_name),
769
 
770
  timeout=REQUEST_TIMEOUT_SECONDS
771
 
 
321
 
322
  # lm = dspy.LM('openai/gpt-4o-mini', api_key=os.getenv("OPENAI_API_KEY"))
323
 
324
+ dspy.configure(lm=default_lm, async_max_workers=1000)
325
 
326
 
327
 
 
345
 
346
  model_name = model_config.get("model", DEFAULT_MODEL_CONFIG["model"])
347
 
348
+ # Get temperature and clamp to valid range for Anthropic (0..1)
349
+ temp = model_config.get("temperature", DEFAULT_MODEL_CONFIG["temperature"])
350
+ if provider == "anthropic":
351
+ temp = min(1.0, max(0.0, float(temp)))
352
 
353
+ # Handle special OpenAI models (gpt-5 and o1 series)
354
+ if ('gpt-5' in model_name or 'o1' in model_name) and provider == 'openai':
 
 
 
 
 
355
  if 'gpt-5' in model_name:
356
  MODEL_OBJECTS[model_name].__dict__['kwargs']['max_tokens'] = 16_000
357
  if 'o1' in model_name:
358
  MODEL_OBJECTS[model_name].__dict__['kwargs']['max_tokens'] = 20_000
 
359
  MODEL_OBJECTS[model_name].__dict__['kwargs']['temperature'] = 1.0
 
360
  else:
361
+ # All other models
362
  MODEL_OBJECTS[model_name].__dict__['kwargs']['max_tokens'] = model_config.get("max_tokens", DEFAULT_MODEL_CONFIG["max_tokens"])
363
+ MODEL_OBJECTS[model_name].__dict__['kwargs']['temperature'] = temp
 
364
 
365
 
366
 
 
710
 
711
  response = await asyncio.wait_for(
712
 
713
+ agent(enhanced_query, ",".join(agent_list)),
714
 
715
  timeout=REQUEST_TIMEOUT_SECONDS
716
 
 
760
 
761
  response = await asyncio.wait_for(
762
 
763
+ agent(enhanced_query, agent_name),
764
 
765
  timeout=REQUEST_TIMEOUT_SECONDS
766
 
src/schemas/model_settings_schema.py CHANGED
@@ -3,5 +3,5 @@ class ModelSettings(BaseModel):
3
  provider: str
4
  model: str
5
  api_key: str = ""
6
- temperature: float = 0
7
- max_tokens: int = 1000
 
3
  provider: str
4
  model: str
5
  api_key: str = ""
6
+ temperature: float = 1.0
7
+ max_tokens: int = 6000