diff --git a/notebooks/test_sop_generator.ipynb b/notebooks/test_sop_generator.ipynb index 59ac554..23cd4fe 100644 --- a/notebooks/test_sop_generator.ipynb +++ b/notebooks/test_sop_generator.ipynb @@ -7,57 +7,28 @@ "outputs": [], "source": [ "from langchain_community.document_loaders import PyPDFLoader\n", - "loader = PyPDFLoader(\"/root/ds_erp_ai/data/raw/test_sop.pdf\")\n", + "loader = PyPDFLoader(\"/content/Example SOP (1) (1).pdf\")\n", "docs = loader.load()" ] }, { "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "from langchain_community.document_loaders import PyPDFLoader\n", - "loader = PyPDFLoader(\"/root/ds_erp_ai/data/raw/test_sop.pdf\")\n", - "docs = loader.load()" - ] - }, - { - "cell_type": "code", - "execution_count": 4, + "execution_count": 1, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "[Document(metadata={'source': '/root/ds_erp_ai/data/raw/test_sop.pdf', 'page': 0}, page_content='ERGO \\nERGO 202 4 VISION \\nDEFINITION \\nA standard operating procedure (SOP) is a step -by-step, repeatable process for any critical \\nand routine task. It’s a kind of documentation that prevents stress, mistakes, and \\nmiscommunication. SOPs ensure reliability, efficiency, and consistently hitting quality \\nstandards in regular work activities. The SOPs represent the what, when, where and how of \\nevery role in the organization as it aligns to it’s vision and goals. \\n \\nVISION: \\nERGO envisions itself as the leading platform for renting spaces, equipment, and services, \\ntransforming the way people access and share resources. By the end of the next year, we \\naim to significantly increase our user base and participation rates, fosterin g a vibrant and \\nactive community that thrives on mutual benefit and shared success. \\n \\nWe are committed to creating an intuitive, reliable, and user -friendly app that empowers \\nindividuals and businesses to rent what they need when they need it, contributing to a \\nmore efficient and sustainable use of resources. We believe in the power of tech nology to \\nsimplify transactions, build connections, and unlock new possibilities. \\n \\nOur strategic vision is to continuously innovate and improve our platform, ensuring it \\nmeets the evolving needs of our users. We will invest in marketing and user engagement \\nstrategies to attract new users and retain existing ones, with a focus on providin g \\nexceptional customer service and a seamless user experience. \\n \\nIn the long term, we aspire to expand our services to new markets and regions, establishing \\nERGO as a global leader in the sharing economy. We are dedicated to creating value for our \\nusers, stakeholders, and the broader community, contributing to a more co nnected and \\nresource -efficient world.\" \\n \\nRemember, a strategic vision is a guiding light for a company’s future direction. It will be \\nrevisited and potentially revised as the company grows and the market landscape \\nchanges. It’s also important to ensure that all stakeholders understand and align with the \\nvision. This includes employees, investors, and customers. They all play a crucia l role in \\nthe company’s journey towards its vision. \\n '),\n", - " Document(metadata={'source': '/root/ds_erp_ai/data/raw/test_sop.pdf', 'page': 1}, page_content=' '),\n", - " Document(metadata={'source': '/root/ds_erp_ai/data/raw/test_sop.pdf', 'page': 2}, page_content='GOALS; \\n1. MARKETING \\na. Brand Awareness : Increase brand awareness by 50% over the next year \\nthrough targeted marketing campaigns. \\nb. User Acquisition: Acquire 100,000 new users over the next year through \\ndigital marketing strategies. \\nc. User Engagement : Improve user engagement by 30% by implementing a \\ncontent marketing strategy that educates users about the benefits and uses \\nof ERGO. \\nd. Market Expansion : Enter two new geographic markets by the end of the year \\nthrough localized marketing campaigns. \\n2. IT INFRASTRUCTURE : \\na. Platform Stability: Achieve 99.9% uptime for the ERGO app to ensure a \\nseamless user experience. \\nb. Security: Implement robust security measures to protect user data and build \\ntrust with the user base. \\nc. Scalability: Enhance the IT infrastructure to support a 50% increase in user \\ntraffic over the next year. \\nd. Feature Development: Develop and launch three new features based on user \\nfeedback to improve the functionality and usability of the ERGO app. \\n3. SALES TEAM GOALS: \\na. New User Sales: Sign up 50,000 new users over the next year through direct \\nsales efforts. \\nb. Partnership Development: Establish partnerships with 20 new businesses to \\noffer their spaces, equipment, or services on ERGO. \\nc. Customer Retention: Achieve a customer retention rate of 90% by providing \\nexcellent customer service and follow -up. \\nd. Revenue Growth: Increase sales revenue by 30% over the next year by \\nupselling premium features and services. \\n '),\n", - " Document(metadata={'source': '/root/ds_erp_ai/data/raw/test_sop.pdf', 'page': 3}, page_content='ERGO 2024 Standard Operating Procedures : \\n \\nAPPLICATION \\nThis document applies to Information technology specialists and contractors. Marketing \\nteams and Contracting Specialist inv olved with Marketing contracts. Current and future \\nsales associates employed or contracted by ERGO. \\n \\nVISION STATEMENT \\n \\nERGO’s strategic goals for the next year encompass marketing, IT infrastructure, and sales. \\nIn marketing, we aim to increase brand awareness by 50% through targeted campaigns, \\nacquire 100,000 new users via digital strategies, improve user engagement by 30% with a \\ncontent marketing strategy, and expand into two new markets. For IT infrastructure, our \\ngoals are to achieve 99.9% app uptime, implement robust security measures, enhance \\ninfrastructure to support a 50% increase in user traffic, and develop three n ew features \\nbased on user feedback. The sales team aims to sign up 50,000 new users, establish \\npartnerships with 20 new businesses, achieve a 90% customer retention rate, and increase \\nsales revenue by 30% through upselling. \\n \\nRESPONSIBILITIES \\n \\nCHIEF OPERATIONS OFFICER : \\nCross -Functional Coordination: As a key member of the executive team, the COO will \\nensure alignment and coordination across different departments to achieve these goals. \\nPerformance Monitoring: The COO will establish key performance indicators (KPIs) and \\nregularly review progress towards these goals, making necessary adjustments to strategies \\nand plans. \\n \\nSALES MANAGER; \\nUnder the oversight and control of the COO, the sales manager will guide the sales team to \\nsign up 50,000 new users, establish partnerships with 20 new businesses, achieve a 90% \\ncustomer retention rate, and increase sales revenue by 30% through upselling. \\n \\nCAMPAIGN MANAGER: '),\n", - " Document(metadata={'source': '/root/ds_erp_ai/data/raw/test_sop.pdf', 'page': 4}, page_content='Under the oversight and control of the COO the campaign manager will oversee the \\nmarketing team’s efforts to increase brand awareness and acquire new users. They will \\nalso ensure the implementation of a content marketing strategy to improve user \\nengagement and spearhead efforts to expand into two new geographic markets. The \\ncampaign manager will exercise operational oversight and control over marketing \\nspecialist and ad contracts. \\n \\nCONTENT MARKETING SPECIALIST: \\nUnder the oversight and control of the campaign manager the content marketing specialist \\nwill; \\n1. Create fun and informative quizzes related to your brand or services . Share them on \\nsocial media and encourage users to participate and share their results. \\n2. Share behind -the-scenes glimpses of your company culture, product development, \\nor team members. People love to connect with the human side of brands. \\n3. User -Generated Content Contests: Run a contest where users submit photos, \\nvideos, or stories related to your brand. Feature the best entries on your website or \\nsocial media. \\n4. Host online webinars or workshops that provide value to potential users. Topics \\ncould include product demos, services trends, or problem -solving sessions. \\n5. Create comprehensive guides or e -books that address common pain points your \\nproduct solves. Promote these through targeted ads and email campaigns. \\n6. Share success stories of existing users. Highlight how your product transformed \\ntheir lives or businesses. Authentic testimonials resonate well with potential users. \\n7. Develop a series of short videos explaining different aspects of your product or \\nservices . Keep them engaging and easy to understand. \\n8. Create visually appealing infographics that educate users about ERGO’s benefits. \\nUse interactive elements like clickable sections or animations. \\n9. Set up a community forum where users can ask questions, share tips, and interact \\nwith each other. Host live Q&A sessions on social media. \\n10. Write blog posts specifically tailored to the culture, language, and interests of the \\nnew markets. Address local challenges and showcase how ERGO can solve them. \\n11. Create landing pages in the local language, highlighting the unique value \\nproposition of ERGO for each market. \\n12. Partner with influencers or thought leaders from the new markets. Have them \\ncreate content or host events related to ERGO. \\n \\nDIGITAL MARKETING SPECIALIST: '),\n", - " Document(metadata={'source': '/root/ds_erp_ai/data/raw/test_sop.pdf', 'page': 5}, page_content='Under the oversight and control of the campaign manager the digital marketing specialist \\nwill; \\n1. Conduct market research to understand the target audience, their preferences, and \\nwhere they spend their time online.. \\n2. React to media inquiries: engage with journalists and media outlets to kickstart your \\nPR efforts1. \\n3. Start a referral program to encourage existing users to refer new ones. \\n4. Regularly publish informative blog posts to attract organic traffic and showcase \\nyour expertise . \\n5. Offer limited -time promotions or exclusive deals to entice new users. \\n6. Personalize content: tailor content to user interests and needs. Use personalized \\npush notifications, emails, and SEO strategies. \\n7. Measure metrics: track page views, time spent on site, bounce rate, and social \\nmedia interactions. Tools like Full Session can provide insights into user behavior4. \\n8. Engage with audience: respond to comments, likes, and shares. Regularly publish \\nrelevant content to keep users engaged. \\n9. Conduct market research: understand local nuances, preferences, and behaviors. \\nDefine demographics, languages, and dialects. \\n10. Adapt content: translate and culturally adapt content. Consider local holidays, \\nsymbols, and traditions. \\n11. Localize marketing channels: choose platforms popular in the new markets. Adjust \\nadvertising campaigns accordingly. \\n12. Test and analyze pilot localized campaigns, analyze results, and optimize based on \\ndata. \\nUnder the oversight and control of the campaign manager and in coordination with other \\nspecialist the digital marketing specialist must; \\n1. Leverage social media: use platforms where your audience is most active. Share \\nengaging content, run targeted ads, and interact with followers \\n2. Implement a search -focused content marketing strategy, create valuable content \\nthat aligns with what your audience searches for. Optimize it for relevant keywords \\nto improve organic visibility \\n3. Run targeted ads on cloud -related platforms or industry -specific websites in the \\nnew markets. Emphasize ERGO’s cloud advantages for local businesses. \\nSEARCH ENGINE OPTIMIZATION SPECIALIST: \\nUnder the oversight and control of the campaign manager the search engine optimization \\nspecialist will; \\n1. Create valuable content that aligns with what your audience searches for. Optimize \\nit for relevant keywords to improve organic visibility '),\n", - " Document(metadata={'source': '/root/ds_erp_ai/data/raw/test_sop.pdf', 'page': 6}, page_content='2. Personalize Content: Tailor content to user interests and needs. Use personalized \\npush notifications, emails, and SEO strategies. \\n3. Measure Metrics: Track page views, time spent on site, bounce rate, and social \\nmedia interactions. Tools like Full Session can provide insights into user behavior4. \\n4. Under the oversight and control of the campaign manager and in coordination with \\nother specialist the search engine optimization specialist must; \\n5. Engage with journalists and media outlets to kickstart your PR efforts. \\n6. Use platforms where your audience is most active. Share engaging content, run \\ntargeted ads, and interact with followers. \\n \\nINFORMATION TECHNOLOGY OFFICER \\nIn coordination cooperation with the Chief Operations Officer the Information Technology \\nOfficer will work closely with the it team to achieve 99.9% uptime for the ergo app, \\nimplement robust security measures, shall enhance the it infrastructure to support \\nincreased user traffic, and must develop and launch new features based on user feedback. \\nThe Information Technology officer will h ave a well -defined plan in place to handle security \\nincidents in local and new markets . \\nCLOUD ENGINEER: \\nunder the oversight and control of the Information Technology Officer the Cloud Engineer \\nshall; \\n1. Select cloud service providers with strong security practices. Ensure they comply \\nwith industry standards. \\n2. Clearly communicate to users how their data will be collected, used, and \\nprotected. Maintain a comprehensive privacy policy on your website. \\n3. Obtain explicit consent from users before collecting any personal data. Implement \\ncookie consent banners and ensure compliance with regulations like GDPR or \\nCCPA. \\n4. Isolate different components of your infrastructure to prevent lateral movement in \\ncase of a breach \\n5. Conduct periodic security audits to identify vulnerabilities and address them \\npromptly. \\nunder the oversight and control of the Information Technology Officer the Cloud Engineer \\nwill; \\n1. Design , implement, and manag e cloud computing solutions, such as public, \\nprivate, and hybrid cloud environments. \\n2. Create step -by-step video tutorials on how new users can set up their accounts, \\naccess features, and utilize cloud -based services within ERGO. \\n3. Deploy cloud infrastructure '),\n", - " Document(metadata={'source': '/root/ds_erp_ai/data/raw/test_sop.pdf', 'page': 7}, page_content=\"4. Migrate on -premises systems to the cloud \\n1. Continuously monitor and optimize ERGO’s cloud resources for scalability and \\ncost -effectiveness. Share success stories of how cloud improvements directly \\nbenefit users. Ensure cloud security and compliance \\n2. Host webinars on cloud -related topics, emphasizing how ERGO leverages cloud \\ntechnology. Invite industry experts and influencers to participate. \\nunder the oversight and control of the Information Technology Officer the Cloud Engineer \\nmust ; \\n3. Establish an online community forum where users can share tips, ask questions, \\nand discuss cloud -related topics. Cloud engineers can actively participate and \\nprovide insights. \\n4. Create visually appealing case studies or blog posts highlighting how ERGO’s cloud \\ninfrastructure enables seamless user experiences. Explain how scalability, \\nreliability, and security are achieved through cloud services. \\n5. Develop an interactive web page or app feature that takes users on a virtual tour of \\nERGO’s cloud architecture. Explain key components, data flow, and benefits. \\n6. Train cloud support teams to assist users in the new markets. Ensure they \\nunderstand the cultural context and can address cloud -related queries effectively. \\n \\nDATABASE ADMINISTRATOR (DBA): \\nDatabase administrators are responsible for the design, implementation, and \\nmaintenance of databases that store and organize an organization's data. They install and \\nconfigure database management systems, optimize database performance, backup and \\nrestore d ata, and enforce data security policies. \\nunder the oversight and control of the Information Technology Officer the DBA will; \\n1. Continuously update and expand the user database. Capture user data through \\nsign -ups, app usage, and interactions. Ensure data accuracy and completeness. \\n2. Leverage lookalike audience targeting on platforms like Facebook and Google Ads. \\nUse existing user profiles to find similar potential users. \\n3. Set up automated triggers based on user behavior (e.g., abandoned carts, frequent \\nvisits). Send personalized emails or notifications to re -engage users. \\n4. Regularly clean and optimize the database. Remove inactive or irrelevant users to \\nimprove engagement metrics. \\n5. Gather data on market trends, cultural nuances, and user preferences in the new \\nmarkets. Understand how ERGO’s brand can align with local values. \\nunder the oversight and control of the Information Technology Officer the DBA must; \"),\n", - " Document(metadata={'source': '/root/ds_erp_ai/data/raw/test_sop.pdf', 'page': 8}, page_content='1. Collaborate with the marketing team to collect data on brand awareness metrics \\n(e.g., social media mentions, website traffic, search volume). Use this data to \\nidentify trends and areas for improvement. \\n2. Create segments within the database based on user interactions with ERGO’s \\nbrand. Tailor marketing messages to each segment, emphasizing brand values, \\nunique selling points, and success stories. \\n3. Experiment with different marketing campaigns and track their impact on brand \\nawareness. Optimize based on the most effective strategies. \\n6. Work closely with data analysts to profile existing users. Understand their \\ndemographics, behavior, and preferences. Use this information to target similar \\naudiences in digital marketing campaigns. \\n7. Collaborate with content creators to personalize marketing content. Use database \\ninsights to tailor messages that resonate with users’ interests and pain points. \\n8. Collaborate with content teams to create region -specific marketing materials. \\nTranslate content, adapt visuals, and customize messaging. \\nIT SECURITY ANALYST: \\nUnder the oversight and control of the Information Technology Officer the IT Security \\nAnalyst shall; \\n1. Research and understand the data protection laws and regulations in the new \\nmarkets. Ensure compliance with GDPR, CCPA, or other relevant standards. \\n2. Train local teams on incident response procedures \\nUnder the oversight and control of the Information Technology Officer the IT Security \\nAnalyst will; \\n1. Restrict access to marketing databases. Only authorized personnel should handle \\nsensitive customer information. \\n2. Implement CAPTCHA or other anti -bot measures during user registration to prevent \\nfraudulent accounts. \\n3. If ERGO uses apis for user registration or authentication, ensure they are properly \\nsecured with authentication tokens and rate limiting. \\n4. Set up anomaly detection to identify suspicious user activity (e.g., sudden spikes in \\nregistrations). \\n5. Regularly update CMS platforms and plugins to patch security vulnerabilities. Use \\nstrong authentication for CMS access. \\n6. Ensure that content marketing materials (blogs, videos, etc.) Are free from \\nmalicious code (e.g., cross -site scripting). Scan for vulnerabilities. \\nUnder the oversight and control of the Information Technology Officer the IT Security \\nAnalyst must; '),\n", - " Document(metadata={'source': '/root/ds_erp_ai/data/raw/test_sop.pdf', 'page': 9}, page_content=\"1. Collaborate with the marketing team to ensure that all customer data collected for \\ntargeted campaigns is securely stored and transmitted. Implement encryption for \\ndata in transit and at rest. \\n2. Educate marketing staff about security best practices. Ensure they understand the \\nimportance of protecting customer data. \\nIT OPERATIONS MANAGER: \\nIT operations managers oversee the day -to-day operations of an organization's IT \\ninfrastructure and support teams. They develop and implement IT policies and procedures, \\nmanage IT resources and budgets, coordinate IT projects and initiatives, and ensure th at IT \\nsystems meet business requirements and objectives. \\nIT SUPPORT SPECIALIST: \\nUnder the oversight and control of the IT OPERATIONS MANAGER the IT Security Analyst \\nwill; \\n1. Ensure that the onboarding process is seamless for new users. Provide clear \\ninstructions, troubleshoot any issues, and guide them through setup. \\n2. Set up efficient user support channels (chat, email, or phone). Respond promptly to \\ninquiries and resolve any technical hurdles. \\n3. Reach out to users who haven’t engaged recently. Offer personalized assistance, \\nask for feedback, and provide tips on using ERGO effectively. \\n4. Gather user feedback on their experiences. Use this information to improve the \\nproduct and enhance brand perception. \\n5. Conduct surveys to understand pain points and areas for improvement. Use this \\ndata to enhance user engagement strategies. \\n6. Continuously update the knowledge base with troubleshooting guides, FAQs, and \\nbest practices. Make it easily accessible to users. \\n7. Collaborate with localization teams to ensure that ERGO’s software and \\ndocumentation are available in the local languages of the new markets. \\n8. Anticipate region -specific technical challenges. Prepare troubleshooting guides \\ntailored to the new markets. \\n9. Host webinars or virtual training sessions for existing and potential users. Teach \\nthem how to make the most of ERGO’s services. \\nUnder the oversight and control of the IT OPERATIONS MANAGER the IT Security Analyst \\nmust; \\n1. Collaborate with the marketing team to create engaging technical content. Write \\nblog posts, FAQs, or video tutorials about ERGO’s unique features and benefits. \\n2. Encourage existing users to refer new users. Offer incentives or discounts for \\nsuccessful referrals. \"),\n", - " Document(metadata={'source': '/root/ds_erp_ai/data/raw/test_sop.pdf', 'page': 10}, page_content='3. Understand cultural nuances and adapt communication accordingly. Provide user \\nsupport that aligns with local customs and preferences. \\nDEVOPS ENGINEER: \\nUnder the oversight and control of the IT OPERATIONS MANAGER the DEVOPS engineer \\nshall ; \\n1. Collaborate with legal and compliance teams to understand data protection laws \\nand ensure adherence in each region. \\nUnder the oversight and control of the IT OPERATIONS MANAGER the DEVOPS engineer \\nwill; \\n1. Implement monitoring tools to track website performance, uptime, and user \\ninteractions. Set up alerts for any anomalies or downtime. \\n2. Ensure that ERGO’s infrastructure can handle increased traffic during marketing \\ncampaigns. Autoscale servers and optimize load balancers. \\n3. Design robust and fault -tolerant systems to handle user registrations, logins, and \\ndata processing. Use redundancy and failover mechanisms. \\n4. optimize content delivery networks (CDNs). Reduce latency for users accessing \\nERGO’s content. \\n5. Set up infrastructure to support A/B testing for different content variations. Monitor \\nuser engagement metrics for each variant. \\n6. Customize deployment scripts for each new market. Consider regional cloud \\nproviders and data centers. \\nUnder the oversight and control of the IT OPERATIONS MANAGER the DEVOPS engineer \\nmust; \\n1. Set up CI/CD pipelines to streamline marketing campaign deployments. Automate \\nthe rollout of new landing pages, banners, and promotional content. \\n2. Collaborate with DBA to simulate heavy user loads during testing. Optimize \\ndatabase queries and API endpoints for scalability. \\n3. Create a feedback loop between DevOps and content teams. Rapidly deploy \\nchanges based on user feedback to improve engagement. \\n4. Set up databases with geo -replication to ensure data availability and low latency in \\nnew markets. \\n \\n \\n \\n \\n \\n \\n '),\n", - " Document(metadata={'source': '/root/ds_erp_ai/data/raw/test_sop.pdf', 'page': 11}, page_content=' \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n ')]" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" + "ename": "NameError", + "evalue": "name 'SOPsResponse' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[1], line 22\u001b[0m\n\u001b[1;32m 19\u001b[0m \u001b[38;5;28;01mclass\u001b[39;00m \u001b[38;5;21;01mRoles_response\u001b[39;00m(BaseModel):\n\u001b[1;32m 20\u001b[0m roles: \u001b[38;5;28mlist\u001b[39m[\u001b[38;5;28mstr\u001b[39m]\n\u001b[0;32m---> 22\u001b[0m \u001b[38;5;28;01mclass\u001b[39;00m \u001b[38;5;21;01mSopGenerator\u001b[39;00m:\n\u001b[1;32m 23\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__init__\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[1;32m 24\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mapi_key \u001b[38;5;241m=\u001b[39m os\u001b[38;5;241m.\u001b[39mgetenv(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mOPENAI_API_KEY\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", + "Cell \u001b[0;32mIn[1], line 89\u001b[0m, in \u001b[0;36mSopGenerator\u001b[0;34m()\u001b[0m\n\u001b[1;32m 60\u001b[0m response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mclient\u001b[38;5;241m.\u001b[39mbeta\u001b[38;5;241m.\u001b[39mchat\u001b[38;5;241m.\u001b[39mcompletions\u001b[38;5;241m.\u001b[39mparse(\n\u001b[1;32m 61\u001b[0m model\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel,\n\u001b[1;32m 62\u001b[0m messages\u001b[38;5;241m=\u001b[39m[\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 83\u001b[0m temperature\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0.1\u001b[39m\n\u001b[1;32m 84\u001b[0m )\n\u001b[1;32m 86\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m json\u001b[38;5;241m.\u001b[39mloads(response\u001b[38;5;241m.\u001b[39mchoices[\u001b[38;5;241m0\u001b[39m]\u001b[38;5;241m.\u001b[39mmessage\u001b[38;5;241m.\u001b[39mcontent)\n\u001b[0;32m---> 89\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mgenerate_sops\u001b[39m(\u001b[38;5;28mself\u001b[39m, roles, docs_text) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[43mSOPsResponse\u001b[49m:\n\u001b[1;32m 90\u001b[0m roles_sops_all \u001b[38;5;241m=\u001b[39m {}\n\u001b[1;32m 92\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m role \u001b[38;5;129;01min\u001b[39;00m roles:\n", + "\u001b[0;31mNameError\u001b[0m: name 'SOPsResponse' is not defined" + ] } ], - "source": [ - "docs" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], "source": [ "import os\n", "import json\n", @@ -187,31 +158,11 @@ "roles = [\"Devops engineers\"]\n", "sops_response = service.check_role_sop(roles,docs)" ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'message': 'SOPs found for the roles: Devops engineers', 'status': True}" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "sops_response" - ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "erp", "language": "python", "name": "python3" }, diff --git a/requirements.txt b/requirements.txt index fd72837..488c514 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,10 +3,4 @@ langchain-community langchain-openai pydantic flask -python-dotenv -pypdf -pypandoc -Spire.Doc -plum-dispatch==1.7.4 -pandas -scikit-learn \ No newline at end of file +python-dotenv \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..e69de29 diff --git a/src/api/routes/questions.py b/src/api/routes/questions.py index 2b80417..17d5664 100644 --- a/src/api/routes/questions.py +++ b/src/api/routes/questions.py @@ -24,9 +24,6 @@ def allowed_file(filename): - - - @qs_b.route('/generate_questions_from_sop', methods=['POST']) @auth_check def generate_questions_from_sop_v2(): @@ -58,7 +55,43 @@ def generate_questions_from_sop_v2(): # Convert the Pydantic model to a dictionary and return as JSON return jsonify({"questions": questions_response.dict()}), 200 - except ValidationError as ve: - return jsonify({"error": "Validation Error", "message": str(ve)}), 400 + except Exception as e: - return jsonify({"error": "Internal Server Error", "message": str(e)}), 500 \ No newline at end of file + return jsonify({"error": "Internal Server Error", "message": str(e)}), 500 + + +@qs_b.route('/generate_questions_from_sop-latest', methods=['POST']) +@auth_check +def generate_questions_from_sop_v3(): + if not request.is_json: + return jsonify({"error": "Invalid input", "message": "Input data must be in JSON format."}), 400 + + input_data = request.get_json() + + required_fields = ['sops', 'assessment_type', 'duration'] + for field in required_fields: + if field not in input_data: + return jsonify({"error": "Missing data", "message": f"'{field}' is required."}), 400 + + try: + # Prepare the data for the generator + generator_input = { + "sops": input_data['sops'], + "assessment_type": input_data['assessment_type'], + "duration": input_data['duration'] + } + + # Generate questions using the QuestionGenerator + generator = QuestionsGeneratorV2() + questions_response = generator.generate_questions_for_all(generator_input) + + if not questions_response: + return jsonify({"error": "Question generation failed", "message": "Could not generate questions from the provided data."}), 500 + + # Convert the Pydantic model to a dictionary and return as JSON + return jsonify({"questions": questions_response}), 200 + + + except Exception as e: + return jsonify({"error": "Internal Server Error", "message": str(e)}), 500 + diff --git a/src/models/questions_response.py b/src/models/questions_response.py index 8d249e5..bd5cf53 100644 --- a/src/models/questions_response.py +++ b/src/models/questions_response.py @@ -14,10 +14,11 @@ class AssementQuestion(BaseModel): from pydantic import BaseModel from typing import List, Dict - +from typing import Optional class Question(BaseModel): - area_tag: int + area_tag: Optional[int] + area_name: str assigned_to: int questions: str role: int @@ -30,4 +31,7 @@ class Questions(BaseModel): questions: List[FrequencyQuestions] class AssessmentQuestions(BaseModel): - questions: Questions \ No newline at end of file + questions: Questions + +class AllQuestions(BaseModel): + questions : List[Question] \ No newline at end of file diff --git a/src/prompts/questions.py b/src/prompts/questions.py index 84bdca6..4f986da 100644 --- a/src/prompts/questions.py +++ b/src/prompts/questions.py @@ -118,6 +118,8 @@ def get_questions_prompt_v2(): def get_questions_prompt_v3(): prompt = """ You are tasked with generating assessment questions for workers based on their SOPs. These questions should vary by assessment type (daily, weekly, biweekly), frequency number (e.g., day 2, week 3), and total duration (e.g., 6 weeks). + + INPUT: SOPS Guidelines: 1. Generate yes/no questions relevant to each worker's SOP based on their role. @@ -149,4 +151,94 @@ def get_questions_prompt_v3(): } } """ - return prompt \ No newline at end of file + return prompt + + +def get_questions_prompt_v5(): + prompt = """ + Comprehensive Assessment Question Generation Methodology + + Objective: + Generate a robust, long-term assessment framework for organizational performance evaluation, focusing on systematic and consistent monitoring of operational procedures. + + Strategic Design Principles: + 1. Question Generation Framework: + - Create a holistic set of assessment questions + - Designed for sustained use across multiple assessment periods + - Provides comprehensive organizational insight + - Enables continuous performance tracking and improvement + + 2. Structural Requirements: + a. Question Attributes: + - Binary (Yes/No) response format + - Directly mapped to specific organizational roles + - Aligned with Standard Operating Procedures (SOPs) + - Covers multiple performance dimensions + + b. Taxonomical Tagging: + - area_tag: Precise topic/domain identifier + - role: Specific organizational role classification + - assigned_to: Exact responsible team member identifier + + 3. Question Design Criteria: + a. Content Depth: + - Reveal operational effectiveness + - Uncover potential process improvements + - Highlight compliance and procedural adherence + - Capture nuanced performance indicators + + b. Evaluation Dimensions: + - Operational efficiency + - Quality control + - Safety protocols + - Procedural compliance + - Resource utilization + - Knowledge application + - Risk management + + 4. Contextual Considerations: + - Reflect current organizational structure + - Adaptable to evolving operational landscapes + - Maintain consistency in assessment approach + - Support data-driven decision-making + Tagging Requirements: + - area_tag: Unique identifier for topic area + - role: Corresponding role ID from SOP + - assigned_to: Exact ID of specific team member responsible + Output Specification: + { + "questions": { + "items": [ + { + "area_tag": int, # Domain/Topic Identifier + "area_name":str # Name of the area + "assigned_to": str, # Responsible Member ID + "questions": str, # Assessment Query + "role": int # Organizational Role Identifier + } + ] + } + } + + Implementation Guidelines: + - Develop questions that transcend mere compliance + - Encourage reflective and proactive organizational learning + - Ensure questions are clear, unambiguous, and actionable + - Prioritize questions that drive continuous improvement + + Critical Mandate: + Craft questions that are: + - Precise and targeted + - Aligned with organizational SOPs + - Capable of revealing substantive operational insights + - Supportive of strategic organizational objectives + NOTE: Generate at least 25 questions and can be more depending on the structure of the sop + NOTE: !!! MAKE SURE YOU CORRECTLY ATTACH "assigned_to" AS THE ID OF THE MEMBER OF THE ROLE AS STATED IN THE SOP. CHECK MEMBERS UNDER THE ROLE IN THE PROVIDED SOP AND USE THE CORRECT ID OF THE MEMBER, DO NOT USE MEMBER iD THAT IS NOT PROVIDED AS "assigned_to" pls FOLLOW THIS STRICTLY!!! + NOTE: CHECK THE "role_id" UNDER THE PROVIDED SOP AND USE THE CORRECT ID OF THE ROLE, DO NOT USE OR FORMULATE "role_id" THAT IS NOT PROVIDED AS "role" pls FOLLOW THIS STRICTLY!!! + + NOTE: IF area tags is not provided for specicfic role SOPS, kindly formulate an area name based on the sop and make the area_tag null but forumlate rea name, only do this if area tags info is not provided for specific role sops + NOTE: Use exactly the area names provided if available unless area tags is missing and you need to forumalate one + + """ + return prompt + \ No newline at end of file diff --git a/src/services/questions_generator.py b/src/services/questions_generator.py index 8ced795..d80b1dc 100644 --- a/src/services/questions_generator.py +++ b/src/services/questions_generator.py @@ -197,3 +197,39 @@ class QuestionsGeneratorV2: except Exception as e: print(f"An error occurred: {e}") return None + + + def generate_questions_for_all(self,input_data, all_questions: List[Dict]=[]): + try: + sops = input_data['sops'] + assessment_type = input_data['assessment_type'] + total_duration = input_data['duration'] + + + # Chunk the SOPs into smaller pieces + chunk_size = 1000 + docs_text = [sops[i:i + chunk_size] for i in range(0, len(sops), chunk_size)] + docs = [{"type": "text", "text": text} for text in docs_text] + + + response = self.client.beta.chat.completions.parse( + model=self.model, + messages=[ + {"role": "system", "content": get_questions_prompt_v5()}, + {"role": "user", "content": f"The SOPs are provided below."}, + {"role": "user", "content": json.dumps(docs)}, + {"role": "user", "content": f"Assessment Type: {assessment_type}"}, + {"role": "user", "content": f"Duration: {total_duration}"} + ], + temperature=0.1, + response_format=AllQuestions, # Ensure you specify the correct format + max_tokens=6000 + ) + + questions_json = json.loads(response.choices[0].message.content) + + # Add the questions to the shared list (using lock to avoid race conditions + return questions_json + except Exception as e: + print(f"An error occurred while generating questions: {e}") + return None \ No newline at end of file