Ollama Function Calling Advanced - Make your Application Future Proof!
AI Summary
- Introduction to Olama function calling - Function calling with Olama runs locally - Compatible with OpenAI - Advanced function calling with Pantic and Instructor - Tutorial Overview - Step-by-step guide on implementing Olama function calling - Encourages subscribing to the YouTube channel for AI content - Installation Steps - Download AMA for your OS from the ol. website - Run `AMA pull llama` to download the model - Install packages with `pip install hyen u y Finance pantic instructor open AI`- Creating `app.py` - Import necessary libraries (requests, json, system, yfinance) - Define the goal: find stock prices by company name - Define schema for the expected JSON response (company name and ticker) - Define payload with model name and messages - Example: entering "Apple" should return JSON with "Apple" and "AAPL" ticker - Send request to Olama URL with payload - Parse JSON response to fetch stock price from Yahoo Finance - Print results with company name, ticker, and stock price - Running the Code - Execute `python app.py` in the terminal - Output displays JSON format with company name, ticker, and stock price - Addressing Inconsistencies - Issues with random errors and inconsistent JSON responses - Use of Pantic and Instructor for reliable JSON structure - Implementing Advanced Function Calling (`advanced.py`) - Import OpenAI, Pantic, Typing, Yahoo Finance, and Instructor - Define `StockInfo` class with Pantic for structured JSON response - Use Instructor to patch OpenAI API for consistent results - Simplify request to just one line with schema in `StockInfo` - Fetch and print stock price using Yahoo Ticker - Run `python advanced.py` for reliable output - Conclusion - Advanced method with Pantic and Instructor is more reliable - Encouragement to like, share, subscribe for more videos