{"id":27046755,"url":"https://github.com/jwalsh/sg-ai-dev-tools","last_synced_at":"2026-05-09T04:31:57.354Z","repository":{"id":286154964,"uuid":"960542358","full_name":"jwalsh/sg-ai-dev-tools","owner":"jwalsh","description":"Study group resources for AI development tools, focusing on LLMs, GenAI, and Agent architectures including Model Context Protocol (MCP)","archived":false,"fork":false,"pushed_at":"2025-04-04T16:17:43.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-31T00:40:27.066Z","etag":null,"topics":["agents","ai","ai-development","fine-tuning","genai","langchain","llm","model-context-protocol","rag","study-group"],"latest_commit_sha":null,"homepage":"https://wal.sh/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jwalsh.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-04-04T16:03:31.000Z","updated_at":"2025-04-04T16:17:47.000Z","dependencies_parsed_at":"2025-04-04T17:36:51.510Z","dependency_job_id":null,"html_url":"https://github.com/jwalsh/sg-ai-dev-tools","commit_stats":null,"previous_names":["jwalsh/sg-ai-dev-tools"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jwalsh/sg-ai-dev-tools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwalsh%2Fsg-ai-dev-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwalsh%2Fsg-ai-dev-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwalsh%2Fsg-ai-dev-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwalsh%2Fsg-ai-dev-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwalsh","download_url":"https://codeload.github.com/jwalsh/sg-ai-dev-tools/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwalsh%2Fsg-ai-dev-tools/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32807179,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T08:22:46.396Z","status":"online","status_checked_at":"2026-05-09T02:00:06.633Z","response_time":123,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agents","ai","ai-development","fine-tuning","genai","langchain","llm","model-context-protocol","rag","study-group"],"created_at":"2025-04-05T06:17:50.047Z","updated_at":"2026-05-09T04:31:57.335Z","avatar_url":"https://github.com/jwalsh.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"#+TITLE: Study Group: AI Development Tools\n#+AUTHOR: Study Group\n#+DATE: [2025-04-10 Thu]\n#+OPTIONS: toc:3 num:3 ^:{}\n#+PROPERTY: header-args :results output :exports both\n#+STARTUP: showeverything\n\n* About This Resource Collection\n\nThis directory contains resources, code examples, and discussion materials related to modern AI development tools, particularly Generative AI, Large Language Models (LLMs), and AI Agents. These resources are intended to support self-study and collaborative learning in the field of AI.\n\n* Current Topics of Interest in AI Development\n\n** Model Context Protocol (MCP)\n\n*** What is MCP?\n\nModel Context Protocol (MCP) provides a standardized way for LLMs to interface with external tools, data, and other models. It establishes a common framework for context window management, allowing models to effectively use their context window with external information.\n\nKey components include:\n- A protocol for context exchange between models and their environments\n- Mechanisms for efficiently managing context windows\n- Standardized interfaces for tool use and external data retrieval\n\n*** Why is MCP Important?\n\n- *Standardization*: Creates a common interface across different model implementations\n- *Efficiency*: Enables more effective use of limited context windows\n- *Interoperability*: Allows different systems to work together more seamlessly\n- *Tool Integration*: Provides consistent ways to connect LLMs with external tools\n- *Enterprise Readiness*: Makes AI systems more controllable and predictable in business environments\n\n*** How to Implement MCP\n\n#+begin_src mermaid\ngraph TD\n    A[Model] \u003c--\u003e|Context Management Interface| B[Context Manager]\n    B \u003c--\u003e|Tool Interface| C[Tool Registry]\n    C --\u003e D[Tool 1: Web Search]\n    C --\u003e E[Tool 2: Code Execution]\n    C --\u003e F[Tool 3: Database Access]\n    B \u003c--\u003e|Memory Interface| G[Memory System]\n    B \u003c--\u003e|Context Processing| H[Input/Output Processor]\n    H \u003c--\u003e I[User Interface]\n\n    classDef model fill:#bfb,stroke:#333,stroke-width:2px;\n    classDef core fill:#f9f,stroke:#333,stroke-width:2px;\n    classDef tools fill:#fbb,stroke:#333,stroke-width:2px;\n    classDef ui fill:#bbf,stroke:#333,stroke-width:2px;\n\n    class A model;\n    class B,C,G,H core;\n    class D,E,F tools;\n    class I ui;\n#+end_src\n\n*Example MCP Implementation Approach:*\n\n1. Define context schema and management patterns\n2. Implement tool registration and calling mechanisms\n3. Create memory interfaces for context persistence\n4. Build context preprocessing and postprocessing capabilities\n5. Develop synchronization mechanisms for multi-model systems\n\n** GenAI Development Frameworks\n:PROPERTIES:\n:header-args:python: :session genai_frameworks :tangle src/genai_frameworks.py :mkdirp t\n:END:\n\n*** Key Frameworks for LLM Development\n\n**** LangChain\n\n#+begin_src python\nimport os\nfrom langchain.llms import OpenAI\nfrom langchain.chains import LLMChain\nfrom langchain.prompts import PromptTemplate\n\n# Example of using LangChain for a simple LLM interaction\ndef langchain_example():\n    # Set up the LLM\n    llm = OpenAI(temperature=0.7)\n    \n    # Create a prompt template\n    template = \"\"\"\n    You are a helpful AI assistant. The user asks: {question}\n    Your response:\n    \"\"\"\n    prompt = PromptTemplate(template=template, input_variables=[\"question\"])\n    \n    # Create a chain\n    chain = LLMChain(llm=llm, prompt=prompt)\n    \n    # Run the chain\n    response = chain.run(question=\"What are practical applications of AI in healthcare?\")\n    print(response)\n    \n    return response\n#+end_src\n\n**** LlamaIndex\n\n#+begin_src python\nfrom llama_index import SimpleDirectoryReader, GPTVectorStoreIndex, LLMPredictor\nfrom langchain.llms import OpenAI\n\n# Example of using LlamaIndex for document-based question answering\ndef llamaindex_example():\n    # Load documents\n    documents = SimpleDirectoryReader('data').load_data()\n    \n    # Initialize predictor with OpenAI\n    llm_predictor = LLMPredictor(llm=OpenAI(temperature=0))\n    \n    # Create index\n    index = GPTVectorStoreIndex.from_documents(\n        documents, llm_predictor=llm_predictor\n    )\n    \n    # Query the index\n    query_engine = index.as_query_engine()\n    response = query_engine.query(\"What are the key findings in the report?\")\n    print(response)\n    \n    return response\n#+end_src\n\n**** Semantic Kernel\n\n#+begin_src python\nimport semantic_kernel as sk\nfrom semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion\n\n# Example of using Semantic Kernel\ndef semantic_kernel_example():\n    # Initialize the kernel\n    kernel = sk.Kernel()\n    \n    # Add OpenAI service\n    kernel.add_chat_service(\"chat-gpt\", OpenAIChatCompletion(\"gpt-4\", \"your-api-key\"))\n    \n    # Create semantic function\n    prompt = \"\"\"\n    Summarize the following text in three bullet points:\n    {{$input}}\n    \"\"\"\n    \n    summarize = kernel.create_semantic_function(prompt)\n    \n    # Use the function\n    text = \"\"\"\n    Artificial intelligence has made significant strides in recent years.\n    Machine learning models can now perform tasks that were once thought\n    to require human intelligence. This progress has led to applications\n    in healthcare, finance, transportation, and many other fields.\n    \"\"\"\n    \n    result = summarize(text)\n    print(result)\n    \n    return result\n#+end_src\n\n** Agent Architecture and Systems\n:PROPERTIES:\n:header-args:python: :session agents :tangle src/agents.py :mkdirp t\n:END:\n\n*** Agent Frameworks and Tools\n\n**** CrewAI\n\n#+begin_src python\nfrom crewai import Agent, Task, Crew\nfrom langchain.llms import OpenAI\n\ndef crewai_example():\n    # Initialize the language model\n    llm = OpenAI(temperature=0.7)\n    \n    # Create agents with different roles\n    researcher = Agent(\n        role=\"Research Analyst\",\n        goal=\"Find comprehensive information on AI development tools\",\n        backstory=\"You are an expert research analyst with expertise in AI technologies\",\n        llm=llm\n    )\n    \n    writer = Agent(\n        role=\"Technical Writer\",\n        goal=\"Create clear and concise documentation about AI tools\",\n        backstory=\"You are a skilled technical writer who excels at explaining complex topics\",\n        llm=llm\n    )\n    \n    # Create tasks for the agents\n    research_task = Task(\n        description=\"Research the latest developments in LLM frameworks\",\n        agent=researcher\n    )\n    \n    writing_task = Task(\n        description=\"Write a comprehensive guide based on the research findings\",\n        agent=writer,\n        dependencies=[research_task]\n    )\n    \n    # Create the crew\n    crew = Crew(\n        agents=[researcher, writer],\n        tasks=[research_task, writing_task],\n        verbose=True\n    )\n    \n    # Start the process\n    result = crew.kickoff()\n    \n    return result\n#+end_src\n\n**** LangGraph\n\n#+begin_src python\nfrom langgraph.graph import Graph, StateBuilder\nfrom langchain.chat_models import ChatOpenAI\nfrom langchain.schema import SystemMessage, HumanMessage\n\n# Example of a basic LangGraph implementation\ndef langgraph_example():\n    # Define state\n    state_builder = StateBuilder()\n    state_builder.add(\"messages\", list)\n    state_builder.add(\"current_step\", str)\n    \n    # Initialize LLM\n    llm = ChatOpenAI(temperature=0)\n    \n    # Define nodes\n    def research_node(state):\n        messages = [\n            SystemMessage(content=\"You are a research assistant. Find key information.\"),\n            HumanMessage(content=\"Research quantum computing applications.\")\n        ]\n        response = llm.invoke(messages)\n        state[\"messages\"].append(response)\n        state[\"current_step\"] = \"analysis\"\n        return state\n    \n    def analysis_node(state):\n        messages = state[\"messages\"] + [\n            SystemMessage(content=\"Analyze the research and identify trends.\"),\n            HumanMessage(content=\"What are the emerging trends?\")\n        ]\n        response = llm.invoke(messages)\n        state[\"messages\"].append(response)\n        state[\"current_step\"] = \"complete\"\n        return state\n    \n    # Define the graph\n    graph = Graph()\n    graph.add_node(\"research\", research_node)\n    graph.add_node(\"analysis\", analysis_node)\n    \n    # Add edges\n    graph.add_edge(\"research\", \"analysis\")\n    \n    # Set entry point\n    graph.set_entry_point(\"research\")\n    \n    return graph\n#+end_src\n\n**** AutoGen\n\n#+begin_src python\nfrom autogen import AssistantAgent, UserProxyAgent, config_list_from_json\n\ndef autogen_example():\n    # Configure LLM\n    config_list = config_list_from_json(\n        \"OAI_CONFIG_LIST\",\n        filter_dict={\"model\": [\"gpt-4\"]}\n    )\n    \n    # Create an assistant agent\n    assistant = AssistantAgent(\n        name=\"AI_Assistant\",\n        llm_config={\"config_list\": config_list},\n        system_message=\"You are a helpful AI assistant with expertise in programming and data analysis.\"\n    )\n    \n    # Create a user proxy agent\n    user_proxy = UserProxyAgent(\n        name=\"User_Proxy\",\n        human_input_mode=\"TERMINATE\",\n        max_consecutive_auto_reply=10,\n        is_termination_msg=lambda x: x.get(\"content\", \"\").rstrip().endswith(\"TERMINATE\"),\n        code_execution_config={\"work_dir\": \"coding\", \"use_docker\": False}\n    )\n    \n    # Start the conversation with a task\n    user_proxy.initiate_chat(\n        assistant,\n        message=\"Write a Python script to perform sentiment analysis on a dataset of customer reviews.\"\n    )\n    \n    return \"AutoGen example completed\"\n#+end_src\n\n** Retrieval Augmented Generation (RAG)\n:PROPERTIES:\n:header-args:python: :session rag :tangle src/rag_examples.py :mkdirp t\n:END:\n\n*** RAG System Architectures\n\n#+begin_src mermaid\ngraph TD\n    A[Documents] --\u003e B[Text Chunking]\n    B --\u003e C[Embedding Generation]\n    C --\u003e D[Vector Database]\n    \n    E[User Query] --\u003e F[Query Understanding]\n    F --\u003e G[Query Transformation]\n    \n    G --\u003e H[Vector Search]\n    D --\u003e H\n    \n    H --\u003e I[Context Selection \u0026 Ranking]\n    I --\u003e J[Context Integration]\n    \n    E --\u003e K[LLM]\n    J --\u003e K\n    K --\u003e L[Response]\n    \n    M[Feedback Loop] --\u003e N[Evaluation]\n    L --\u003e N\n    N --\u003e M\n\n    classDef process fill:#f9f,stroke:#333,stroke-width:2px;\n    classDef data fill:#bbf,stroke:#333,stroke-width:2px;\n    classDef model fill:#bfb,stroke:#333,stroke-width:2px;\n    classDef feedback fill:#fbb,stroke:#333,stroke-width:2px;\n\n    class A,D,E,L data;\n    class B,C,F,G,H,I,J process;\n    class K model;\n    class M,N feedback;\n#+end_src\n\n*** Advanced RAG Techniques\n\n#+begin_src python\ndef advanced_rag_techniques():\n    \"\"\"\n    Modern RAG architectures and advanced techniques:\n    \n    1. Hybrid Search:\n       - Combine sparse (BM25, keyword) and dense (semantic) retrieval\n       - Merge results using custom re-ranking algorithms\n    \n    2. Multi-vector Retrieval:\n       - Represent documents with multiple embeddings\n       - Child-parent relationships between chunks\n       - Sentence, paragraph, and document-level embeddings\n    \n    3. Query Transformation:\n       - HyDE (Hypothetical Document Embeddings)\n       - Query expansion and reformulation\n       - Multi-query generation\n    \n    4. Recursive RAG:\n       - Generate sub-queries from main query\n       - Perform multiple retrieval steps\n       - Synthesize information across retrievals\n    \n    5. Contextual Compression:\n       - Extract only relevant sentences from retrieved documents\n       - Remove redundancy across retrieved passages\n       - Map-reduce over large document sets\n    \n    6. Self-correcting RAG:\n       - Hallucination detection\n       - RAG with cross-checking and verification\n       - Incorporating metadata for factuality\n    \n    7. Multimodal RAG:\n       - Incorporate images, audio, and video\n       - Cross-modal retrieval techniques\n       - Multi-encoder approaches\n    \"\"\"\n    \n    return {\n        \"techniques\": [\n            \"Hybrid Search\",\n            \"Multi-vector Retrieval\",\n            \"Query Transformation\",\n            \"Recursive RAG\",\n            \"Contextual Compression\",\n            \"Self-correcting RAG\",\n            \"Multimodal RAG\"\n        ]\n    }\n#+end_src\n\n*** Implementing RAG with LlamaIndex\n\n#+begin_src python\nfrom llama_index import VectorStoreIndex, SimpleDirectoryReader\nfrom llama_index.indices.postprocessor import SentenceTransformerRerank\nfrom llama_index.query_engine import RetrieverQueryEngine\nfrom llama_index.retrievers import VectorIndexRetriever\nfrom llama_index.schema import Node\nfrom llama_index.llms import OpenAI\n\ndef advanced_llamaindex_rag():\n    # Load documents\n    documents = SimpleDirectoryReader(\"./data\").load_data()\n    \n    # Create index\n    index = VectorStoreIndex.from_documents(documents)\n    \n    # Configure retriever with hybrid search\n    retriever = VectorIndexRetriever(\n        index=index,\n        similarity_top_k=10,  # Retrieve more candidates for reranking\n        service_context=None\n    )\n    \n    # Add reranker for better precision\n    reranker = SentenceTransformerRerank(\n        model=\"cross-encoder/ms-marco-MiniLM-L-12-v2\",\n        top_n=3  # Keep only top 3 after reranking\n    )\n    \n    # Create the query engine with the retriever and reranker\n    query_engine = RetrieverQueryEngine.from_args(\n        retriever=retriever,\n        node_postprocessors=[reranker],\n        llm=OpenAI(model=\"gpt-4\")\n    )\n    \n    # Example query\n    response = query_engine.query(\n        \"What are the environmental impacts of blockchain technology?\"\n    )\n    \n    return response\n#+end_src\n\n** Evaluation Frameworks and Techniques\n:PROPERTIES:\n:header-args:python: :session eval :tangle src/evaluation.py :mkdirp t\n:END:\n\n*** Evaluating LLM Systems\n\n**** RAGAS for RAG Evaluation\n\n#+begin_src python\nfrom ragas.metrics import (\n    faithfulness,\n    answer_relevancy,\n    context_precision,\n    context_recall\n)\nfrom datasets import Dataset\n\ndef ragas_evaluation_example():\n    # Sample data\n    data = {\n        \"question\": [\n            \"What are the key features of our product?\",\n            \"How does our pricing compare to competitors?\"\n        ],\n        \"answer\": [\n            \"Our product features AI-powered analytics, real-time monitoring, and intuitive dashboards.\",\n            \"Our pricing is subscription-based starting at $49/month, which is 20% lower than the industry average.\"\n        ],\n        \"contexts\": [\n            [\n                \"The product includes advanced AI analytics capabilities.\",\n                \"Real-time monitoring allows instant alerts.\",\n                \"The intuitive dashboard provides visualization of all metrics.\"\n            ],\n            [\n                \"Subscription plans start at $49 per month for basic features.\",\n                \"The industry average pricing for similar tools is approximately $60 per month.\",\n                \"Enterprise plans are customized based on specific needs.\"\n            ]\n        ],\n        \"ground_truths\": [\n            [\n                \"The product's key features are AI analytics, real-time monitoring, and interactive dashboards.\"\n            ],\n            [\n                \"Our pricing starts at $49/month, which is lower than competitors who average $60/month.\"\n            ]\n        ]\n    }\n    \n    # Create dataset\n    dataset = Dataset.from_dict(data)\n    \n    # Calculate metrics\n    result = {\n        \"faithfulness\": faithfulness.compute(dataset),\n        \"answer_relevancy\": answer_relevancy.compute(dataset),\n        \"context_precision\": context_precision.compute(dataset),\n        \"context_recall\": context_recall.compute(dataset)\n    }\n    \n    return result\n#+end_src\n\n**** LangSmith for End-to-End Evaluation\n\n#+begin_src python\nfrom langchain.smith import RunEvalConfig\nfrom langchain.evaluation import load_evaluator\nfrom langchain.evaluation.criteria import CriteriaEvaluator\n\ndef langsmith_evaluation_example():\n    # Define evaluation criteria\n    criteria = {\n        \"correctness\": \"Does the response correctly answer the query?\",\n        \"coherence\": \"Is the response coherent and well-structured?\",\n        \"helpfulness\": \"Is the response helpful and does it address the user's need?\",\n        \"harmlessness\": \"Is the response free from harmful, unethical, or misleading content?\"\n    }\n    \n    # Create evaluator\n    evaluator = load_evaluator(\"criteria\", criteria=criteria)\n    \n    # Example evaluation config\n    eval_config = RunEvalConfig(\n        evaluators=[\n            \"qa\",  # Question-answering correctness\n            \"context_faithfulness\",  # Checks if response is supported by context\n            evaluator  # Custom criteria evaluator\n        ]\n    )\n    \n    # In production, would run:\n    # eval_results = run_on_dataset(\n    #     dataset_name=\"my_eval_dataset\",\n    #     llm_or_chain=my_chain,\n    #     evaluation=eval_config\n    # )\n    \n    return {\"eval_config\": eval_config, \"criteria\": criteria}\n#+end_src\n\n*** Metrics for AI System Evaluation\n\n#+begin_src python\ndef key_evaluation_metrics():\n    \"\"\"\n    Important metrics for evaluating GenAI systems:\n    \n    1. Accuracy Metrics:\n       - Factual accuracy\n       - Semantic accuracy\n       - Task completion rate\n    \n    2. RAG-specific Metrics:\n       - Retrieval precision/recall\n       - Context relevance\n       - Faithfulness to sources\n       - Answer relevancy\n    \n    3. Agent Metrics:\n       - Tool selection accuracy\n       - Task success rate\n       - Reasoning quality\n       - Efficiency (steps to solution)\n    \n    4. User Experience Metrics:\n       - Helpfulness\n       - Coherence\n       - Clarity\n       - Response time\n    \n    5. Safety Metrics:\n       - Harmlessness\n       - Ethical alignment\n       - Bias detection\n       - Refusal appropriateness\n    \n    6. Business Metrics:\n       - Cost per interaction\n       - User satisfaction\n       - Time saved vs. baseline\n       - Error reduction rate\n    \"\"\"\n    \n    return {\n        \"categories\": [\n            \"Accuracy Metrics\",\n            \"RAG-specific Metrics\",\n            \"Agent Metrics\",\n            \"User Experience Metrics\",\n            \"Safety Metrics\",\n            \"Business Metrics\"\n        ]\n    }\n#+end_src\n\n** Fine-tuning and Adaptation Techniques\n:PROPERTIES:\n:header-args:python: :session finetuning :tangle src/finetuning.py :mkdirp t\n:END:\n\n*** Approaches to Model Adaptation\n\n#+begin_src python\ndef model_adaptation_techniques():\n    \"\"\"\n    Techniques for adapting LLMs to specific use cases:\n    \n    1. Full Fine-tuning:\n       - Update all model weights\n       - Requires significant data and compute\n       - Best for major behavior changes\n    \n    2. Parameter-Efficient Fine-tuning (PEFT):\n       - LoRA (Low-Rank Adaptation)\n       - QLoRA (Quantized LoRA)\n       - Prefix tuning\n       - Prompt tuning\n       - Adapter layers\n    \n    3. Instruction Tuning:\n       - Format data as instructions\n       - Focus on following specific direction types\n       - Can be combined with PEFT methods\n    \n    4. Context Learning:\n       - Few-shot learning in context\n       - In-context learning (ICL)\n       - Retrieval-augmented generation\n    \n    5. Prompt Engineering:\n       - System prompts\n       - Chain-of-thought prompting\n       - Tree-of-thought techniques\n       - Self-consistency methods\n    \"\"\"\n    \n    return {\n        \"categories\": [\n            \"Full Fine-tuning\",\n            \"Parameter-Efficient Fine-tuning (PEFT)\",\n            \"Instruction Tuning\",\n            \"Context Learning\",\n            \"Prompt Engineering\"\n        ]\n    }\n#+end_src\n\n*** LoRA Implementation Example\n\n#+begin_src python\nfrom datasets import load_dataset\nfrom transformers import AutoModelForCausalLM, AutoTokenizer, TrainingArguments\nfrom peft import LoraConfig, get_peft_model, prepare_model_for_kbit_training\nimport torch\n\ndef lora_finetuning_example():\n    # 1. Load base model\n    model_name = \"meta-llama/Llama-2-7b-hf\"\n    model = AutoModelForCausalLM.from_pretrained(\n        model_name,\n        load_in_8bit=True,\n        device_map=\"auto\",\n        trust_remote_code=True\n    )\n    tokenizer = AutoTokenizer.from_pretrained(model_name)\n    \n    # 2. Prepare model for LoRA training\n    model = prepare_model_for_kbit_training(model)\n    \n    # 3. Configure LoRA\n    lora_config = LoraConfig(\n        r=16,                    # Rank of update matrices\n        lora_alpha=32,           # LoRA scaling factor\n        target_modules=[\"q_proj\", \"v_proj\", \"k_proj\", \"o_proj\"],  # Which modules to apply LoRA to\n        lora_dropout=0.05,       # Dropout probability for LoRA layers\n        bias=\"none\",             # Don't add bias parameters\n        task_type=\"CAUSAL_LM\"    # Task type\n    )\n    \n    # 4. Apply LoRA config to model\n    model = get_peft_model(model, lora_config)\n    \n    # 5. Define training arguments\n    training_args = TrainingArguments(\n        output_dir=\"./lora-llama2\",\n        per_device_train_batch_size=4,\n        gradient_accumulation_steps=4,\n        warmup_steps=100,\n        max_steps=1000,\n        learning_rate=2e-4,\n        fp16=True,\n        logging_steps=10,\n        save_steps=100,\n        evaluation_strategy=\"steps\",\n        eval_steps=100,\n    )\n    \n    # Note: In a real implementation, you would:\n    # 1. Prepare your dataset\n    # 2. Set up a data collator\n    # 3. Initialize a Trainer\n    # 4. Start the training process\n    # 5. Merge LoRA weights or use the adapter\n    \n    return {\n        \"model\": model_name,\n        \"lora_config\": {\n            \"r\": lora_config.r,\n            \"lora_alpha\": lora_config.lora_alpha,\n            \"target_modules\": lora_config.target_modules,\n        },\n        \"training_args\": {\n            \"batch_size\": training_args.per_device_train_batch_size,\n            \"learning_rate\": training_args.learning_rate,\n            \"max_steps\": training_args.max_steps\n        }\n    }\n#+end_src\n\n* Learning Resources\n\n** Documentation and Guides\n\n- LangChain Documentation: https://python.langchain.com/docs/get_started/introduction\n- LlamaIndex Documentation: https://docs.llamaindex.ai/en/stable/\n- CrewAI Documentation: https://docs.crewai.com/\n- AutoGen Documentation: https://microsoft.github.io/autogen/\n- Semantic Kernel Guide: https://learn.microsoft.com/en-us/semantic-kernel/\n- LangSmith Platform: https://docs.smith.langchain.com/\n- PEFT Documentation: https://huggingface.co/docs/peft/index\n\n** Tutorials and Courses\n\n- DeepLearning.AI Short Courses: https://www.deeplearning.ai/short-courses/\n- Hugging Face NLP Course: https://huggingface.co/learn/nlp-course/\n- Full Stack LLM Bootcamp: https://fullstackdeeplearning.com/llm-bootcamp/\n- LLM University by Cohere: https://docs.cohere.com/docs/llmu\n- Prompt Engineering Guide: https://www.promptingguide.ai/\n\n** Research Papers\n\n- \"Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks\" (Lewis et al., 2020)\n- \"Training Language Models to Follow Instructions\" (Ouyang et al., 2022)\n- \"LoRA: Low-Rank Adaptation of Large Language Models\" (Hu et al., 2021)\n- \"ReAct: Synergizing Reasoning and Acting in Language Models\" (Yao et al., 2022)\n- \"Chain-of-Thought Prompting Elicits Reasoning in Large Language Models\" (Wei et al., 2022)\n- \"Tree of Thoughts: Deliberate Problem Solving with Large Language Models\" (Yao et al., 2023)\n- \"QLoRA: Efficient Finetuning of Quantized LLMs\" (Dettmers et al., 2023)\n\n** Tools and Libraries\n\n- LangChain: https://github.com/langchain-ai/langchain\n- LlamaIndex: https://github.com/jerryjliu/llama_index\n- PEFT: https://github.com/huggingface/peft\n- CrewAI: https://github.com/joaomdmoura/crewAI\n- AutoGen: https://github.com/microsoft/autogen\n- LangGraph: https://github.com/langchain-ai/langgraph\n- RAGAS: https://github.com/explodinggradients/ragas\n- Semantic Kernel: https://github.com/microsoft/semantic-kernel\n\n** Community Resources\n\n- Hugging Face Community: https://huggingface.co/\n- LangChain Discord: https://discord.gg/langchain\n- MLOps Community: https://mlops.community/\n- AI Engineers Discord: https://discord.gg/aie\n- Papers with Code: https://paperswithcode.com/\n\n* Getting Started\n\nTo use the code examples in this repository:\n\n1. Clone this repository\n2. Set up a virtual environment\n3. Install dependencies:\n   ```bash\n   pip install -r requirements.txt\n   ```\n4. Run the examples:\n   ```bash\n   python -m src.rag_examples\n   ```\n\n** Environment Setup\n\nRequirements for running the examples:\n\n#+begin_src python\n# requirements.txt\nlangchain\u003e=0.1.0\nllama-index\u003e=0.8.54\nsemantic-kernel\u003e=0.3.0\ntransformers\u003e=4.36.0\npeft\u003e=0.6.0\nragas\u003e=0.0.18\ndatasets\u003e=2.14.0\nfaiss-cpu\u003e=1.7.4\ncrewai\u003e=0.28.0\nsentence-transformers\u003e=2.2.2\ntorch\u003e=2.0.0\nbitsandbytes\u003e=0.41.0\naccelerate\u003e=0.21.0\nopenai\u003e=1.3.0\nautogen\u003e=0.2.0\n#+end_src\n\n* Contributing\n\nThis is a collaborative resource. To contribute:\n\n1. Add your examples, notes, or resources\n2. Ensure code examples are well-documented\n3. Include requirements for any new dependencies\n4. Share your knowledge with the community\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwalsh%2Fsg-ai-dev-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwalsh%2Fsg-ai-dev-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwalsh%2Fsg-ai-dev-tools/lists"}