Spaces:
Paused
Paused
Increase max_tokens for all models in generation settings to enhance response capacity
Browse filesFiles changed (2)
- config/environments/default.yaml+4-4
- main.py+26-22
22 unmodified lines2324252627282930313222 unmodified lines# Generation Settingsgeneration:max_tokens:openai: 1024anthropic: 1024gemini: 1024deepseek: 1024max_tokens_analysis: 4000temperature: 0.522 unmodified lines2324252627282930313222 unmodified lines# Generation Settingsgeneration:max_tokens:openai: 4096anthropic: 4096gemini: 4096deepseek: 4096max_tokens_analysis: 4000temperature: 0.5
600 unmodified lines6016026036046056066076086096106116126136146156166176186196206216226236246256266276286296301 unmodified line6326336346356366372 unmodified lines640641642643644645646647648649650651652653654655656657658659660661662136 unmodified lines7998008018028038048058068 unmodified lines815816817818819820600 unmodified linesraise Exception(f"Текст судового рішення занадто короткий або відсутній (довжина: {len(court_decision_text) if court_decision_text else 0} символів). Будь ласка, перевірте вхідні дані.")if provider == ModelProvider.OPENAI.value:llm = LlamaOpenAI(model=model_name,temperature=GENERATION_TEMPERATURE,max_tokens=MAX_TOKENS_CONFIG["openai"])messages = [ChatMessage(role="system", content=system_prompt),ChatMessage(role="user", content=content),]try:response = llm.chat(messages, response_format=LEGAL_POSITION_SCHEMA)response_text = response.message.contentjson_response = extract_json_from_text(response_text)if json_response and all(key in json_response for key in ["title", "text", "proceeding", "category"]):return json_responseelse:raise ValueError(f"Invalid JSON structure from OpenAI: {response_text[:200]}...")except Exception as e:print(f"[ERROR] OpenAI generation/parsing failed: {e}")return {"title": "Автоматично сформований заголовок (OpenAI)","text": content[:500] if not 'response_text' in locals() else response_text,"proceeding": "Не визначено","category": "Помилка парсингу"}1 unmodified lineif provider == ModelProvider.DEEPSEEK.value:client = OpenAI(api_key=DEEPSEEK_API_KEY, base_url="https://api.deepseek.com")try:response = client.chat.completions.create(model=model_name,messages=[2 unmodified lines],temperature=GENERATION_TEMPERATURE,max_tokens=MAX_TOKENS_CONFIG["deepseek"],response_format={'type': 'json_object'},stream=False)response_text = response.choices[0].message.contentjson_response = extract_json_from_text(response_text)if json_response and all(key in json_response for key in ["title", "text", "proceeding", "category"]):return json_responseelse:raise ValueError(f"Invalid JSON structure from DeepSeek: {response_text[:200]}...")except Exception as e:print(f"[ERROR] DeepSeek generation/parsing failed: {e}")return {"title": "Автоматично сформований заголовок (DeepSeek)","text": "Помилка при отриманні відповіді від DeepSeek","proceeding": "Не визначено","category": "Помилка API/Парсингу"}136 unmodified lines)# Only add response_mime_type for models that support itif not model_name.startswith("gemini-3"):config_params["response_mime_type"] = "application/json"generate_content_config = types.GenerateContentConfig(**config_params)8 unmodified linesif not response_text:raise Exception("Пуста відповідь від моделі Gemini")# Спробуємо розпарсити JSON за допомогою універсальної функціїjson_response = extract_json_from_text(response_text)600 unmodified lines6016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316321 unmodified line6346356366376386396402 unmodified lines643644645646647648649650651652653654655656657658659660661662663136 unmodified lines8008018028038048058068078 unmodified lines816817818819820821822823824600 unmodified linesraise Exception(f"Текст судового рішення занадто короткий або відсутній (довжина: {len(court_decision_text) if court_decision_text else 0} символів). Будь ласка, перевірте вхідні дані.")if provider == ModelProvider.OPENAI.value:client = OpenAI(api_key=OPENAI_API_KEY)try:print(f"[DEBUG] OpenAI Generation - Model: {model_name}")response = client.chat.completions.create(model=model_name,messages=[{"role": "system", "content": system_prompt},{"role": "user", "content": content},],temperature=GENERATION_TEMPERATURE,max_tokens=MAX_TOKENS_CONFIG["openai"],)response_text = response.choices[0].message.contentprint(f"[DEBUG] OpenAI response length: {len(response_text)}")json_response = extract_json_from_text(response_text)if json_response and all(key in json_response for key in ["title", "text", "proceeding", "category"]):return json_responseelse:print(f"[WARNING] Invalid JSON structure from OpenAI. Text: {response_text[:300]}...")raise ValueError("Invalid JSON structure")except Exception as e:print(f"[ERROR] OpenAI generation/parsing failed: {e}")return {"title": "Автоматично сформований заголовок (OpenAI)","text": response_text.strip() if 'response_text' in locals() else "Помилка при отриманні відповіді","proceeding": "Не визначено","category": "Помилка парсингу"}1 unmodified lineif provider == ModelProvider.DEEPSEEK.value:client = OpenAI(api_key=DEEPSEEK_API_KEY, base_url="https://api.deepseek.com")try:print(f"[DEBUG] DeepSeek Generation - Model: {model_name}")response = client.chat.completions.create(model=model_name,messages=[2 unmodified lines],temperature=GENERATION_TEMPERATURE,max_tokens=MAX_TOKENS_CONFIG["deepseek"],)response_text = response.choices[0].message.contentprint(f"[DEBUG] DeepSeek response length: {len(response_text)}")json_response = extract_json_from_text(response_text)if json_response and all(key in json_response for key in ["title", "text", "proceeding", "category"]):return json_responseelse:print(f"[WARNING] Invalid JSON structure from DeepSeek. Text: {response_text[:300]}...")raise ValueError("Invalid JSON structure")except Exception as e:print(f"[ERROR] DeepSeek generation/parsing failed: {e}")return {"title": "Автоматично сформований заголовок (DeepSeek)","text": response_text.strip() if 'response_text' in locals() else "Помилка при отриманні відповіді від DeepSeek","proceeding": "Не визначено","category": "Помилка API/Парсингу"}136 unmodified lines)# Only add response_mime_type for models that support it# if not model_name.startswith("gemini-3"):# config_params["response_mime_type"] = "application/json"generate_content_config = types.GenerateContentConfig(**config_params)8 unmodified linesif not response_text:raise Exception("Пуста відповідь від моделі Gemini")print(f"[DEBUG] Gemini response length: {len(response_text)}")print(f"[DEBUG] Gemini response preview: {response_text[:300]}...")# Спробуємо розпарсити JSON за допомогою універсальної функціїjson_response = extract_json_from_text(response_text)
config/environments/default.yaml+4-4
main.py+26-22