File size: 5,997 Bytes
45f00f2 | 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 | {
"cells": [
{
"cell_type": "code",
"execution_count": 42,
"id": "2946f394",
"metadata": {},
"outputs": [],
"source": [
"from langchain.agents import create_agent\n",
"from dotenv import load_dotenv\n",
"from langchain_groq import ChatGroq\n",
"from langchain_core.messages import BaseMessage, HumanMessage\n",
"\n",
"load_dotenv()\n",
"\n",
"llm = ChatGroq(\n",
" model=\"qwen/qwen3-32b\",\n",
" temperature=0,\n",
" reasoning_format=\"parsed\",\n",
" streaming=True\n",
")\n",
"\n",
"\n",
"def get_weather(city: str) -> str:\n",
" \"\"\"Get weather for a given city.\"\"\"\n",
"\n",
" return f\"It's always sunny in {city}!\"\n",
"\n",
"tools = [get_weather]\n",
"agent = create_agent(llm, tools=tools)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "7ddafbda",
"metadata": {},
"outputs": [],
"source": [
"# for chunk in llm.stream(\n",
"# {\"messages\": [{\"role\": \"user\", \"content\": \"write 500 words eassy on AI\"}]}\n",
"# ):\n",
"# if chunk.get(\"model\"):\n",
"# print(chunk.get(\"model\").get(\"messages\")[0].content)"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "acd47304",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"**The Rise of Artificial Intelligence: Promise and Peril** \n",
"\n",
"Artificial Intelligence (AI), the simulation of human intelligence by machines, has emerged as one of the most transformative technologies of the 21st century. From streamlining industries to redefining daily life, AI’s influence is pervasive. However, its rapid advancement also raises critical questions about ethics, employment, and societal impact. As we navigate this dual-edged revolution, understanding AI’s potential and pitfalls is essential for shaping a future that balances innovation with responsibility. \n",
"\n",
"AI’s applications span nearly every sector. In healthcare, machine learning algorithms analyze medical data to detect diseases like cancer with unprecedented accuracy, while robotic surgery systems enhance precision in operations. In education, AI-powered platforms personalize learning, adapting to individual student needs and bridging gaps in traditional teaching methods. The financial industry leverages AI for fraud detection, risk management, and algorithmic trading, optimizing decisions in milliseconds. Even creative fields, such as music and art, now incorporate AI tools that generate original content, challenging notions of human creativity. These advancements underscore AI’s capacity to augment human capabilities, driving efficiency and innovation. \n",
"\n",
"Yet, the rise of AI is not without challenges. One of the most pressing concerns is job displacement. Automation threatens industries reliant on repetitive tasks, from manufacturing to customer service, potentially exacerbating economic inequality. While new roles in AI development and maintenance are emerging, the transition may leave many workers behind, necessitating robust reskilling initiatives. Additionally, biases embedded in AI systems—often reflecting historical prejudices in training data—can perpetuate discrimination in areas like hiring, lending, and law enforcement. Addressing these biases requires diverse, inclusive datasets and transparent algorithms. \n",
"\n",
"Ethical dilemmas further complicate AI’s trajectory. Autonomous weapons, for instance, raise moral questions about delegating life-and-death decisions to machines. Privacy concerns intensify as AI analyzes vast amounts of personal data, often without explicit consent. The 2023 EU AI Act, which classifies AI systems by risk level and imposes strict regulations on high-risk applications, reflects growing global efforts to establish ethical frameworks. However, enforcement remains inconsistent, highlighting the need for international collaboration to prevent misuse. \n",
"\n",
"The future of AI hinges on striking a balance between innovation and accountability. Governments, corporations, and academia must collaborate to develop policies that prioritize human welfare. Investments in AI literacy and education will empower individuals to adapt to technological shifts, while ethical AI design—centered on fairness, transparency, and privacy—can mitigate risks. Public dialogue is equally vital, ensuring that diverse perspectives shape AI’s evolution. \n",
"\n",
"In conclusion, AI represents both a remarkable opportunity and a profound responsibility. Its ability to solve complex problems and enhance human potential is undeniable, but unchecked, it risks amplifying societal divides and ethical crises. By fostering inclusive, ethical development, we can harness AI as a tool for collective progress rather than a source of division. The choices we make today will determine whether AI becomes a force for good—or a harbinger of unintended consequences."
]
}
],
"source": [
"for chunk in llm.stream(\n",
" [{\"role\": \"user\", \"content\": \"write 500 words essay on AI\"}]\n",
"):\n",
" if chunk.content:\n",
" print(chunk.content, end=\"\", flush=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bf450c3d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|