{"id":15787,"date":"2024-12-17T18:21:58","date_gmt":"2024-12-17T10:21:58","guid":{"rendered":"https:\/\/www.aisharenet.com\/?p=15787"},"modified":"2024-12-17T18:31:43","modified_gmt":"2024-12-17T10:31:43","slug":"crewai-command-r7b","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/en\/crewai-command-r7b\/","title":{"rendered":"CrewAI + Command-R7B \u767e\u884c\u4ee3\u7801\u5b9e\u73b0\u667a\u80fd\u751f\u6210\u65b0\u95fb"},"content":{"rendered":"<p>\u57fa\u4e8e <a href=\"https:\/\/www.kdjingpai.com\/en\/crewai\/\">CrewAI<\/a> \u591a\u667a\u80fd\u4f53\u534f\u4f5c\u548c <a href=\"https:\/\/www.kdjingpai.com\/en\/cohere\/\">Cohere<\/a> Command-R7B \u5927\u6a21\u578b\uff0c\u7cfb\u7edf\u80fd\u81ea\u52a8\u5b8c\u6210\u4ece\u7814\u7a76\u5230\u5199\u4f5c\u7684\u5168\u6d41\u7a0b\uff0c\u50cf\u62e5\u6709\u4e00\u4e2a 24 \u5c0f\u65f6\u8fd0\u8f6c\u7684\u65b0\u95fb\u5de5\u4f5c\u5ba4<\/p>\n<p><strong> <img decoding=\"async\" title=\"CrewAI + Command-R7B \u667a\u80fd\u65b0\u95fb\u751f\u6210-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/6de6a07287915dc.jpg\" alt=\"CrewAI + Command-R7B \u667a\u80fd\u65b0\u95fb\u751f\u6210-1\" \/> <\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u6838\u5fc3\u529f\u80fd\uff1a<\/strong><\/p>\n<ol>\n<li>\u7814\u7a76\u5206\u6790\uff1a\u7531\u7b2c\u4e00\u4e2a AI \u52a9\u624b\u8d1f\u8d23\u641c\u7d22\u548c\u6574\u7406\u4e0e\u8bdd\u9898\u76f8\u5173\u7684\u6240\u6709\u8d44\u6599\uff0c\u5305\u62ec\u65b0\u95fb\u3001\u6570\u636e\u548c\u4e13\u5bb6\u89c2\u70b9\u3002<\/li>\n<li>\u5185\u5bb9\u521b\u4f5c\uff1a\u7b2c\u4e8c\u4e2a AI \u52a9\u624b\u5c06\u7814\u7a76\u8d44\u6599\u8f6c\u5316\u4e3a\u7ed3\u6784\u5b8c\u6574\u7684\u6587\u7ae0\uff0c\u786e\u4fdd\u4e13\u4e1a\u6027\u548c\u53ef\u8bfb\u6027\u3002<\/li>\n<li>\u4e00\u952e\u751f\u6210\uff1a\u7528\u6237\u53ea\u9700\u8f93\u5165\u8bdd\u9898\uff0c\u7cfb\u7edf\u5c31\u4f1a\u81ea\u52a8\u5b8c\u6210\u5168\u90e8\u5de5\u4f5c\u3002<\/li>\n<\/ol>\n<p><strong>\u6280\u672f\u4eae\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li>\u91c7\u7528 crewAI\uff0c\u6846\u67b6\u5b9e\u73b0\u591a AI \u534f\u4f5c<\/li>\n<\/ul>\n<ul>\n<li>\u4f7f\u7528 cohere\uff0cCommand-R7B \u5927\u6a21\u578b\u786e\u4fdd\u8f93\u51fa\u8d28\u91cf<\/li>\n<\/ul>\n<ul>\n<li>\u57fa\u4e8e streamlit\uff0c\u6784\u5efa\u7b80\u6d01\u6613\u7528\u7684\u7f51\u9875\u754c\u9762<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528\u6d41\u7a0b\uff1a<\/strong><\/p>\n<ol>\n<li>\u5728\u4fa7\u8fb9\u680f\u8f93\u5165\u60f3\u8981\u4e86\u89e3\u7684\u8bdd\u9898<\/li>\n<li>\u53ef\u9009\u62e9\u8c03\u6574\u751f\u6210\u53c2\u6570\uff08\u5982\u521b\u9020\u6027\u7a0b\u5ea6\uff09<\/li>\n<li>\u70b9\u51fb\u751f\u6210\u6309\u94ae<\/li>\n<li>\u7b49\u5f85\u7cfb\u7edf\u5b8c\u6210\u7814\u7a76\u548c\u5199\u4f5c<\/li>\n<li>\u53ef\u76f4\u63a5\u67e5\u770b\u6216\u4e0b\u8f7d\u751f\u6210\u7684\u6587\u7ae0<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><strong>\u4e0b\u9762\u5c55\u793a\u7684\u67b6\u6784\u56fe\u5c55\u793a\u4e86\u90e8\u5206\u5173\u952e\u7ec4\u4ef6\uff08\u667a\u80fd\u4f53\/\u4efb\u52a1\/\u5de5\u5177\uff09\u4ee5\u53ca\u5b83\u4eec\u5982\u4f55\u76f8\u4e92\u4f5c\u7528\uff01<\/strong><\/p>\n<p>\u63a5\u4e0b\u6765\u5c06\u8be6\u7ec6\u63cf\u8ff0\u6bcf\u4e2a\u7ec4\u4ef6\u53ca\u5176\u4ee3\u7801\uff1a<\/p>\n<p><img decoding=\"async\" title=\"-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/614a3f0faa0e3fb.jpg\" alt=\"-1\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u8bbe\u7f6e\u5927\u8bed\u8a00\u6a21\u578b\uff08LLM\uff09\u548c\u7f51\u9875\u641c\u7d22\u5de5\u5177<\/strong><\/p>\n<p>\u540c\u65f6\u521b\u5efa\u4e00\u4e2a .env \u6587\u4ef6\u7528\u4e8e\u5b58\u653e\u5b83\u4eec\u76f8\u5e94\u7684 API \u5bc6\u94a5\uff1a<\/p>\n<p><img decoding=\"async\" title=\"-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/20a8513281064e8.jpg\" alt=\"-1\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u9ad8\u7ea7\u7814\u7a76\u5206\u6790\u5458\u667a\u80fd\u4f53<\/strong><\/p>\n<p>\u7f51\u9875\u641c\u7d22\u667a\u80fd\u4f53\u63a5\u53d7\u7528\u6237\u67e5\u8be2\uff0c\u7136\u540e\u4f7f\u7528 Serper \u7f51\u9875\u641c\u7d22\u5de5\u5177\u4ece\u4e92\u8054\u7f51\u4e0a\u83b7\u53d6\u7ed3\u679c\u5e76\u8fdb\u884c\u6574\u5408\u3002<\/p>\n<p>\u770b\u770b\u8fd9\u4e2a\ud83d\udc47<\/p>\n<p><img decoding=\"async\" title=\"-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/ad86e6a4d42c80b.jpg\" alt=\"-1\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u7814\u7a76\u5206\u6790\u5458\u667a\u80fd\u4f53\u4efb\u52a1<\/strong><\/p>\n<p>\u8fd9\u662f\u6211\u4eec\u5206\u914d\u7ed9\u9ad8\u7ea7\u7814\u7a76\u5206\u6790\u5458\u667a\u80fd\u4f53\u7684\u7814\u7a76\u4efb\u52a1\uff0c\u5305\u542b\u4efb\u52a1\u63cf\u8ff0\u548c\u9884\u671f\u8f93\u51fa\u3002<\/p>\n<p><img decoding=\"async\" title=\"-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/d285435c81648dc.jpg\" alt=\"-1\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u5185\u5bb9\u7f16\u5199\u667a\u80fd\u4f53<\/strong><\/p>\n<p>\u5185\u5bb9\u7f16\u5199\u667a\u80fd\u4f53\u7684\u89d2\u8272\u662f\u4f7f\u7528\u6574\u7406\u597d\u7684\u7ed3\u679c\u5e76\u5c06\u5176\u8f6c\u5316\u4e3a\u4e00\u7bc7\u7cbe\u7f8e\u7684\u3001\u53ef\u53d1\u5e03\u7684\u65b0\u95fb\u6587\u7ae0\u3002<\/p>\n<p><img decoding=\"async\" title=\"-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/1effb4bd340a05d.jpg\" alt=\"-1\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u5185\u5bb9\u7f16\u5199\u667a\u80fd\u4f53\u4efb\u52a1<\/strong><\/p>\n<p>\u8fd9\u662f\u6211\u4eec\u5982\u4f55\u63cf\u8ff0\u5199\u4f5c\u4efb\u52a1\uff0c\u5305\u62ec\u6240\u6709\u7ec6\u8282\u548c\u9884\u671f\u8f93\u51fa\uff1a<\/p>\n<p><img decoding=\"async\" title=\"-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/221a36dce27ff8e.jpg\" alt=\"-1\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>\u8bbe\u7f6e Crew,\u5b8c\u6210\u4e86\uff01\u2705<\/p>\n<p>\u542f\u52a8\u5b83\uff01\ud83d\ude80<\/p>\n<p><img decoding=\"async\" title=\"-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/b2eea223f2e990f.jpg\" alt=\"-1\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>\u90e8\u7f72\u6559\u7a0b<\/h2>\n<h3>AI \u65b0\u95fb\u751f\u6210\u5668<\/h3>\n<p>\u8be5\u9879\u76ee\u5229\u7528 CrewAI \u548c Cohere \u7684 Command-R:7B \u6a21\u578b\u6784\u5efa\u4e86\u4e00\u4e2a AI \u65b0\u95fb\u751f\u6210\u5668\uff01<\/p>\n<h3>\u5b89\u88c5\u4e0e\u8bbe\u7f6e<\/h3>\n<p><strong>\u83b7\u53d6 API \u5bc6\u94a5<\/strong>\uff1a<\/p>\n<ul>\n<li><a href=\"https:\/\/serper.dev\/\">Serper API \u5bc6\u94a5<\/a><\/li>\n<li><a href=\"https:\/\/dashboard.cohere.com\/api-keys\">Cohere API \u5bc6\u94a5<\/a><\/li>\n<\/ul>\n<p><strong>\u5b89\u88c5\u4f9d\u8d56\u9879<\/strong>\uff1a<br \/>\n\u786e\u4fdd\u60a8\u5df2\u5b89\u88c5 Python 3.11 \u6216\u66f4\u9ad8\u7248\u672c\u3002<\/p>\n<pre><code>pip install crewai crewai-tools\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p><strong>.env.example<\/strong><\/p>\n<pre>SERPER_API_KEY=your_serper_api_key\r\nCOHERE_API_KEY=your_cohere_apikey<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>app.py<\/strong><\/p>\n<pre>import os\r\nimport streamlit as st\r\nfrom crewai import Agent, Task, Crew, LLM\r\nfrom crewai_tools import SerperDevTool\r\nfrom dotenv import load_dotenv\r\n\r\n# Load environment variables\r\nload_dotenv()\r\n\r\n# Streamlit page config\r\nst.set_page_config(page_title=\"AI News Generator\", page_icon=\"\ud83d\udcf0\", layout=\"wide\")\r\n\r\n# Title and description\r\nst.title(\"\ud83e\udd16 AI News Generator, powered by CrewAI and Cohere's <a href=\"https:\/\/www.kdjingpai.com\/en\/cohere\/\">Command<\/a> R7B\")\r\nst.markdown(\"Generate comprehensive blog posts about any topic using AI agents.\")\r\n\r\n# Sidebar\r\nwith st.sidebar:\r\nst.header(\"Content Settings\")\r\n\r\n# Make the text input take up more space\r\ntopic = st.text_area(\r\n\"Enter your topic\",\r\nheight=100,\r\nplaceholder=\"Enter the topic you want to generate content about...\"\r\n)\r\n\r\n# Add more sidebar controls if needed\r\nst.markdown(\"### Advanced Settings\")\r\ntemperature = st.slider(\"Temperature\", 0.0, 1.0, 0.7)\r\n\r\n# Add some spacing\r\nst.markdown(\"---\")\r\n\r\n# Make the generate button more prominent in the sidebar\r\ngenerate_button = st.button(\"Generate Content\", type=\"primary\", use_container_width=True)\r\n\r\n# Add some helpful information\r\nwith st.expander(\"\u2139\ufe0f How to use\"):\r\nst.markdown(\"\"\"\r\n1. Enter your desired topic in the text area above\r\n2. Adjust the temperature if needed (higher = more creative)\r\n3. Click 'Generate Content' to start\r\n4. Wait for the AI to generate your article\r\n5. Download the result as a markdown file\r\n\"\"\")\r\n\r\ndef generate_content(topic):\r\nllm = LLM(\r\nmodel=\"command-r\",\r\ntemperature=0.7\r\n)\r\n\r\nsearch_tool = SerperDevTool(n_results=10)\r\n\r\n# First Agent: Senior Research Analyst\r\nsenior_research_analyst = Agent(\r\nrole=\"Senior Research Analyst\",\r\ngoal=f\"Research, analyze, and synthesize comprehensive information on {topic} from reliable web sources\",\r\nbackstory=\"You're an expert research analyst with advanced web research skills. \"\r\n\"You excel at finding, analyzing, and synthesizing information from \"\r\n\"across the internet using search tools. You're skilled at \"\r\n\"distinguishing reliable sources from unreliable ones, \"\r\n\"fact-checking, cross-referencing information, and \"\r\n\"identifying key patterns and insights. You provide \"\r\n\"well-organized research briefs with proper citations \"\r\n\"and source verification. Your analysis includes both \"\r\n\"raw data and interpreted insights, making complex \"\r\n\"information accessible and actionable.\",\r\nallow_delegation=False,\r\nverbose=True,\r\ntools=[search_tool],\r\nllm=llm\r\n)\r\n\r\n# Second Agent: Content Writer\r\ncontent_writer = Agent(\r\nrole=\"Content Writer\",\r\ngoal=\"Transform research findings into engaging blog posts while maintaining accuracy\",\r\nbackstory=\"You're a skilled content writer specialized in creating \"\r\n\"engaging, accessible content from technical research. \"\r\n\"You work closely with the Senior Research Analyst and excel at maintaining the perfect \"\r\n\"balance between informative and entertaining writing, \"\r\n\"while ensuring all facts and citations from the research \"\r\n\"are properly incorporated. You have a talent for making \"\r\n\"complex topics approachable without oversimplifying them.\",\r\nallow_delegation=False,\r\nverbose=True,\r\nllm=llm\r\n)\r\n\r\n# Research Task\r\nresearch_task = Task(\r\ndescription=(\"\"\"\r\n1. Conduct comprehensive research on {topic} including:\r\n- Recent developments and news\r\n- Key industry trends and innovations\r\n- Expert opinions and analyses\r\n- Statistical data and market insights\r\n2. Evaluate source credibility and fact-check all information\r\n3. Organize findings into a structured research brief\r\n4. Include all relevant citations and sources\r\n\"\"\"),\r\nexpected_output=\"\"\"A detailed research report containing:\r\n- Executive summary of key findings\r\n- Comprehensive analysis of current trends and developments\r\n- List of verified facts and statistics\r\n- All citations and links to original sources\r\n- Clear categorization of main themes and patterns\r\nPlease format with clear sections and bullet points for easy reference.\"\"\",\r\nagent=senior_research_analyst\r\n)\r\n\r\n# Writing Task\r\nwriting_task = Task(\r\ndescription=(\"\"\"\r\nUsing the research brief provided, create an engaging blog post that:\r\n1. Transforms technical information into accessible content\r\n2. Maintains all factual accuracy and citations from the research\r\n3. Includes:\r\n- Attention-grabbing introduction\r\n- Well-structured body sections with clear headings\r\n- Compelling conclusion\r\n4. Preserves all source citations in [Source: URL] format\r\n5. Includes a References section at the end\r\n\"\"\"),\r\nexpected_output=\"\"\"A polished blog post in markdown format that:\r\n- Engages readers while maintaining accuracy\r\n- Contains properly structured sections\r\n- Includes Inline citations hyperlinked to the original source url\r\n- Presents information in an accessible yet informative way\r\n- Follows proper markdown formatting, use H1 for the title and H3 for the sub-sections\"\"\",\r\nagent=content_writer\r\n)\r\n\r\n# Create Crew\r\ncrew = Crew(\r\nagents=[senior_research_analyst, content_writer],\r\ntasks=[research_task, writing_task],\r\nverbose=True\r\n)\r\n\r\nreturn crew.kickoff(inputs={\"topic\": topic})\r\n\r\n# Main content area\r\nif generate_button:\r\nwith st.spinner('Generating content... This may take a moment.'):\r\ntry:\r\nresult = generate_content(topic)\r\nst.markdown(\"### Generated Content\")\r\nst.markdown(result)\r\n\r\n# Add download button\r\nst.download_button(\r\nlabel=\"Download Content\",\r\ndata=result.raw,\r\nfile_name=f\"{topic.lower().replace(' ', '_')}_article.md\",\r\nmime=\"text\/markdown\"\r\n)\r\nexcept Exception as e:\r\nst.error(f\"An error occurred: {str(e)}\")\r\n\r\n# Footer\r\nst.markdown(\"---\")\r\nst.markdown(\"Built with CrewAI, Streamlit and powered by Cohere's Command R7B\")<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u4e8e CrewAI \u591a\u667a\u80fd\u4f53\u534f\u4f5c\u548c Cohere Command-R7B \u5927\u6a21\u578b\uff0c\u7cfb\u7edf\u80fd\u81ea\u52a8\u5b8c\u6210\u4ece\u7814\u7a76\u5230\u5199\u4f5c\u7684\u5168\u6d41\u7a0b\uff0c\u50cf\u62e5\u6709\u4e00\u4e2a 24 \u5c0f\u65f6\u8fd0\u8f6c\u7684\u65b0\u95fb\u5de5\u4f5c\u5ba4 &nbsp; \u6838\u5fc3\u529f\u80fd\uff1a \u7814\u7a76\u5206\u6790\uff1a\u7531\u7b2c\u4e00\u4e2a AI \u52a9\u624b\u8d1f\u8d23\u641c\u7d22\u548c\u6574\u7406\u4e0e\u8bdd\u9898\u76f8\u5173\u7684&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182],"tags":[],"class_list":["post-15787","post","type-post","status-publish","format-standard","hentry","category-shicao"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts\/15787","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/comments?post=15787"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts\/15787\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/media?parent=15787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/categories?post=15787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/tags?post=15787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}