この記事では、phidata と Ollama ローカル LLM を使用して、Web 検索、財務分析、推論、検索拡張生成用の AI エージェントを作成する方法を検討します。コードはllama3.2モデルを使用しています。別のモデルを使用したい場合は、使用したいモデルをダウンロードし、コード内の model_id 変数を置き換える必要があります。
ファイダタとは何ですか?
エージェント システムを構築、出荷、監視するためのオープンソース プラットフォーム。
https://www.phidata.com/
オラマとは何ですか?
Ollama は、ローカル大規模言語モデル (LLM) の導入と使用を簡素化するように設計されたプラットフォームとツールセットです。
https://ollam.ai/
この記事では、llama3.2 モデルを使用します。
ollama pull llama3.2
紫外線とは何ですか?
Rust で書かれた、非常に高速な Python パッケージおよびプロジェクト マネージャー。
https://github.com/astral-sh/uv
UV を使用したくない場合は、UV の代わりに pip を使用できます。その場合、uv add の代わりに pip install を使用する必要があります。
UVのインストール方法
https://docs.astral.sh/uv/getting-started/installation/
プロジェクトフォルダーを作成する
pip を使用する場合は、プロジェクト フォルダーを作成する必要があります。
uv init phidata-ollama
依存関係のインストール
uv add phidata ollama duckduckgo-search yfinance pypdf lancedb tantivy sqlalchemy
この記事では、phidata と Ollama を使用して 5 つの AI エージェントを作成してみます。
注: 開始する前に、ollamserve を実行して、ollam サーバーが実行されていることを確認してください。
Web 検索エージェントを作成する
作成する最初のエージェントは、DuckDuckGo 検索エンジンを使用する Web 検索エージェントです。
from phi.agent import Agent from phi.model.ollama import Ollama from phi.tools.duckduckgo import DuckDuckGo model_id = "llama3.2" model = Ollama(id=model_id) web_agent = Agent( name="Web Agent", model=model, tools=[DuckDuckGo()], instructions=["Always include sources"], show_tool_calls=True, markdown=True, ) web_agent.print_response("Tell me about OpenAI Sora?", stream=True)
出力:
┏━ Message ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ┃ ┃ Tell me about OpenAI Sora? ┃ ┃ ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┏━ Response (12.0s) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ┃ ┃ ┃ ┃ • Running: duckduckgo_news(query=OpenAI Sora) ┃ ┃ ┃ ┃ OpenAI's Sora is a video-generating model that has been trained on ┃ ┃ copyrighted content, which has raised concerns about its legality. ┃ ┃ According to TechCrunch, it appears that OpenAI trained Sora on game ┃ ┃ content, which could be a problem. Additionally, MSN reported that the ┃ ┃ model doesn't feel like the game-changer it was supposed to be. ┃ ┃ ┃ ┃ In other news, Yahoo reported that when asked to generate gymnastics ┃ ┃ videos, Sora produces horrorshow videos with whirling and morphing ┃ ┃ limbs. A lawyer told ExtremeTech that it's "overwhelmingly likely" that ┃ ┃ copyrighted materials are included in Sora's training dataset. ┃ ┃ ┃ ┃ Geeky Gadgets reviewed OpenAI's Sora, stating that while it is included ┃ ┃ in the 0/month Pro Plan, its standalone value for video generation ┃ ┃ is less clear compared to other options. ┃ ┃ ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
財務エージェントを作成する
作成する 2 番目のエージェントは、yfinance ツールを使用する金融エージェントです。
from phi.agent import Agent from phi.model.ollama import Ollama from phi.tools.yfinance import YFinanceTools model_id = "llama3.2" model = Ollama(id=model_id) finance_agent = Agent( name="Finance Agent", model=model, tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True)], instructions=["Use tables to display data"], show_tool_calls=True, markdown=True, ) finance_agent.print_response("Summarize analyst recommendations for NVDA", stream=True)
出力:
┏━ Message ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ┃ ┃ Summarize analyst recommendations for NVDA ┃ ┃ ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┏━ Response (3.9s) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ┃ ┃ ┃ ┃ • Running: get_analyst_recommendations(symbol=NVDA) ┃ ┃ ┃ ┃ Based on the analyst recommendations, here is a summary: ┃ ┃ ┃ ┃ • The overall sentiment is bullish, with 12 strong buy and buy ┃ ┃ recommendations. ┃ ┃ • There are no strong sell or sell recommendations. ┃ ┃ • The average price target for NVDA is around 0-0. ┃ ┃ • Analysts expect NVDA to continue its growth trajectory, driven by ┃ ┃ its strong products and services in the tech industry. ┃ ┃ ┃ ┃ Please note that these recommendations are subject to change and may ┃ ┃ not reflect the current market situation. It's always a good idea to do ┃ ┃ your own research and consult with a financial advisor before making ┃ ┃ any investment decisions. ┃ ┃ ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
エージェントチームを作成する
私たちが作成する 3 番目のエージェントは、DuckDuckGo 検索エンジンと YFinance ツールを使用するエージェント チームです。
from phi.agent import Agent from phi.model.ollama import Ollama from phi.tools.duckduckgo import DuckDuckGo from phi.tools.yfinance import YFinanceTools web_instructions = 'Always include sources' finance_instructions = 'Use tables to display data' model_id = "llama3.2" model = Ollama(id=model_id) web_agent = Agent( name="Web Agent", role="Search the web for information", model=model, tools=[DuckDuckGo()], instructions=[web_instructions], show_tool_calls=True, markdown=True, ) finance_agent = Agent( name="Finance Agent", role="Get financial data", model=model, tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True)], instructions=[finance_instructions], show_tool_calls=True, markdown=True, ) agent_team = Agent( model=model, team=[web_agent, finance_agent], instructions=[web_instructions, finance_instructions], show_tool_calls=True, markdown=True, ) agent_team.print_response("Summarize analyst recommendations and share the latest news for NVDA", stream=True)
推論エージェントを作成する
作成する 4 番目のエージェントは、タスクを使用する推論エージェントです。
from phi.agent import Agent from phi.model.ollama import Ollama model_id = "llama3.2" model = Ollama(id=model_id) task = ( "Three missionaries and three cannibals want to cross a river." "There is a boat that can carry up to two people, but if the number of cannibals exceeds the number of missionaries, the missionaries will be eaten." ) reasoning_agent = Agent(model=model, reasoning=True, markdown=True, structured_outputs=True) reasoning_agent.print_response(task, stream=True, show_full_reasoning=True)
出力:
┏━ Message ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ┃ ┃ Three missionaries and three cannibals want to cross a river.There is a ┃ ┃ boat that can carry up to two people, but if the number of cannibals ┃ ┃ exceeds the number of missionaries, the missionaries will be eaten. ┃ ┃ ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ [Reasoning steps and output as in the original document]
RAG エージェントを作成する
作成する 5 番目のエージェントは、PDF ナレッジ ベースと LanceDB ベクター データベースを使用する RAG エージェントです。
from phi.agent import Agent from phi.model.openai import OpenAIChat from phi.embedder.openai import OpenAIEmbedder from phi.embedder.ollama import OllamaEmbedder from phi.model.ollama import Ollama from phi.knowledge.pdf import PDFUrlKnowledgeBase from phi.vectordb.lancedb import LanceDb, SearchType model_id = "llama3.2" model = Ollama(id=model_id) embeddings = OllamaEmbedder().get_embedding("The quick brown fox jumps over the lazy dog.") knowledge_base = PDFUrlKnowledgeBase( urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"], vector_db=LanceDb( table_name="recipes", uri="tmp/lancedb", search_type=SearchType.vector, embedder=OllamaEmbedder(), ), ) knowledge_base.load() agent = Agent( model=model, knowledge=knowledge_base, show_tool_calls=True, markdown=True, ) agent.print_response("Please tell me how to make green curry.", stream=True)
出力:
uv run rag_agent.py WARNING model "openhermes" not found, try pulling it first WARNING model "openhermes" not found, try pulling it first INFO Creating collection INFO Loading knowledge base INFO Reading: https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf WARNING model "openhermes" not found, try pulling it first WARNING model "openhermes" not found, try pulling it first WARNING model "openhermes" not found, try pulling it first WARNING model "openhermes" not found, try pulling it first WARNING model "openhermes" not found, try pulling it first WARNING model "openhermes" not found, try pulling it first WARNING model "openhermes" not found, try pulling it first WARNING model "openhermes" not found, try pulling it first WARNING model "openhermes" not found, try pulling it first WARNING model "openhermes" not found, try pulling it first WARNING model "openhermes" not found, try pulling it first WARNING model "openhermes" not found, try pulling it first WARNING model "openhermes" not found, try pulling it first WARNING model "openhermes" not found, try pulling it first INFO Added 14 documents to knowledge base WARNING model "openhermes" not found, try pulling it first ERROR Error searching for documents: list index out of range ┏━ Message ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ┃ ┃ Please tell me how to make green curry. ┃ ┃ ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┏━ Response (5.4s) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ┃ ┃ ┃ ┃ • Running: search_knowledge_base(query=green curry recipe) ┃ ┃ ┃ ┃ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ┃ ┃ Green Curry Recipe ┃ ┃ ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┃ ┃ ┃ ┃ ** Servings: 4-6 people** ┃ ┃ ┃ ┃ Ingredients: ┃ ┃ ┃ ┃ • 2 tablespoons vegetable oil ┃ ┃ • 2 cloves garlic, minced ┃ ┃ • 1 tablespoon grated fresh ginger ┃ ┃ • 2 tablespoons Thai red curry paste ┃ ┃ • 2 cups coconut milk ┃ ┃ • 1 cup mixed vegetables (such as bell peppers, bamboo shoots, and ┃ ┃ Thai eggplant) ┃ ┃ • 1 pound boneless, skinless chicken breasts or thighs, cut into ┃ ┃ bite-sized pieces ┃ ┃ • 2 tablespoons fish sauce ┃ ┃ • 1 tablespoon palm sugar ┃ ┃ • 1/4 teaspoon ground white pepper ┃ ┃ • Salt to taste ┃ ┃ • Fresh basil leaves for garnish ┃ ┃ ┃ ┃ Instructions: ┃ ┃ ┃ ┃ 1 Prepare the curry paste: In a blender or food processor, combine the ┃ ┃ curry paste, garlic, ginger, fish sauce, palm sugar, and white ┃ ┃ pepper. Blend until smooth. ┃ ┃ 2 Heat oil in a pan: Heat the oil in a large skillet or Dutch oven ┃ ┃ over medium-high heat. ┃ ┃ 3 Add the curry paste: Pour the blended curry paste into the hot oil ┃ ┃ and stir constantly for 1-2 minutes, until fragrant. ┃ ┃ 4 Add coconut milk: Pour in the coconut milk and bring the mixture to ┃ ┃ a simmer. ┃ ┃ 5 Add vegetables and chicken: Add the mixed vegetables and chicken ┃ ┃ pieces to the pan. Stir gently to combine. ┃ ┃ 6 Reduce heat and cook: Reduce the heat to medium-low and let the ┃ ┃ curry simmer, uncovered, for 20-25 minutes or until the chicken is ┃ ┃ cooked through and the sauce has thickened. ┃ ┃ 7 Season with salt and taste: Season the curry with salt to taste. ┃ ┃ Serve hot garnished with fresh basil leaves. ┃ ┃ ┃ ┃ Tips and Variations: ┃ ┃ ┃ ┃ • Adjust the level of spiciness by using more or less Thai red curry ┃ ┃ paste. ┃ ┃ • Add other protein sources like shrimp, tofu, or tempeh for a ┃ ┃ vegetarian or vegan option. ┃ ┃ • Experiment with different vegetables, such as zucchini or carrots, ┃ ┃ to add variety. ┃ ┃ ┃ ┃ Tools Used: Python ┃ ┃ ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
結論
この記事では、phidata と Ollama ローカル LLM を使用して、Web 検索、財務分析、推論、検索拡張生成のための AI エージェントを作成する方法を検討しました。
以上がphidata と Ollama を使用して I エージェントを構築するの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

このチュートリアルでは、Pythonを使用してZIPFの法則の統計的概念を処理する方法を示し、法律の処理時にPythonの読み取りおよび並べ替えの効率性を示します。 ZIPF分布という用語が何を意味するのか疑問に思うかもしれません。この用語を理解するには、まずZIPFの法律を定義する必要があります。心配しないでください、私は指示を簡素化しようとします。 ZIPFの法則 ZIPFの法則は単に意味します。大きな自然言語のコーパスでは、最も頻繁に発生する単語は、2番目の頻繁な単語のほぼ2倍の頻度で表示されます。 例を見てみましょう。アメリカ英語の茶色のコーパスを見ると、最も頻繁な言葉は「thであることに気付くでしょう。

ノイズの多い画像を扱うことは、特に携帯電話や低解像度のカメラの写真でよくある問題です。 このチュートリアルでは、OpenCVを使用してPythonの画像フィルタリング手法を調査して、この問題に取り組みます。 画像フィルタリング:強力なツール 画像フィルター

この記事では、Pythonライブラリである美しいスープを使用してHTMLを解析する方法について説明します。 find()、find_all()、select()、およびget_text()などの一般的な方法は、データ抽出、多様なHTML構造とエラーの処理、および代替案(SEL

この記事では、深い学習のためにTensorflowとPytorchを比較しています。 関連する手順、データの準備、モデルの構築、トレーニング、評価、展開について詳しく説明しています。 特に計算グラップに関して、フレームワーク間の重要な違い

データサイエンスと処理のお気に入りであるPythonは、高性能コンピューティングのための豊富なエコシステムを提供します。ただし、Pythonの並列プログラミングは、独自の課題を提示します。このチュートリアルでは、これらの課題を調査し、グローバルな承認に焦点を当てています

このチュートリアルでは、Python 3にカスタムパイプラインデータ構造を作成し、機能を強化するためにクラスとオペレーターのオーバーロードを活用していることを示しています。 パイプラインの柔軟性は、一連の機能をデータセットに適用する能力にあります。

Pythonオブジェクトのシリアル化と脱介入は、非自明のプログラムの重要な側面です。 Pythonファイルに何かを保存すると、構成ファイルを読み取る場合、またはHTTPリクエストに応答する場合、オブジェクトシリアル化と脱滑り化を行います。 ある意味では、シリアル化と脱派化は、世界で最も退屈なものです。これらすべての形式とプロトコルを気にするのは誰ですか? Pythonオブジェクトを維持またはストリーミングし、後で完全に取得したいと考えています。 これは、概念レベルで世界を見るのに最適な方法です。ただし、実用的なレベルでは、選択したシリアル化スキーム、形式、またはプロトコルは、プログラムの速度、セキュリティ、メンテナンスの自由、およびその他の側面を決定する場合があります。

Pythonの統計モジュールは、強力なデータ統計分析機能を提供して、生物統計やビジネス分析などのデータの全体的な特性を迅速に理解できるようにします。データポイントを1つずつ見る代わりに、平均や分散などの統計を見て、無視される可能性のある元のデータの傾向と機能を発見し、大きなデータセットをより簡単かつ効果的に比較してください。 このチュートリアルでは、平均を計算し、データセットの分散の程度を測定する方法を説明します。特に明記しない限り、このモジュールのすべての関数は、単に平均を合計するのではなく、平均()関数の計算をサポートします。 浮動小数点数も使用できます。 ランダムをインポートします インポート統計 fractiから


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

SAP NetWeaver Server Adapter for Eclipse
Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

Dreamweaver Mac版
ビジュアル Web 開発ツール

メモ帳++7.3.1
使いやすく無料のコードエディター

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター
