diff --git a/cookbook/llms/anyscale/README.md b/cookbook/llms/anyscale/README.md index 4b1c00d78..bff75c18a 100644 --- a/cookbook/llms/anyscale/README.md +++ b/cookbook/llms/anyscale/README.md @@ -12,13 +12,13 @@ source ~/.venvs/aienv/bin/activate 2. Install libraries ```shell -pip install -U phidata openai +pip install -U openai phidata ``` 3. Export `ANYSCALE_API_KEY` -```text -export ANYSCALE_API_KEY= +```shell +export ANYSCALE_API_KEY=*** ``` 4. Test Anyscale Assistant diff --git a/cookbook/llms/anyscale/assistant.py b/cookbook/llms/anyscale/assistant.py index 14ff510dd..4a510d42f 100644 --- a/cookbook/llms/anyscale/assistant.py +++ b/cookbook/llms/anyscale/assistant.py @@ -5,4 +5,4 @@ llm=Anyscale(model="mistralai/Mixtral-8x7B-Instruct-v0.1"), description="You help people with their health and fitness goals.", ) -assistant.print_response("Share a 2 sentence quick healthy breakfast recipe.", markdown=True) +assistant.print_response("Share a 2 sentence quick and healthy breakfast recipe.", markdown=True) diff --git a/cookbook/llms/anyscale/assistant_stream_off.py b/cookbook/llms/anyscale/assistant_stream_off.py index e13fb5032..077bca825 100644 --- a/cookbook/llms/anyscale/assistant_stream_off.py +++ b/cookbook/llms/anyscale/assistant_stream_off.py @@ -2,7 +2,7 @@ from phi.llm.anyscale import Anyscale assistant = Assistant( - llm=Anyscale(), + llm=Anyscale(model="mistralai/Mixtral-8x7B-Instruct-v0.1"), description="You help people with their health and fitness goals.", ) -assistant.print_response("Share a quick healthy breakfast recipe.", stream=False, markdown=True) +assistant.print_response("Share a 2 sentence quick and healthy breakfast recipe.", markdown=True, stream=False) diff --git a/cookbook/llms/azure_openai/README.md b/cookbook/llms/azure_openai/README.md index 236eb286a..87b0763a0 100644 --- a/cookbook/llms/azure_openai/README.md +++ b/cookbook/llms/azure_openai/README.md @@ -18,11 +18,11 @@ pip install -U phidata openai 3. Export Azure Credentials (`AZURE_OPENAI_API_KEY` and `AZURE_OPENAI_ENDPOINT` are required) ```shell -export AZURE_OPENAI_API_KEY= -export AZURE_OPENAI_ENDPOINT= +export AZURE_OPENAI_API_KEY=*** +export AZURE_OPENAI_ENDPOINT=*** # Optional: -# export AZURE_OPENAI_API_VERSION= -# export AZURE_DEPLOYMENT= +# export AZURE_OPENAI_API_VERSION=*** +# export AZURE_DEPLOYMENT=*** ``` 4. Test Azure Assistant diff --git a/cookbook/llms/azure_openai/assistant.py b/cookbook/llms/azure_openai/assistant.py index 3ba521575..3e2ce4a61 100644 --- a/cookbook/llms/azure_openai/assistant.py +++ b/cookbook/llms/azure_openai/assistant.py @@ -2,7 +2,7 @@ from phi.llm.azure import AzureOpenAIChat assistant = Assistant( - llm=AzureOpenAIChat(model="gpt-35-turbo"), # model="deployment_name" + llm=AzureOpenAIChat(model="gpt-35-turbo"), description="You help people with their health and fitness goals.", ) -assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True) +assistant.print_response("Share a 2 sentence quick and healthy breakfast recipe.", markdown=True) diff --git a/cookbook/llms/azure_openai/assistant_stream_off.py b/cookbook/llms/azure_openai/assistant_stream_off.py index 885075de4..ed4e7d687 100644 --- a/cookbook/llms/azure_openai/assistant_stream_off.py +++ b/cookbook/llms/azure_openai/assistant_stream_off.py @@ -2,7 +2,7 @@ from phi.llm.azure import AzureOpenAIChat assistant = Assistant( - llm=AzureOpenAIChat(model="gpt-35-turbo"), # model="deployment_name" + llm=AzureOpenAIChat(model="gpt-35-turbo"), description="You help people with their health and fitness goals.", ) -assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True, stream=False) +assistant.print_response("Share a 2 sentence quick and healthy breakfast recipe.", markdown=True, stream=False) diff --git a/cookbook/llms/claude/README.md b/cookbook/llms/claude/README.md index 880bd77a1..542d60a83 100644 --- a/cookbook/llms/claude/README.md +++ b/cookbook/llms/claude/README.md @@ -39,12 +39,6 @@ python cookbook/llms/claude/assistant_stream_off.py ### 5. Run Assistant with Tools -- Web search - -```shell -python cookbook/llms/claude/web_search.py -``` - - YFinance ```shell diff --git a/cookbook/llms/claude/assistant.py b/cookbook/llms/claude/assistant.py index 9a3022d32..d5b84ca6e 100644 --- a/cookbook/llms/claude/assistant.py +++ b/cookbook/llms/claude/assistant.py @@ -1,8 +1,10 @@ from phi.assistant import Assistant +from phi.tools.duckduckgo import DuckDuckGo from phi.llm.anthropic import Claude assistant = Assistant( llm=Claude(model="claude-3-opus-20240229"), - description="You help people with their health and fitness goals.", + tools=[DuckDuckGo()], + show_tool_calls=True, ) -assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True) +assistant.print_response("Whats happening in France?", markdown=True) diff --git a/cookbook/llms/claude/assistant_stream_off.py b/cookbook/llms/claude/assistant_stream_off.py index fdfeb627b..14dd966a0 100644 --- a/cookbook/llms/claude/assistant_stream_off.py +++ b/cookbook/llms/claude/assistant_stream_off.py @@ -1,8 +1,10 @@ from phi.assistant import Assistant +from phi.tools.duckduckgo import DuckDuckGo from phi.llm.anthropic import Claude assistant = Assistant( llm=Claude(model="claude-3-opus-20240229"), - description="You help people with their health and fitness goals.", + tools=[DuckDuckGo()], + show_tool_calls=True, ) -assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True, stream=False) +assistant.print_response("Whats happening in France?", markdown=True, stream=False) diff --git a/cookbook/llms/claude/basic.py b/cookbook/llms/claude/basic.py new file mode 100644 index 000000000..eee14825c --- /dev/null +++ b/cookbook/llms/claude/basic.py @@ -0,0 +1,8 @@ +from phi.assistant import Assistant +from phi.llm.anthropic import Claude + +assistant = Assistant( + llm=Claude(model="claude-3-haiku-20240307"), + description="You help people with their health and fitness goals.", +) +assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True) diff --git a/cookbook/llms/claude/basic_stream_off.py b/cookbook/llms/claude/basic_stream_off.py new file mode 100644 index 000000000..5719fd1d0 --- /dev/null +++ b/cookbook/llms/claude/basic_stream_off.py @@ -0,0 +1,8 @@ +from phi.assistant import Assistant +from phi.llm.anthropic import Claude + +assistant = Assistant( + llm=Claude(model="claude-3-haiku-20240307"), + description="You help people with their health and fitness goals.", +) +assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True, stream=False) diff --git a/cookbook/llms/claude/web_search.py b/cookbook/llms/claude/web_search.py deleted file mode 100644 index f5799f182..000000000 --- a/cookbook/llms/claude/web_search.py +++ /dev/null @@ -1,11 +0,0 @@ -from phi.assistant import Assistant -from phi.tools.duckduckgo import DuckDuckGo -from phi.llm.anthropic import Claude - -assistant = Assistant( - llm=Claude(model="claude-3-opus-20240229"), - tools=[DuckDuckGo()], - show_tool_calls=True, - # debug_mode=True, -) -assistant.print_response("Share 1 story from france and 1 from germany?", markdown=True, stream=False) diff --git a/cookbook/llms/cohere/README.md b/cookbook/llms/cohere/README.md index 7b9cb679f..9ef468c98 100644 --- a/cookbook/llms/cohere/README.md +++ b/cookbook/llms/cohere/README.md @@ -1,6 +1,6 @@ # CohereChat function calling -Currently "command-r" model supports function calling +Currently Cohere's "command-r" and "command-r-plus" models supports function calling > Note: Fork and clone this repository if needed @@ -14,7 +14,7 @@ source ~/.venvs/aienv/bin/activate ### 2. Export your CohereChat API Key ```shell -export CO_API_KEY=xxx +export CO_API_KEY=*** ``` ### 3. Install libraries diff --git a/cookbook/llms/cohere/assistant.py b/cookbook/llms/cohere/assistant.py index 177a8ace4..8ab940dc7 100644 --- a/cookbook/llms/cohere/assistant.py +++ b/cookbook/llms/cohere/assistant.py @@ -1,9 +1,10 @@ from phi.assistant import Assistant +from phi.tools.duckduckgo import DuckDuckGo from phi.llm.cohere import CohereChat assistant = Assistant( llm=CohereChat(model="command-r"), - description="You help people with their health and fitness goals.", - debug_mode=True, + tools=[DuckDuckGo()], + show_tool_calls=True, ) -assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True) +assistant.print_response("Whats happening in France?", markdown=True) diff --git a/cookbook/llms/cohere/assistant_stream_off.py b/cookbook/llms/cohere/assistant_stream_off.py index b5ee1e9ef..f197b1b6a 100644 --- a/cookbook/llms/cohere/assistant_stream_off.py +++ b/cookbook/llms/cohere/assistant_stream_off.py @@ -1,9 +1,10 @@ from phi.assistant import Assistant +from phi.tools.duckduckgo import DuckDuckGo from phi.llm.cohere import CohereChat assistant = Assistant( llm=CohereChat(model="command-r"), - description="You help people with their health and fitness goals.", - debug_mode=True, + tools=[DuckDuckGo()], + show_tool_calls=True, ) -assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True, stream=False) +assistant.print_response("Whats happening in France?", markdown=True, stream=False) diff --git a/cookbook/llms/cohere/basic.py b/cookbook/llms/cohere/basic.py new file mode 100644 index 000000000..276adec9d --- /dev/null +++ b/cookbook/llms/cohere/basic.py @@ -0,0 +1,8 @@ +from phi.assistant import Assistant +from phi.llm.cohere import CohereChat + +assistant = Assistant( + llm=CohereChat(model="command-r"), + description="You help people with their health and fitness goals.", +) +assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True) diff --git a/cookbook/llms/cohere/basic_stream_off.py b/cookbook/llms/cohere/basic_stream_off.py new file mode 100644 index 000000000..4be94bdc9 --- /dev/null +++ b/cookbook/llms/cohere/basic_stream_off.py @@ -0,0 +1,8 @@ +from phi.assistant import Assistant +from phi.llm.cohere import CohereChat + +assistant = Assistant( + llm=CohereChat(model="command-r"), + description="You help people with their health and fitness goals.", +) +assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True, stream=False) diff --git a/cookbook/llms/cohere/web_search.py b/cookbook/llms/cohere/web_search.py deleted file mode 100644 index d08541139..000000000 --- a/cookbook/llms/cohere/web_search.py +++ /dev/null @@ -1,12 +0,0 @@ -from phi.assistant import Assistant -from phi.tools.duckduckgo import DuckDuckGo -from phi.llm.cohere import CohereChat - -assistant = Assistant( - llm=CohereChat(model="command-r"), - tools=[DuckDuckGo()], - show_tool_calls=True, - instructions=["Format your response using markdown and use tables to display information where possible."], - debug_mode=True, -) -assistant.print_response("Share 1 story from france and 1 from germany?", markdown=True) diff --git a/cookbook/llms/fireworks/README.md b/cookbook/llms/fireworks/README.md index a4ba1087e..f66ff64e9 100644 --- a/cookbook/llms/fireworks/README.md +++ b/cookbook/llms/fireworks/README.md @@ -1,4 +1,4 @@ -## Fireworks AI Function Calling +## Fireworks AI > Note: Fork and clone this repository if needed @@ -17,14 +17,14 @@ pip install -U openai yfinance exa_py duckduckgo-search streamlit phidata 3. Export `FIREWORKS_API_KEY` -```text -export FIREWORKS_API_KEY= +```shell +export FIREWORKS_API_KEY=*** ``` > If you want to use Exa Search, export `EXA_API_KEY` as well -```text -export EXA_API_KEY= +```shell +export EXA_API_KEY=*** ``` 4. Run streamlit app @@ -60,7 +60,3 @@ python cookbook/llms/fireworks/pydantic_output.py ```shell python cookbook/llms/fireworks/tool_call.py ``` - -```shell -python cookbook/llms/fireworks/web_search.py -``` diff --git a/cookbook/llms/fireworks/assistant.py b/cookbook/llms/fireworks/assistant.py index f7b30cf91..c30cda8a6 100644 --- a/cookbook/llms/fireworks/assistant.py +++ b/cookbook/llms/fireworks/assistant.py @@ -1,8 +1,10 @@ from phi.assistant import Assistant from phi.llm.fireworks import Fireworks +from phi.tools.duckduckgo import DuckDuckGo assistant = Assistant( - llm=Fireworks(), - description="You help people with their health and fitness goals.", + llm=Fireworks(), + tools=[DuckDuckGo()], + show_tool_calls=True ) -assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True) +assistant.print_response("Whats happening in France?", markdown=True) diff --git a/cookbook/llms/fireworks/assistant_stream_off.py b/cookbook/llms/fireworks/assistant_stream_off.py index 2e7a25434..f474a42ac 100644 --- a/cookbook/llms/fireworks/assistant_stream_off.py +++ b/cookbook/llms/fireworks/assistant_stream_off.py @@ -1,8 +1,10 @@ from phi.assistant import Assistant from phi.llm.fireworks import Fireworks +from phi.tools.duckduckgo import DuckDuckGo assistant = Assistant( - llm=Fireworks(), - description="You help people with their health and fitness goals.", + llm=Fireworks(), + tools=[DuckDuckGo()], + show_tool_calls=True ) -assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True, stream=False) +assistant.print_response("Whats happening in France?", markdown=True, stream=False) diff --git a/cookbook/llms/fireworks/basic.py b/cookbook/llms/fireworks/basic.py new file mode 100644 index 000000000..f7b30cf91 --- /dev/null +++ b/cookbook/llms/fireworks/basic.py @@ -0,0 +1,8 @@ +from phi.assistant import Assistant +from phi.llm.fireworks import Fireworks + +assistant = Assistant( + llm=Fireworks(), + description="You help people with their health and fitness goals.", +) +assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True) diff --git a/cookbook/llms/fireworks/basic_stream_off.py b/cookbook/llms/fireworks/basic_stream_off.py new file mode 100644 index 000000000..2e7a25434 --- /dev/null +++ b/cookbook/llms/fireworks/basic_stream_off.py @@ -0,0 +1,8 @@ +from phi.assistant import Assistant +from phi.llm.fireworks import Fireworks + +assistant = Assistant( + llm=Fireworks(), + description="You help people with their health and fitness goals.", +) +assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True, stream=False) diff --git a/cookbook/llms/fireworks/web_search.py b/cookbook/llms/fireworks/web_search.py deleted file mode 100644 index a2213addd..000000000 --- a/cookbook/llms/fireworks/web_search.py +++ /dev/null @@ -1,6 +0,0 @@ -from phi.assistant import Assistant -from phi.llm.fireworks import Fireworks -from phi.tools.duckduckgo import DuckDuckGo - -assistant = Assistant(llm=Fireworks(), tools=[DuckDuckGo()], show_tool_calls=True) -assistant.print_response("Whats happening in France? Summarize top 5 stories with sources.", markdown=True) diff --git a/cookbook/llms/groq/README.md b/cookbook/llms/groq/README.md index 5a13beda9..2c7af06f5 100644 --- a/cookbook/llms/groq/README.md +++ b/cookbook/llms/groq/README.md @@ -16,7 +16,7 @@ source ~/.venvs/aienv/bin/activate > Need to use OpenAI for embeddings as Groq doesn't support embeddings yet. ```shell -export GROQ_API_KEY=xxx +export GROQ_API_KEY=*** export OPENAI_API_KEY=sk-*** ``` @@ -28,20 +28,32 @@ pip install -r cookbook/llms/groq/requirements.txt 4. Start pgvector +> Install [docker desktop](https://docs.docker.com/desktop/install/mac-install/) first. + +- Run using a helper script + ```shell -phi start cookbook/llms/groq/resources.py -y +./cookbook/run_pgvector.sh ``` -5. Run RAG App +- OR run using the docker run command ```shell -streamlit run cookbook/llms/groq/app.py +docker run -d \ + -e POSTGRES_DB=ai \ + -e POSTGRES_USER=ai \ + -e POSTGRES_PASSWORD=ai \ + -e PGDATA=/var/lib/postgresql/data/pgdata \ + -v pgvolume:/var/lib/postgresql/data \ + -p 5532:5432 \ + --name pgvector \ + phidata/pgvector:16 ``` -6. Stop pgvector +5. Run RAG App ```shell -phi stop cookbook/llms/groq/resources.py -y +streamlit run cookbook/llms/groq/app.py ``` ## Build AI Assistants with Groq @@ -54,14 +66,6 @@ pip install -U groq phidata 2. Run Assistant -- stream on - ```shell python cookbook/llms/groq/assistant.py ``` - -- stream off - -```shell -python cookbook/llms/groq/assistant_stream_off.py -``` diff --git a/cookbook/llms/groq/assistant.py b/cookbook/llms/groq/assistant.py index 8d0a2a6c3..2d78ed448 100644 --- a/cookbook/llms/groq/assistant.py +++ b/cookbook/llms/groq/assistant.py @@ -1,9 +1,10 @@ from phi.assistant import Assistant +from phi.tools.duckduckgo import DuckDuckGo from phi.llm.groq import Groq assistant = Assistant( llm=Groq(model="mixtral-8x7b-32768"), - description="You help people with their health and fitness goals.", - # debug_mode=True, + tools=[DuckDuckGo()], + show_tool_calls=True, ) -assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True) +assistant.print_response("Whats happening in France?", markdown=True, stream=False) diff --git a/cookbook/llms/groq/basic.py b/cookbook/llms/groq/basic.py new file mode 100644 index 000000000..6f21dc2ab --- /dev/null +++ b/cookbook/llms/groq/basic.py @@ -0,0 +1,8 @@ +from phi.assistant import Assistant +from phi.llm.groq import Groq + +assistant = Assistant( + llm=Groq(model="mixtral-8x7b-32768"), + description="You help people with their health and fitness goals.", +) +assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True) diff --git a/cookbook/llms/groq/assistant_stream_off.py b/cookbook/llms/groq/basic_stream_off.py similarity index 92% rename from cookbook/llms/groq/assistant_stream_off.py rename to cookbook/llms/groq/basic_stream_off.py index 163419bd6..134180d9c 100644 --- a/cookbook/llms/groq/assistant_stream_off.py +++ b/cookbook/llms/groq/basic_stream_off.py @@ -4,6 +4,5 @@ assistant = Assistant( llm=Groq(model="mixtral-8x7b-32768"), description="You help people with their health and fitness goals.", - # debug_mode=True, ) assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True, stream=False) diff --git a/cookbook/llms/groq/groq_assistant.py b/cookbook/llms/groq/groq_assistant.py index 054e75b3c..8eaf60e3a 100644 --- a/cookbook/llms/groq/groq_assistant.py +++ b/cookbook/llms/groq/groq_assistant.py @@ -7,17 +7,17 @@ from phi.vectordb.pgvector import PgVector2 from phi.storage.assistant.postgres import PgAssistantStorage -from resources import vector_db # type: ignore +db_url="postgresql+psycopg://ai:ai@localhost:5532/ai" groq_assistant_storage = PgAssistantStorage( - db_url=vector_db.get_db_connection_local(), + db_url=db_url, # Store assistant runs in table: ai.groq_rag_assistant table_name="groq_rag_assistant", ) groq_assistant_knowledge = AssistantKnowledge( vector_db=PgVector2( - db_url=vector_db.get_db_connection_local(), + db_url=db_url, # Store embeddings in table: ai.groq_rag_documents collection="groq_rag_documents", embedder=OpenAIEmbedder(model="text-embedding-3-small"), @@ -33,7 +33,7 @@ def get_groq_assistant( run_id: Optional[str] = None, debug_mode: bool = False, ) -> Assistant: - """Get a Mistral RAG Assistant.""" + """Get a Groq Mistral RAG Assistant.""" return Assistant( name="mixtral-8x7b-32768", diff --git a/cookbook/llms/groq/web_search.py b/cookbook/llms/groq/web_search.py deleted file mode 100644 index f3d748e77..000000000 --- a/cookbook/llms/groq/web_search.py +++ /dev/null @@ -1,11 +0,0 @@ -from phi.assistant import Assistant -from phi.tools.duckduckgo import DuckDuckGo -from phi.llm.groq import Groq - -assistant = Assistant( - llm=Groq(model="mixtral-8x7b-32768"), - tools=[DuckDuckGo()], - show_tool_calls=True, - # debug_mode=True -) -assistant.print_response("Tell me about OpenAI Sora", markdown=True, stream=False) diff --git a/cookbook/llms/hermes2/README.md b/cookbook/llms/hermes2/README.md index 7074e06f4..44de55f51 100644 --- a/cookbook/llms/hermes2/README.md +++ b/cookbook/llms/hermes2/README.md @@ -25,7 +25,7 @@ source ~/.venvs/aienv/bin/activate ### 3. Install libraries ```shell -pip install -U ollama phidata duckduckgo-search yfinance +pip install -U ollama duckduckgo-search yfinance phidata ``` ### 4. Web search function calling diff --git a/cookbook/llms/hermes2/assistant.py b/cookbook/llms/hermes2/assistant.py index 70d677a93..0d4c32f8d 100644 --- a/cookbook/llms/hermes2/assistant.py +++ b/cookbook/llms/hermes2/assistant.py @@ -1,8 +1,6 @@ from phi.assistant import Assistant +from phi.tools.duckduckgo import DuckDuckGo from phi.llm.ollama import Hermes -assistant = Assistant( - llm=Hermes(model="adrienbrault/nous-hermes2pro:Q8_0"), - description="You help people with their health and fitness goals.", -) -assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True) +assistant = Assistant(llm=Hermes(model="adrienbrault/nous-hermes2pro:Q8_0"), tools=[DuckDuckGo()], show_tool_calls=True) +assistant.print_response("Whats happening in France?", markdown=True) diff --git a/cookbook/llms/hermes2/basic.py b/cookbook/llms/hermes2/basic.py new file mode 100644 index 000000000..70d677a93 --- /dev/null +++ b/cookbook/llms/hermes2/basic.py @@ -0,0 +1,8 @@ +from phi.assistant import Assistant +from phi.llm.ollama import Hermes + +assistant = Assistant( + llm=Hermes(model="adrienbrault/nous-hermes2pro:Q8_0"), + description="You help people with their health and fitness goals.", +) +assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True) diff --git a/cookbook/llms/hermes2/web_search.py b/cookbook/llms/hermes2/web_search.py deleted file mode 100644 index 1772c573f..000000000 --- a/cookbook/llms/hermes2/web_search.py +++ /dev/null @@ -1,6 +0,0 @@ -from phi.assistant import Assistant -from phi.tools.duckduckgo import DuckDuckGo -from phi.llm.ollama import Hermes - -assistant = Assistant(llm=Hermes(model="adrienbrault/nous-hermes2pro:Q8_0"), tools=[DuckDuckGo()], show_tool_calls=True) -assistant.print_response("Tell me about OpenAI Sora", markdown=True) diff --git a/cookbook/llms/mistral/README.md b/cookbook/llms/mistral/README.md index 3e4a0daf7..b2aa72465 100644 --- a/cookbook/llms/mistral/README.md +++ b/cookbook/llms/mistral/README.md @@ -14,7 +14,7 @@ source ~/.venvs/aienv/bin/activate 2. Export your Mistral API Key ```shell -export MISTRAL_API_KEY=xxx +export MISTRAL_API_KEY=*** ``` 3. Install libraries @@ -25,20 +25,32 @@ pip install -r cookbook/llms/mistral/requirements.txt 4. Start pgvector +> Install [docker desktop](https://docs.docker.com/desktop/install/mac-install/) first. + +- Run using a helper script + ```shell -phi start cookbook/llms/mistral/resources.py -y +./cookbook/run_pgvector.sh ``` -5. Run RAG App +- OR run using the docker run command ```shell -streamlit run cookbook/llms/mistral/app.py +docker run -d \ + -e POSTGRES_DB=ai \ + -e POSTGRES_USER=ai \ + -e POSTGRES_PASSWORD=ai \ + -e PGDATA=/var/lib/postgresql/data/pgdata \ + -v pgvolume:/var/lib/postgresql/data \ + -p 5532:5432 \ + --name pgvector \ + phidata/pgvector:16 ``` -6. Stop pgvector +5. Run RAG App ```shell -phi stop cookbook/llms/mistral/resources.py -y +streamlit run cookbook/llms/mistral/app.py ``` ## Build AI Assistants with Mistral @@ -52,7 +64,7 @@ pip install -U mistralai phidata 2. Run Assistant ```shell -python cookbook/llms/mistral/simple_assistant.py +python cookbook/llms/mistral/assistant.py ``` 3. Output Pydantic models diff --git a/cookbook/llms/mistral/assistant.py b/cookbook/llms/mistral/assistant.py index 06962f6c9..972d4fcec 100644 --- a/cookbook/llms/mistral/assistant.py +++ b/cookbook/llms/mistral/assistant.py @@ -4,6 +4,5 @@ assistant = Assistant( llm=Mistral(model="mistral-large-latest"), description="You help people with their health and fitness goals.", - # debug_mode=True, ) assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True) diff --git a/cookbook/llms/mistral/assistant_stream_off.py b/cookbook/llms/mistral/assistant_stream_off.py index 161e1288c..af7b51067 100644 --- a/cookbook/llms/mistral/assistant_stream_off.py +++ b/cookbook/llms/mistral/assistant_stream_off.py @@ -4,6 +4,5 @@ assistant = Assistant( llm=Mistral(model="mistral-large-latest"), description="You help people with their health and fitness goals.", - # debug_mode=True, ) assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True, stream=False) diff --git a/cookbook/llms/mistral/mistral_assistant.py b/cookbook/llms/mistral/mistral_assistant.py index e28c66552..001dc2c18 100644 --- a/cookbook/llms/mistral/mistral_assistant.py +++ b/cookbook/llms/mistral/mistral_assistant.py @@ -7,17 +7,17 @@ from phi.vectordb.pgvector import PgVector2 from phi.storage.assistant.postgres import PgAssistantStorage -from resources import vector_db # type: ignore +db_url="postgresql+psycopg://ai:ai@localhost:5532/ai" mistral_assistant_storage = PgAssistantStorage( - db_url=vector_db.get_db_connection_local(), + db_url=db_url, # Store assistant runs in table: ai.mistral_rag_assistant table_name="mistral_rag_assistant", ) mistral_assistant_knowledge = AssistantKnowledge( vector_db=PgVector2( - db_url=vector_db.get_db_connection_local(), + db_url=db_url, # Store embeddings in table: ai.mistral_rag_documents collection="mistral_rag_documents", embedder=MistralEmbedder(), diff --git a/cookbook/llms/ollama/assistant.py b/cookbook/llms/ollama/assistant.py index 027882265..551b7beef 100644 --- a/cookbook/llms/ollama/assistant.py +++ b/cookbook/llms/ollama/assistant.py @@ -2,7 +2,7 @@ from phi.llm.ollama import Ollama assistant = Assistant( - llm=Ollama(), + llm=Ollama(model="openhermes"), description="You help people with their health and fitness goals.", ) assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True) diff --git a/cookbook/llms/ollama/assistant_stream_off.py b/cookbook/llms/ollama/assistant_stream_off.py index 29c14f43b..6337fb390 100644 --- a/cookbook/llms/ollama/assistant_stream_off.py +++ b/cookbook/llms/ollama/assistant_stream_off.py @@ -2,8 +2,7 @@ from phi.llm.ollama import Ollama assistant = Assistant( - llm=Ollama(), + llm=Ollama(model="openhermes"), description="You help people with their health and fitness goals.", - debug_mode=True, ) assistant.print_response("Share a quick healthy breakfast recipe.", stream=False, markdown=True) diff --git a/cookbook/llms/openai/README.md b/cookbook/llms/openai/README.md index 75a711882..545009ed7 100644 --- a/cookbook/llms/openai/README.md +++ b/cookbook/llms/openai/README.md @@ -12,7 +12,7 @@ source ~/.venvs/aienv/bin/activate 2. Install libraries ```shell -pip install -U phidata openai +pip install -U openai duckduckgo-search yfinance phidata ``` 3. Export `OPENAI_API_KEY` @@ -33,8 +33,8 @@ python cookbook/llms/openai/assistant.py python cookbook/llms/openai/pydantic_output.py ``` -6. Test function calling +6. Further test function calling ```shell -python cookbook/llms/openai/tool_call.py +python cookbook/llms/openai/finance.py ``` diff --git a/cookbook/llms/openai/finance.py b/cookbook/llms/openai/finance.py new file mode 100644 index 000000000..64107b480 --- /dev/null +++ b/cookbook/llms/openai/finance.py @@ -0,0 +1,15 @@ +from phi.assistant import Assistant +from phi.tools.yfinance import YFinanceTools +from phi.llm.openai import OpenAIChat + +assistant = Assistant( + name="Finance Assistant", + llm=OpenAIChat(model="gpt-4-turbo", max_tokens=500, temperature=0.3), + tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, stock_fundamentals=True)], + show_tool_calls=True, + description="You are an investment analyst that researches stock prices, analyst recommendations, and stock fundamentals.", + instructions=["Format your response using markdown and use tables to display data where possible."], + # debug_mode=True, +) +assistant.print_response("Share the NVDA stock price and analyst recommendations", markdown=True) +# assistant.print_response("Summarize fundamentals for TSLA", markdown=True) diff --git a/cookbook/llms/together/README.md b/cookbook/llms/together/README.md index 7060edfef..ba0cca0ff 100644 --- a/cookbook/llms/together/README.md +++ b/cookbook/llms/together/README.md @@ -12,13 +12,13 @@ source ~/.venvs/aienv/bin/activate 2. Install libraries ```shell -pip install -U together phidata openai +pip install -U together openai phidata ``` 3. Export `TOGETHER_API_KEY` ```text -export TOGETHER_API_KEY= +export TOGETHER_API_KEY=*** ``` 4. Test Together Assistant diff --git a/cookbook/llms/together/assistant_stream_off.py b/cookbook/llms/together/assistant_stream_off.py index e208dd2db..ef800e8f1 100644 --- a/cookbook/llms/together/assistant_stream_off.py +++ b/cookbook/llms/together/assistant_stream_off.py @@ -2,7 +2,7 @@ from phi.llm.together import Together assistant = Assistant( - llm=Together(), + llm=Together(model="mistralai/Mixtral-8x7B-Instruct-v0.1"), description="You help people with their health and fitness goals.", ) assistant.print_response("Share a quick healthy breakfast recipe.", markdown=True, stream=False) diff --git a/cookbook/llms/together/cli.py b/cookbook/llms/together/cli.py index 801ea32c3..ca799a92f 100644 --- a/cookbook/llms/together/cli.py +++ b/cookbook/llms/together/cli.py @@ -1,8 +1,5 @@ from phi.assistant import Assistant -from phi.tools.duckduckgo import DuckDuckGo from phi.llm.together import Together -assistant = Assistant( - llm=Together(), tools=[DuckDuckGo()], description="You help people with their health and fitness goals." -) +assistant = Assistant(llm=Together(), description="You help people with their health and fitness goals.") assistant.cli_app(markdown=True, stream=False) diff --git a/phi/assistant/assistant.py b/phi/assistant/assistant.py index 297805cb3..be8bb66f6 100644 --- a/phi/assistant/assistant.py +++ b/phi/assistant/assistant.py @@ -879,7 +879,7 @@ def cli_app( user: str = "User", emoji: str = ":sunglasses:", stream: bool = True, - markdown: bool = True, + markdown: bool = False, exit_on: Tuple[str, ...] = ("exit", "bye"), ) -> None: from rich.prompt import Prompt