Untitled
def llm_generate_insights(remake_df, model, generation_config, safety_config): try: structured_data = remake_df.to_dict(orient='records') # Step 1: Generate trends and patterns trends_prompt = f""" Analyze the following data of RPG remakes/remasters: {structured_data} Provide insights on the most common features, patterns, and player reception trends. Summarize in a structured format. """ logging.info("First Call: Generating trends and patterns...") trends_response = model.generate_content( contents=trends_prompt, generation_config=generation_config, safety_settings=safety_config ) time.sleep(2) # Step 2: Generate Chrono Trigger recommendations chrono_trigger_prompt = f""" Based on the following trends and RPG remakes/remaster data, suggest the top 5 most relevant RPG remakes/remasters for a Chrono Trigger remake. Explain why these titles are relevant. Also, suggest actionable features or patterns that should be included in the remake based on successful games. Trends and Patterns: {trends_response.text} RPG Data: {structured_data} """ logging.info("Second Call: Generating Chrono Trigger recommendations...") chrono_response = model.generate_content( contents=chrono_trigger_prompt, generation_config=generation_config, safety_settings=safety_config ) time.sleep(2) # Step 3: Extract feature patterns for visualization features_prompt = f""" Extract the most mentioned features or patterns from the RPG remakes/remasters dataset. Provide a concise list of features with frequency counts in JSON format - PICK MAX 20. {structured_data} Sample Format: {"features": {"Improved visuals": 2, "New game modes": 2, "Gameplay enhancements": 25, "Expanded narrative": 24}} """ logging.info("Third Call: Extracting features for visualization...") features_response = model.generate_content( contents=features_prompt, generation_config=generation_config, safety_settings=safety_config ) time.sleep(2) # Step 4: Extract relevant titles titles_prompt = f""" Based on the following response for Chrono Trigger recommendations: {chrono_response.text} Provide the top 5 titles in JSON format with the following fields: - Title - Features: Relevant to Chrono Trigger Remake (up to 3 features) """ logging.info("Fourth Call: Extracting relevant titles...") titles_response = model.generate_content( contents=titles_prompt, generation_config=generation_config, safety_settings=safety_config ) time.sleep(2) # Parse LLM responses using parse_llm_response trends_summary = trends_response.text.strip() chrono_trigger_summary = chrono_response.text.strip() feature_insights = parse_llm_response(features_response.text) relevant_titles = parse_llm_response(titles_response.text) if feature_insights is None or relevant_titles is None: logging.error("Failed to parse some of the LLM responses.") return {} logging.info("All LLM calls and parsing completed successfully.") return { "trends_summary": trends_summary, "chrono_trigger_summary": chrono_trigger_summary, "feature_insights": feature_insights, "relevant_titles": relevant_titles } except Exception as e: logging.error(f"Error in llm_generate_insights: {e}") return {}
Leave a Comment