File size: 4,225 Bytes
fe6b125 3caf785 fe6b125 ceafe94 da35894 0ae6627 18cbe29 da35894 eeb5bed da35894 3a5bbff da35894 2651e12 0ae6627 da35894 2651e12 db1cd9b 11acf98 da35894 fe6b125 da35894 db1cd9b da35894 fe6b125 3caf785 9e6c18e eeb44aa 9e6c18e fe6b125 29786ae 0864565 29786ae 0864565 29786ae 0864565 29786ae fdb5b3d 3177144 fe6b125 0864565 da35894 3177144 da35894 3177144 3e95a64 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
#####################################
##
#####################################
from langchain_community.llms import HuggingFaceHub
#from langchain_community.llms import HuggingFaceHub
llm_zephyr_7b_beta = HuggingFaceHub(
repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1",
task="text-generation",
model_kwargs={
"max_new_tokens": 1000,
"top_k": 2,
"temperature": 0.1,
"repetition_penalty": 1.03,
},
)
import os
from crewai import Agent, Task, Crew, Process
from crewai_tools.tools import SerperDevTool
#from crewai_tools import SerperDevTool
search_tool = SerperDevTool()
# Define your agents with roles and goals
researcher = Agent(
role='Senior Research Analyst',
goal='Uncover cutting-edge developments in AI and data science',
backstory="""You work at a leading tech think tank.
Your expertise lies in identifying emerging trends.
You have a knack for dissecting complex data and presenting actionable insights.""",
verbose=True,
allow_delegation=False,
tools=[search_tool],
max_execution_time=120,
max_iter=50, # Optional
max_rpm=25, # Optional
llm=llm_zephyr_7b_beta
# You can pass an optional llm attribute specifying what mode you wanna use.
# It can be a local model through Ollama / LM Studio or a remote
# model like OpenAI, Mistral, Antrophic or others (https://docs.crewai.com/how-to/LLM-Connections/)
#
# import os
# os.environ['OPENAI_MODEL_NAME'] = 'gpt-3.5-turbo'
#
# OR
#
# from langchain_openai import ChatOpenAI
# llm=ChatOpenAI(model_name="gpt-3.5", temperature=0.7)
)
writer = Agent(
role='Tech Content Strategist',
goal='Craft compelling content on tech advancements',
backstory="""You are a renowned Content Strategist, known for your insightful and engaging articles.
You transform complex concepts into compelling narratives.""",
verbose=True,
max_execution_time=120,
max_iter=50, # Optional
max_rpm=25, # Optional
allow_delegation=False,
llm=llm_zephyr_7b_beta
)
# Create tasks for your agents
task1 = Task(
description="""Conduct a comprehensive analysis of the latest advancements in AI in 2024.
Identify key trends, breakthrough technologies, and potential industry impacts.""",
expected_output="Full analysis report in bullet points",
agent=researcher
)
task2 = Task(
description="""Using the insights provided, develop an engaging blog
post that highlights the most significant AI advancements.
Your post should be informative yet accessible, catering to a tech-savvy audience.
Make it sound cool, avoid complex words so it doesn't sound like AI.""",
expected_output="Full blog post of at least 4 paragraphs",
agent=writer
)
# Instantiate your crew with a sequential process
crew = Crew(
agents=[researcher, writer],
tasks=[task1, task2],
verbose=1, # You can set it to 1 or 2 to different logging levels
)
# Get your crew to work!
#result = crew.kickoff()
#print("######################")
#print(result)
##################
###### other models:
# "Trelis/Llama-2-7b-chat-hf-sharded-bf16"
# "bn22/Mistral-7B-Instruct-v0.1-sharded"
# "HuggingFaceH4/zephyr-7b-beta"
# function for loading 4-bit quantized model
def load_model( ):
model = HuggingFaceHub(
repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1",
model_kwargs={"max_length": 1048, "temperature":0.2, "max_new_tokens":256, "top_p":0.95, "repetition_penalty":1.0},
)
return model
###############
#####
#####
#####
####
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
# middlewares to allow cross orgin communications
app.add_middleware(
CORSMiddleware,
allow_origins=['*'],
allow_credentials=True,
allow_methods=['*'],
allow_headers=['*'],
)
@app.post("/generate/")
def generate(user_input, history=[]):
print("######################")
result = crew.kickoff()
print("######################")
print(result)
return result
# load the model asynchronously on startup and save it into memory
@app.on_event("startup")
async def startup():
# Get your crew to work!
# result = crew.kickoff()
print("######################")
# print(result)
|