### Start the Coworker UI (Development) Source: https://github.com/andrewyng/aisuite/blob/main/platform/surfaces/gui/README.md Install dependencies and start the UI in development mode. Access the UI at http://localhost:5173. ```bash cd platform/surfaces/gui npm install # first time npm run dev # → http://localhost:5173 ``` -------------------------------- ### Start Development Server Source: https://github.com/andrewyng/aisuite/blob/main/aisuite-js/examples/chat-app/README.md This command starts the development server for the React application. ```bash npm run dev ``` -------------------------------- ### Install AISuite Package Source: https://github.com/andrewyng/aisuite/blob/main/aisuite-js/README.md Install the AISuite library using npm. ```bash npm install aisuite ``` -------------------------------- ### Install AI Suite with all dependencies Source: https://github.com/andrewyng/aisuite/blob/main/examples/AISuiteDemo.ipynb Use this command to install the AI Suite and all its optional dependencies. Ensure you have pip installed and configured. ```bash !pip install aisuite[all] ``` -------------------------------- ### Install AI Suite for Chat Completions Source: https://github.com/andrewyng/aisuite/blob/main/README-alternative.md Install the aisuite package. Add provider-specific extras as needed, for example, `aisuite[anthropic]`. ```bash pip install aisuite # add provider extras, e.g. aisuite[anthropic] ``` -------------------------------- ### Run AISuite Examples Source: https://github.com/andrewyng/aisuite/blob/main/aisuite-js/README.md Commands to execute different example scripts for the AISuite library, such as basic usage or tool calling. ```bash #Run basic usage example only: npm run example:basic # Run tool calling example only: npm run example:tools # Run the full test suite: npm run test:examples ``` -------------------------------- ### Install Dependencies Source: https://github.com/andrewyng/aisuite/blob/main/aisuite-js/examples/chat-app/README.md Run this command to install all necessary project dependencies using npm. ```bash npm install ``` -------------------------------- ### Install Groq Python Client Source: https://github.com/andrewyng/aisuite/blob/main/guides/groq.md Install the necessary Python library to interact with the Groq API. ```shell pip install groq ``` -------------------------------- ### Install aisuite Source: https://github.com/andrewyng/aisuite/blob/main/docs/chat-completions-quickstart.md Install the base aisuite package or with specific provider SDKs. Use 'all' to include every provider SDK. ```shell pip install aisuite # base package, no provider SDKs pip install 'aisuite[anthropic]' # with one provider's SDK pip install 'aisuite[all]' # with every provider SDK ``` -------------------------------- ### Install aisuite with MCP support Source: https://github.com/andrewyng/aisuite/blob/main/examples/mcp_tools_example.ipynb Install the aisuite library with MCP support. You can install it with all providers or specific ones like OpenAI. ```bash pip install 'aisuite[mcp]' # Or install providers you need: pip install 'aisuite[openai,mcp]' ``` -------------------------------- ### Install and Run aisuite-code CLI Source: https://github.com/andrewyng/aisuite/blob/main/cli/py/aisuite-code-cli/README.md Install the aisuite-code CLI using poetry and run it with a specified working directory. ```bash cd cli/py/aisuite-code-cli python3 -m poetry install python3 -m poetry run aisuite-code --cwd /path/to/project ``` -------------------------------- ### Install Streamlit Source: https://github.com/andrewyng/aisuite/blob/main/examples/chat-ui/README.md Install the Streamlit library to run the chat UI application. ```bash pip install streamlit ``` -------------------------------- ### Call Model with Tools Configuration Source: https://github.com/andrewyng/aisuite/blob/main/examples/simple_tool_calling.ipynb Initializes the client and configures it for making calls to models that can utilize tools. This example shows the setup for Azure. ```python import json import sys from dotenv import load_dotenv, find_dotenv import os sys.path.append('../../aisuite') # Load from .env file if available load_dotenv(find_dotenv()) from aisuite import Client client = Client() client.configure({"azure" : { "api_key": os.environ["AZURE_API_KEY"], "base_url": "https://aisuite-mistral-large-2407.westus3.models.ai.azure.com/v1/", }}) # model = "anthropic:claude-3-5-sonnet-20241022" # model = "aws:mistral.mistral-7b-instruct-v0:2" # model = "azure:aisuite-mistral-large" # model = "cohere:command-r-plus" # model = "deepseek:deepseek-chat" # model = "fireworks:accounts/fireworks/models/llama-v3p1-405b-instruct" # model = "google:gemini-1.5-pro-002" # model = "groq:llama-3.3-70b-versatile" ``` -------------------------------- ### Install ibm-watsonx-ai Client Source: https://github.com/andrewyng/aisuite/blob/main/guides/watsonx.md Install the ibm-watsonx-ai Python client library using pip or poetry. ```shell pip install ibm-watsonx-ai ``` ```shell poetry add ibm-watsonx-ai ``` -------------------------------- ### Example Prompt: List Files Source: https://github.com/andrewyng/aisuite/blob/main/cli/py/aisuite-code-cli/TRY_IT.md A sample prompt to instruct aisuite-code to list files in the current directory and describe their contents. This operation is read-only. ```text List files in this directory and tell me what you see. ``` -------------------------------- ### Start the Coworker Server Source: https://github.com/andrewyng/aisuite/blob/main/platform/surfaces/gui/README.md Run this command to start the coworker server. Ensure the OPENAI_API_KEY environment variable is set. ```bash cd platform export OPENAI_API_KEY=sk-... ./.venv/bin/coworker-server --cwd /path/to/your/project --port 8765 ``` -------------------------------- ### Install AI Suite with Agent Extras Source: https://github.com/andrewyng/aisuite/blob/main/README-alternative.md Install the aisuite package with the necessary extras for agent functionality. ```bash pip install aisuite[agents] ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/andrewyng/aisuite/blob/main/CONTRIBUTING.md Install the necessary development and testing dependencies using Poetry. This ensures your environment is set up correctly for development. ```bash poetry install --with dev,test ``` -------------------------------- ### Setup Deepseek Client and Load Environment Variables Source: https://github.com/andrewyng/aisuite/blob/main/examples/DeepseekPost.ipynb Initializes the Deepseek client and loads environment variables. Ensure you have a .env file with necessary API keys. ```python import sys from dotenv import load_dotenv, find_dotenv sys.path.append('../../aisuite') load_dotenv(find_dotenv()) ``` -------------------------------- ### Install boto3 Client Source: https://github.com/andrewyng/aisuite/blob/main/guides/aws.md Install the boto3 library, which is required for AWS integration, using pip or poetry. ```shell pip install boto3 ``` ```shell poetry add boto3 ``` -------------------------------- ### Setup aisuite Client with Provider Configurations Source: https://github.com/andrewyng/aisuite/blob/main/examples/asr_example.ipynb Initializes the aisuite client with API keys and credentials for OpenAI, Deepgram, and Google. Ensure environment variables are set for each provider. ```python import aisuite as ai from aisuite.framework.message import TranscriptionResult from dotenv import load_dotenv, find_dotenv import os load_dotenv(find_dotenv()) # Set up client with provider configurations client = ai.Client({ "openai": {"api_key": os.getenv("OPENAI_API_KEY")}, "deepgram": {"api_key": os.getenv("DEEPGRAM_API_KEY")}, "google": { "project_id": os.getenv("GOOGLE_PROJECT_ID"), "region": os.getenv("GOOGLE_REGION"), "application_credentials": os.getenv("GOOGLE_APPLICATION_CREDENTIALS"), }, }) audio_file = "../aiplayground/speech.mp3" # Replace with your audio file path ``` -------------------------------- ### Install PyMuPDF and requests Source: https://github.com/andrewyng/aisuite/blob/main/examples/QnA_with_pdf.ipynb Installs the necessary libraries for PDF processing and making HTTP requests. ```python #!pip install PyMuPDF requests ``` -------------------------------- ### Initialize MCP Servers Source: https://github.com/andrewyng/aisuite/blob/main/examples/agents/world_weather_dashboard.ipynb Sets up MCP clients for fetching data and interacting with the file system. Requires OPENAI_API_KEY or ANTHROPIC_API_KEY and specific MCP server installations. ```python import os from datetime import datetime from dotenv import load_dotenv import aisuite as ai from aisuite.mcp import MCPClient load_dotenv() # Initialize MCP servers fetch_mcp = MCPClient(command="uvx", args=["mcp-server-fetch"]) filesystem_mcp = MCPClient( command="npx", args=["-y", "@modelcontextprotocol/server-filesystem", os.getcwd()] ) print("✓ Ready!") ``` -------------------------------- ### Install aisuite Library Source: https://github.com/andrewyng/aisuite/blob/main/README.md Install the base aisuite Python package or include specific provider SDKs. You will also need API keys for the providers you intend to use. ```shell pip install aisuite # base package, no provider SDKs pip install 'aisuite[anthropic]' # with a specific provider's SDK pip install 'aisuite[all]' # with all provider SDKs ``` -------------------------------- ### Install Vertex AI SDK Source: https://github.com/andrewyng/aisuite/blob/main/guides/google.md Install the Vertex AI SDK using pip to enable interaction with Google's AI services. ```shell pip install vertexai ``` -------------------------------- ### Sample Query Example Source: https://github.com/andrewyng/aisuite/blob/main/aisuite-js/examples/chat-app/README.md Examples of queries you can use to test the chat application's capabilities with different AI models. ```text "What is the weather in Tokyo?" ``` ```text "Write a poem about the weather in Tokyo." ``` ```text "Write a python program to print the fibonacci sequence." ``` ```text "Write test cases for this program." ``` -------------------------------- ### Install Rust for Tauri Source: https://github.com/andrewyng/aisuite/blob/main/platform/surfaces/gui/README.md Install the Rust toolchain using the provided script. This is required for building the Tauri desktop application. ```bash curl https://sh.rustup.rs -sSf | sh # install Rust, then add the Tauri scaffold ``` -------------------------------- ### Setup Python Path Source: https://github.com/andrewyng/aisuite/blob/main/examples/client.ipynb Appends the 'aisuite' directory to the system path for module imports. ```python import sys from dotenv import load_dotenv, find_dotenv sys.path.append('../../aisuite') ``` -------------------------------- ### Example Output: Question and Answers Source: https://github.com/andrewyng/aisuite/blob/main/examples/AISuiteDemo.ipynb Example of the output format for a generated question and its two corresponding answers from different AI models. ```python ('Original text:\n' " Here's a short question suitable for asking an LLM:\n\nWhat are the potential benefits and risks of artificial intelligence in healthcare?\n\n") ('Option 1 text:\n' ' **Benefits:**\n1. Improved diagnostics and personalized treatment plans.\n2. Increased efficiency in administrative tasks.\n3. Faster drug discovery and development.\n4. Enhanced patient monitoring and support.\n\n**Risks:**\n1. Privacy and data security concerns.\n2. Potential biases in AI algorithms.\n3. Over-reliance on AI systems by healthcare professionals.\n4. Ethical and accountability issues in decision-making.\n\n') ('Option 2 text:\n' ' The potential benefits of artificial intelligence (AI) in healthcare include:\n\n* Improved diagnosis accuracy and speed\n* Enhanced patient outcomes through personalized medicine\n* Increased efficiency and reduced costs through automation\n* Better disease prevention and detection\n* Enhanced research capabilities and new treatment discoveries\n\nHowever, there are also potential risks, such as:\n\n* Bias in AI decision-making due to flawed data or algorithms\n* Job displacement of healthcare professionals\n* Cybersecurity risks to patient data\n* Dependence on technology leading to deskilling of healthcare workers\n* Unintended consequences of AI-driven decision-making that may not align with human values.\n\nThese benefits and risks highlight the need for responsible development, deployment, and oversight of AI in healthcare.\n\n') ``` -------------------------------- ### Sample User Queries Source: https://github.com/andrewyng/aisuite/blob/main/examples/chat-ui/README.md Examples of user prompts that can be used with the chat UI. ```text User: "What is the weather in Tokyo?" ``` ```text User: "Write a poem about the weather in Tokyo." ``` ```text User: "Write a python program to print the fibonacci sequence." Assistant: "-- Content from LLM 1 --" User: "Write test cases for this program." ``` -------------------------------- ### Install aisuite and MCP dependencies Source: https://github.com/andrewyng/aisuite/blob/main/examples/agents/recipe_chef_assistant.ipynb Install the necessary Python packages for aisuite and its MCP client. Includes support for Jupyter notebooks. ```bash pip install aisuite python-dotenv pip install 'aisuite[mcp]' # Includes MCP client + nest_asyncio for Jupyter support pip install uv # For fetch MCP server ``` -------------------------------- ### Initialize MCP Servers Source: https://github.com/andrewyng/aisuite/blob/main/examples/agents/stock_market_tracker.ipynb Initializes MCP clients for web research (fetch) and file system operations (filesystem). Lists available tools for each server. Ensure MCP servers are installed. ```python # Fetch MCP Server - for web research fetch_mcp = MCPClient( command="uvx", args=["mcp-server-fetch"], name="fetch" ) # Filesystem MCP Server - for saving HTML files ilesystem_mcp = MCPClient( command="npx", args=["-y", "@modelcontextprotocol/server-filesystem", os.getcwd()], name="filesystem" ) print("✓ MCP servers initialized") print(f"\nAvailable tools:") print(f" - Fetch: {[tool['name'] for tool in fetch_mcp.list_tools()]}") print(f" - Filesystem: {[tool['name'] for tool in filesystem_mcp.list_tools()]}") ``` -------------------------------- ### Install mistralai Python Client Source: https://github.com/andrewyng/aisuite/blob/main/guides/mistral.md Install the mistralai Python client using pip or poetry. This is necessary to use Mistral models with aisuite. ```shell pip install mistralai ``` ```shell poetry add mistralai ``` -------------------------------- ### Example Output: Another Question and Answers Source: https://github.com/andrewyng/aisuite/blob/main/examples/AISuiteDemo.ipynb Example of the output format for a different generated question and its two corresponding answers from different AI models. ```python ('Original text:\n' ' What are the potential applications of large language models in healthcare?\n\n') ('Option 1 text:\n' ' Large language models have numerous potential applications in healthcare, including:\n\n1. **Clinical Decision Support**: Providing doctors with accurate diagnoses, treatment options, and medication recommendations.\n2. **Medical Text Analysis**: Analyzing large amounts of medical literature, patient records, and clinical notes to identify patterns and insights.\n3. **Patient Engagement**: Generating personalized health summaries, communicating medical information in simple language, and facilitating patient-provider communication.\n4. **Disease Surveillance**: Monitoring social media and online platforms for disease outbreaks and tracking epidemiological trends.\n5. **Medical Writing Assistance**: Assisting healthcare professionals in generating medical reports, discharge summaries, and other documents.\n6. **Chatbots and Virtual Assistants**: Offering patients timely support and answers to medical queries.\n7. **Research and Development**: Accelerating biomedical research by analyzing large datasets, identifying research gaps, and suggesting potential areas of investigation.\n\nThese applications have the potential to improve healthcare outcomes, reduce costs, and enhance patient experiences.\n\n') ('Option 2 text:\n' ' Large language models in healthcare could potentially be used for:\n\n1. Clinical decision support\n2. Medical literature analysis and summarization\n3. Patient triage and symptom checking\n4. Medical education and training\n5. Automated medical coding and documentation\n6. Drug discovery and development\n7. Personalized treatment recommendations\n8. Health-related chatbots for patient engagement\n9. Medical research and hypothesis generation\n10. Natural language processing of electronic health records\n\nThese applications could help improve efficiency, accuracy, and accessibility in various aspects of healthcare.\n\n') ``` -------------------------------- ### Install and Run aisuite-code from Package Directory Source: https://github.com/andrewyng/aisuite/blob/main/cli/py/aisuite-code-cli/TRY_IT.md Install the aisuite-code package using Poetry and then run the CLI tool from its package directory. This method is useful for development or when working within the package's specific environment. ```bash cd cli/py/aisuite-code-cli python3 -m poetry install python3 -m poetry run aisuite-code --cwd /tmp/aisuite-cli-play --viewer ``` -------------------------------- ### Example Prompt: Create and Run Python Code Source: https://github.com/andrewyng/aisuite/blob/main/cli/py/aisuite-code-cli/TRY_IT.md A prompt to generate a Python file with a specific function and main block, then execute it. File writes and shell commands require user approval. ```text Create app.py with an add(a, b) function and a small main block that prints add(2, 3). Then run it. ``` -------------------------------- ### Install Filesystem MCP Server Source: https://github.com/andrewyng/aisuite/blob/main/examples/mcp_tools_example.ipynb Install the filesystem MCP server using npm. This server allows AI models to access files in the specified directory. ```bash npm install -g @modelcontextprotocol/server-filesystem ``` -------------------------------- ### Install Cohere Python Client Source: https://github.com/andrewyng/aisuite/blob/main/guides/cohere.md Install the Cohere Python client using pip or poetry. This is required to use Cohere models with aisuite. ```shell pip install cohere ``` ```shell poetry add cohere ``` -------------------------------- ### Check MCP Server Installation Source: https://github.com/andrewyng/aisuite/blob/main/tests/mcp/README.md Verify that the MCP server can be installed using npx. This command helps troubleshoot hanging or timing out tests. ```bash npx -y @modelcontextprotocol/server-filesystem --help ``` -------------------------------- ### Use MCPClient as a Context Manager Source: https://github.com/andrewyng/aisuite/blob/main/examples/mcp_tools_example.ipynb Recommended approach for using MCPClient, ensuring automatic cleanup of connections. This example demonstrates querying file information within a specified directory. ```python # Using context manager ensures proper cleanup with MCPClient( command="npx", args=["-y", "@modelcontextprotocol/server-filesystem", os.getcwd()] ) as mcp: response = client.chat.completions.create( model="openai:gpt-4o", messages=[{"role": "user", "content": "How many files are in the current directory?"}], tools=mcp.get_callable_tools(), max_turns=2 ) print(response.choices[0].message.content) # Connection is automatically closed after the with block ``` -------------------------------- ### Install OpenAI Python Client Source: https://github.com/andrewyng/aisuite/blob/main/guides/deepseek.md Install the `openai` Python client using pip or poetry. This client is used to interact with the DeepSeek API. ```shell pip install openai ``` ```shell poetry add openai ``` -------------------------------- ### Environment Setup and Verification Source: https://github.com/andrewyng/aisuite/blob/main/examples/agents/stock_market_tracker.ipynb Loads environment variables, verifies the ANTHROPIC_API_KEY, and prints working directory and current date. Ensure your .env file contains the necessary API key. ```python import os import json from pathlib import Path from dotenv import load_dotenv from datetime import datetime import aisuite as ai from aisuite.mcp import MCPClient # Load environment variables load_dotenv() # Verify required API keys if not os.getenv("ANTHROPIC_API_KEY"): raise ValueError( "Missing ANTHROPIC_API_KEY\n" "Please add it to your .env file" ) print("✓ Environment configured") print(f"✓ Working directory: {os.getcwd()}") print(f"✓ Today's date: {datetime.now().strftime('%Y-%m-%d')}") print("\nReady to track the markets!") ``` -------------------------------- ### Install Anthropic Python Client Source: https://github.com/andrewyng/aisuite/blob/main/guides/anthropic.md Install the official Anthropic Python client library using pip or poetry. This is required to interact with Anthropic's API. ```shell pip install anthropic ``` ```shell poetry add anthropic ``` -------------------------------- ### Set Up MCP Servers for Fetch and Memory Source: https://github.com/andrewyng/aisuite/blob/main/examples/agents/movie_buff_assistant.ipynb Configure and start the MCP servers for movie data fetching (from the web) and memory storage (user preferences). The memory server uses a JSONL file to store preferences. ```python # Start fetch server (for getting movie data from the web) fetch_mcp = MCPClient( command="uvx", args=["mcp-server-fetch"], name="fetch" ) # Set up memory file for your movie preferences memory_file = os.path.join(os.getcwd(), "movie_memory.jsonl") # Start memory server (for remembering your preferences) memory_mcp = MCPClient( command="npx", args=["-y", "@modelcontextprotocol/server-memory"], env={"MEMORY_FILE_PATH": memory_file}, name="memory" ) print("Fetch server ready - can research movies from the web") print("Memory server ready - will remember your preferences") print(f"📁 Memories stored in: {memory_file}") ``` -------------------------------- ### Example Prompt: Git Status and Diff Source: https://github.com/andrewyng/aisuite/blob/main/cli/py/aisuite-code-cli/TRY_IT.md A prompt to retrieve the current Git status and diff. These Git operations are read-only and do not require approval. ```text Show git status and git diff. ``` -------------------------------- ### Initialize Client and Define Messages Source: https://github.com/andrewyng/aisuite/blob/main/examples/aisuite_tool_abstraction.ipynb Initializes the AI Suite client and sets up the user messages for a chat completion request. Ensure the `aisuite` library is installed. ```python from aisuite import Client client = Client() messages = [{"role": "user", "content": "Can you plan a picnic for today afternoon in San Francisco? Check the temperature and if its raining."}] ``` -------------------------------- ### Setup Environment for AI Suite Source: https://github.com/andrewyng/aisuite/blob/main/examples/aisuite_tool_abstraction.ipynb Loads environment variables from a .env file and sets a specific environment variable to enable multi-turn conversations. Ensure the .env file is in the correct location. ```python import json import sys from dotenv import load_dotenv, find_dotenv import os sys.path.append('../../aisuite') # Load from .env file if available load_dotenv(find_dotenv()) os.environ['ALLOW_MULTI_TURN'] = 'true' ``` -------------------------------- ### Initialize Client and Load Environment Variables Source: https://github.com/andrewyng/aisuite/blob/main/examples/simple_tool_calling.ipynb Sets up the necessary environment variables and initializes the AI client. Ensure your .env file is correctly configured. ```python import json import sys from dotenv import load_dotenv, find_dotenv import os sys.path.append('../../aisuite') # Load from .env file if available load_dotenv(find_dotenv()) ``` -------------------------------- ### Python Scripted Provider and Agent Setup Source: https://github.com/andrewyng/aisuite/blob/main/examples/agents/local_observability_demo.ipynb Defines helper functions for tool calls and responses, a ScriptedProvider class, and sets up an AI client with scripted responses. This is used to simulate agent behavior deterministically. ```python from pathlib import Path import tempfile import json from types import SimpleNamespace from aisuite.llm.base import ChatCompletionMessageToolCall, Function, Message import aisuite.llm.base as ai import aisuite.viewer as viewer def tool_call(name, arguments, call_id): return ChatCompletionMessageToolCall( id=call_id, type='function', function=Function(name=name, arguments=arguments), ) def response(content=None, tool_calls=None): message = Message(role='assistant', content=content, tool_calls=tool_calls) return SimpleNamespace(choices=[SimpleNamespace(message=message)]) class ScriptedProvider: def __init__(self, responses): self.responses = list(responses) def chat_completions_create(self, *_args, **_kwargs): if not self.responses: raise RuntimeError('No scripted responses left.') return self.responses.pop(0) workspace = Path(tempfile.mkdtemp(prefix='aisuite-notebook-demo-')) (workspace / 'README.md').write_text('notebook demo workspace\n', encoding='utf-8') large_content = 'notebook artifact line\n' * 1300 client = ai.Client() client.providers['openai'] = ScriptedProvider([ response(None, [tool_call('list_files', '{"path": "."}', 'call_list פורמט')]), response('I found a small demo workspace.'), response(None, [tool_call('write_file', json.dumps({'path': 'large.txt', 'content': large_content}), 'call_write')]), response('I wrote a large file so the viewer can show an artifactized argument.'), ]) def approve_all(context): return ai.ToolPolicyDecision(allowed=True, reason='approved by notebook demo') scripted_agent = ai.Agent( name='notebook_scripted_demo', model='openai:gpt-4o-mini', instructions='Use tools to create a deterministic local observability demo.', tools=ai.toolkits.files(root=workspace, allow_write=True), tags=['notebook', 'scripted'], metadata={'demo': 'local_observability', 'mode': 'scripted'}, ) artifact_store = ai.FileArtifactStore(workspace / '.aisuite' / 'artifacts') scripted_result = ai.Runner.run_sync( scripted_agent, 'Inspect this workspace and write a large demo file.', client=client, trace_sinks=[viewer.trace_sink], tool_policy=approve_all, artifact_store=artifact_store, run_name='scripted_artifact_demo', group_id='notebook-demo', max_turns=5, ) scripted_result.final_output ``` -------------------------------- ### MCP Tools Inline Configuration Source: https://github.com/andrewyng/aisuite/blob/main/docs/agents-quickstart.md Integrate Model Context Protocol (MCP) server tools by providing inline configuration. This example lists files in the current directory using an MCP filesystem server. ```python response = client.chat.completions.create( model="openai:gpt-4o", messages=[{"role": "user", "content": "List the files in the current directory"}], tools=[{ "type": "mcp", "name": "filesystem", "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/directory"] }], max_turns=3 ) ``` -------------------------------- ### Start an in-memory viewer Source: https://github.com/andrewyng/aisuite/blob/main/examples/agents/local_observability_demo.ipynb Initializes an AI Suite viewer using an InMemoryTraceStore. This allows runs to be observed without needing a persistent JSONL file. The viewer's URL is provided for access. ```python store = ai.tracing.InMemoryTraceStore() viewer = ai.tracing.start_viewer(None, port=0, trace_store=store) viewer.url ``` -------------------------------- ### Run aisuite-code from Repository Root Source: https://github.com/andrewyng/aisuite/blob/main/cli/py/aisuite-code-cli/TRY_IT.md Execute the aisuite-code CLI tool directly from the repository's root directory. This command starts the tool with a specified working directory and enables the viewer. ```bash ./scripts/aisuite-code --cwd /tmp/aisuite-cli-play --viewer ``` -------------------------------- ### Initialize aisuite Client and Verify API Key Source: https://github.com/andrewyng/aisuite/blob/main/examples/agents/movie_buff_assistant.ipynb Set up the Python environment by adding the repository root to sys.path for development, loading environment variables, and verifying the OpenAI API key. This code prepares the aisuite client for use. ```python import os import sys from pathlib import Path # Add parent directory to Path - to pick up aisuite for development # Skip this step if you're running from an installed package repo_root = Path().absolute().parent.parent if str(repo_root) not in sys.path: sys.path.insert(0, str(repo_root)) from dotenv import load_dotenv from aisuite import Client from aisuite.mcp import MCPClient # Needed to connect to MCP servers. load_dotenv() # Verify API key if not os.getenv("OPENAI_API_KEY"): raise ValueError("Add OPENAI_API_KEY to .env file!") print("✓ Ready to discover movies!") ``` -------------------------------- ### Chat with MCP Filesystem Tool Source: https://github.com/andrewyng/aisuite/blob/main/README.md Interact with a Model Context Protocol (MCP) server for filesystem operations using the chat completions API. This example lists files in a specified directory. ```python client = ai.Client() response = client.chat.completions.create( model="openai:gpt-4o", messages=[{"role": "user", "content": "List the files in the current directory"}], tools=[{ "type": "mcp", "name": "filesystem", "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/directory"] }], max_turns=3 ) print(response.choices[0].message.content) ``` -------------------------------- ### Install Python Test Dependencies Source: https://github.com/andrewyng/aisuite/blob/main/tests/mcp/README.md Installs necessary Python packages for running the MCP integration tests. Ensure you have Python and pip installed. ```bash pip install pytest pytest-asyncio python-dotenv ``` -------------------------------- ### Call Model with Tools (Claude Example) Source: https://github.com/andrewyng/aisuite/blob/main/examples/aisuite_tool_abstraction.ipynb Creates a chat completion request using the Anthropic Claude model, providing user messages and a list of available tools. This demonstrates model flexibility. ```python response = client.chat.completions.create( model="anthropic:claude-3-5-sonnet-20241022", messages=messages, tools=[get_current_temperature, is_it_raining], max_turns=4) print(response.choices[0].message.content) ``` -------------------------------- ### Initialize MCP Filesystem Server Source: https://github.com/andrewyng/aisuite/blob/main/examples/agents/snake_game_generator.ipynb Sets up the MCP filesystem server to allow the AI to write files. Ensure your API key is set in the .env file. ```python import os from dotenv import load_dotenv import aisuite as ai from aisuite.mcp import MCPClient from IPython.display import IFrame, display # For displaying HTML file load_dotenv() # Initialize filesystem MCP server for file writing filesystem_mcp = MCPClient( command="npx", args=["-y", "@modelcontextprotocol/server-filesystem", os.getcwd()] ) print("✓ Ready!") ``` -------------------------------- ### Set up environment and import libraries Source: https://github.com/andrewyng/aisuite/blob/main/examples/QnA_with_pdf.ipynb Configures the Python environment by adding a directory to sys.path and loading environment variables. ```python import sys from dotenv import load_dotenv, find_dotenv sys.path.append('../aisuite') ``` -------------------------------- ### Initialize aisuite Client and MCP Servers Source: https://github.com/andrewyng/aisuite/blob/main/examples/agents/recipe_chef_assistant.ipynb Set up the aisuite client, load environment variables, and initialize MCP servers for fetching recipes and managing memory. Ensures the Anthropic API key is set. ```python import os import sys from pathlib import Path # Add parent directory to path for development # Skip this step if you're running from an installed package repo_root = Path().absolute().parent.parent if str(repo_root) not in sys.path: sys.path.insert(0, str(repo_root)) from dotenv import load_dotenv from aisuite import Client from aisuite.mcp import MCPClient load_dotenv() # Verify API key if not os.getenv("ANTHROPIC_API_KEY"): raise ValueError("❌ Add ANTHROPIC_API_KEY to .env file!") print("✓ Ready to cook up some recipes!") ``` ```python # Set up memory file for your cooking preferences memory_file = os.path.join(os.getcwd(), "recipe_memory.jsonl") # Start fetch server (for getting recipes from the web) fetch_mcp = MCPClient( command="uvx", args=["mcp-server-fetch"], name="fetch" ) # Start memory server (for remembering preferences and recipes) memory_mcp = MCPClient( command="npx", args=["-y", "@modelcontextprotocol/server-memory"], env={"MEMORY_FILE_PATH": memory_file}, name="memory" ) print("🔍 Fetch server ready - can research recipes from the web") print("🧠 Memory server ready - will remember your preferences") print(f"📁 Recipes stored in: {memory_file}") ``` -------------------------------- ### Initialize and List Tools Source: https://github.com/andrewyng/aisuite/blob/main/examples/aisuite_tool_abstraction.ipynb Instantiate the `Tools` class with a list of available tools and then call the `tools()` method to see the registered tools. ```python from aisuite import Tools tools = Tools(tools=[get_current_temperature, is_it_raining]) tools.tools() ``` -------------------------------- ### Initialize AI Client and Tools Source: https://github.com/andrewyng/aisuite/blob/main/examples/agents/stock_market_tracker.ipynb Initializes the aisuite client and combines tools from both fetch and filesystem MCP servers. This prepares the agent for market data retrieval. ```python # Initialize aisuite client client = ai.Client() # Combine all available tools all_tools = fetch_mcp.get_callable_tools() + filesystem_mcp.get_callable_tools() print("📈 Fetching latest stock market data...\n") print("=" * 60) ``` -------------------------------- ### Install Test Dependencies Source: https://github.com/andrewyng/aisuite/blob/main/tests/mcp/README.md Install necessary dependencies for running tests, including pytest and pytest-asyncio. This command resolves import errors. ```bash pip install pytest pytest-asyncio ``` -------------------------------- ### Verify Node.js and npx Installation Source: https://github.com/andrewyng/aisuite/blob/main/tests/mcp/README.md Checks if Node.js and npx are installed on your system, which are required for running the Anthropic filesystem MCP server. ```bash npx --version ``` -------------------------------- ### Initialize MCP Servers for Web Fetching and File System Source: https://github.com/andrewyng/aisuite/blob/main/examples/agents/stock_market_mini_tracker.ipynb Sets up MCP clients for web fetching and file system operations. Requires OPENAI_API_KEY in .env. The fetch_mcp is configured for 'uvx mcp-server-fetch' and filesystem_mcp for 'npx -y @modelcontextprotocol/server-filesystem'. ```python import os from datetime import datetime from dotenv import load_dotenv import aisuite as ai from aisuite.mcp import MCPClient load_dotenv() # Initialize MCP servers for web fetching and file writing fetch_mcp = MCPClient(command="uvx", args=["mcp-server-fetch"]) filesystem_mcp = MCPClient( command="npx", args=["-y", "@modelcontextprotocol/server-filesystem", os.getcwd()] ) print("✓ Ready!") ``` -------------------------------- ### Connect to Filesystem MCP Server and List Tools Source: https://github.com/andrewyng/aisuite/blob/main/examples/mcp_tools_example.ipynb Connect to a filesystem MCP server using MCPClient, providing the command to execute and arguments. This grants the AI access to files in the current working directory and lists available tools. ```python # Connect to the filesystem MCP server # This gives the AI access to files in the specified directory mcp_client = MCPClient( command="npx", args=["-y", "@modelcontextprotocol/server-filesystem", os.getcwd()] ) print(f"Connected to MCP server: {mcp_client}") print(f"\nAvailable tools:") for tool in mcp_client.list_tools(): print(f" - {tool['name']}: {tool.get('description', 'No description')}") ``` -------------------------------- ### Install Pre-commit Hooks Source: https://github.com/andrewyng/aisuite/blob/main/CONTRIBUTING.md Install pre-commit hooks to automatically format your code and ensure consistency before committing. This helps maintain code style standards. ```bash pre-commit install ``` -------------------------------- ### Initialize MCPClient and Load Environment Variables Source: https://github.com/andrewyng/aisuite/blob/main/examples/mcp_tools_example.ipynb Load environment variables for API keys and initialize the MCPClient to connect to a filesystem MCP server. Ensure the OPENAI_API_KEY is set. ```python import os from dotenv import load_dotenv import aisuite as ai from aisuite.mcp import MCPClient # Load environment variables (API keys) load_dotenv() # Verify API key is set if not os.getenv("OPENAI_API_KEY"): raise ValueError("Please set OPENAI_API_KEY environment variable") ``` -------------------------------- ### Initial Model Request with Tool Definitions Source: https://github.com/andrewyng/aisuite/blob/main/examples/simple_tool_calling.ipynb Configure the model and messages, then make an initial request to the language model with available tools. This sets up the model to potentially identify and request the use of specific tools. ```python model = "xai:grok-2-latest" messages = [{ "role": "user", "content": "What is the current temperature in San Francisco in Celsius?" }] tools = get_available_tools() # Make the initial request to OpenAI API response = client.chat.completions.create( model=model, messages=messages, tools=tools) print(response) print(response.choices[0].message) ``` -------------------------------- ### Research Director's Filmography and Get Recommendations Source: https://github.com/andrewyng/aisuite/blob/main/examples/agents/movie_buff_assistant.ipynb This code snippet allows you to research a director's filmography and get personalized movie recommendations based on your stored preferences. It also stores the top recommendation in memory. ```python response = client.chat.completions.create( model="openai:gpt-4o", messages=[{ "role": "user", "content": """Research Denis Villeneuve's filmography from IMDb or Wikipedia. 1. List his major films 2. Based on my interests and moveis I liked earlier (check memory!), which of his films would I love? 3. Store the top recommendation in memory Make it exciting - I love discovering new directors!""" }], tools=all_tools, max_turns=10 ) print("="*60) print("🎥 DIRECTOR DEEP DIVE") print("="*60) print(response.choices[0].message.content) ``` -------------------------------- ### Initialize aisuite Client Source: https://github.com/andrewyng/aisuite/blob/main/examples/agents/movie_buff_assistant.ipynb Instantiate the aisuite Client. This client will be used to interact with the LLM and the configured MCP tools. ```python client = Client() ``` -------------------------------- ### Local Model Completion via Ollama Source: https://github.com/andrewyng/aisuite/blob/main/docs/chat-completions-quickstart.md Run chat completions locally using Ollama. No API key is required for this setup. ```python response = client.chat.completions.create( model="ollama:llama3.3", messages=[{"role": "user", "content": "Hello!"}], ) ``` -------------------------------- ### Try with different providers Source: https://github.com/andrewyng/aisuite/blob/main/examples/mcp_tools_example.ipynb Iterate through a list of providers to send the same message and collect responses. Ensure API keys are set and providers are installed. ```python providers = [ "openai:gpt-4o", "anthropic:claude-3-5-sonnet-20240620", ] messages = [ {"role": "user", "content": "List the files in the current directory and tell me how many there are."} ] for model in providers: print(f"\n{'='*60}") print(f"Provider: {model}") print(f"{'='*60}\n") try: response = client.chat.completions.create( model=model, messages=messages, tools=mcp_client.get_callable_tools(), max_turns=3 ) print(response.choices[0].message.content) except Exception as e: print(f"Error: {e}") print("Make sure you have the API key set and provider installed.") ``` -------------------------------- ### Streaming Responses with Abort Controller Source: https://github.com/andrewyng/aisuite/blob/main/aisuite-js/README.md Control streaming responses using an AbortController. This example aborts the stream after 5 seconds and handles the 'AbortError'. ```typescript const controller = new AbortController(); // Abort after 5 seconds setTimeout(() => controller.abort(), 5000); const stream = await client.chat.completions.create({ model: 'anthropic:claude-3-haiku-20240307', messages: [{ role: 'user', content: 'Write a long story' }], stream: true }, { signal: controller.signal }); try { for await (const chunk of stream as AsyncIterable) { process.stdout.write(chunk.choices[0]?.delta?.content || ''); } } catch (error) { if (error.name === 'AbortError') { console.log('Stream aborted'); } } ``` -------------------------------- ### Create and Run AI Agent Chat Completion Source: https://github.com/andrewyng/aisuite/blob/main/examples/agents/world_weather_dashboard.ipynb Initializes the AI client, combines tools from MCP clients, selects a language model, and sends the prompt to generate the weather dashboard. This step may take a significant amount of time. ```python client = ai.Client() tools = fetch_mcp.get_callable_tools() + filesystem_mcp.get_callable_tools() # Choose your model (uncomment one): model = "openai:gpt-5.1" # model = "anthropic:claude-sonnet-4-5" print("Fetching weather for world capitals...\n") print("(This may take a minute or more\n") response = client.chat.completions.create( model=model, messages=[{"role": "user", "content": prompt}], tools=tools, max_turns=20 ) print("✓ WEATHER DASHBOARD CREATED!") ``` -------------------------------- ### Setting Up Multiple API Keys Source: https://github.com/andrewyng/aisuite/blob/main/examples/AISuiteDemo.ipynb Sets up API keys for OpenAI and Anthropic as environment variables using getpass for secure input, enabling interaction with models from different providers. ```python os.environ['OPENAI_API_KEY'] = getpass('Enter your OPENAI API key: ') os.environ['ANTHROPIC_API_KEY'] = getpass('Enter your ANTHROPIC API key: ') ``` -------------------------------- ### Ollama Phi3 Mini Completion Source: https://github.com/andrewyng/aisuite/blob/main/examples/client.ipynb This example shows how to generate a chat completion using Ollama with the Phi3 Mini model. Adjust the temperature parameter for creativity. ```python ollama_tinyllama = "ollama:tinyllama" ollama_phi3mini = "ollama:phi3:mini" response = client.chat.completions.create(model=ollama_phi3mini, messages=messages, temperature=0.75) print(response.choices[0].message.content) ``` -------------------------------- ### Example Prompt: Review Changes with Reviewer Subagent Source: https://github.com/andrewyng/aisuite/blob/main/cli/py/aisuite-code-cli/TRY_IT.md A prompt to engage the reviewer subagent for code review of current changes. This interaction assumes Git operations have been performed. ```text Ask the reviewer subagent to review the current changes. ``` -------------------------------- ### Make a Request to Model Without Tools Source: https://github.com/andrewyng/aisuite/blob/main/examples/simple_tool_calling.ipynb Example of sending a simple text-based prompt to a model without any tool integration. Useful for basic text generation tasks. ```python from aisuite import Client client = Client() # Configuring Azure. Rest all providers use environment variables for their parameters. client.configure({"azure" : { "api_key": os.environ["AZURE_API_KEY"], "base_url": "https://aisuite-mistral-large-2407.westus3.models.ai.azure.com/v1/", }}) # model = "anthropic:claude-3-5-sonnet-20241022" # model = "aws:mistral.mistral-7b-instruct-v0:2" # model = "azure:aisuite-mistral-large" # model = "cohere:command-r-plus" # model = "deepseek:deepseek-chat" # model = "fireworks:accounts/fireworks/models/llama-v3p1-405b-instruct" # model = "google:gemini-1.5-pro-002" # model = "groq:llama-3.3-70b-versatile" # model = "huggingface:meta-llama/Llama-3.1-8B-Instruct" # model = "mistral:mistral-large-latest" # model = "nebius:" # model = "ollama:" # model = "sambanova:Meta-Llama-3.3-70B-Instruct" # model = "together:meta-llama/Llama-3.3-70B-Instruct-Turbo" # model = "watsonx:" model = "xai:grok-2-latest" messages = [{ "role": "user", "content": "What is the current temperature in San Francisco in Celsius?"}] response = client.chat.completions.create( model=model, messages=messages) print("For model: " + model) print(response.choices[0].message.content) ``` -------------------------------- ### Configure AISuite Client Source: https://github.com/andrewyng/aisuite/blob/main/aisuite-js/README.md Shows how to initialize the AISuite client with API keys and optional base URLs for different providers like OpenAI, Anthropic, and Deepgram. ```typescript const client = new Client({ openai?: { apiKey: string; baseURL?: string; organization?: string; }, anthropic?: { apiKey: string; baseURL?: string; }, deepgram?: { apiKey: string; baseURL?: string; } }); ``` -------------------------------- ### Create Chat Completion with DeepSeek Source: https://github.com/andrewyng/aisuite/blob/main/guides/deepseek.md Use the AI Suite client to create a chat completion with a DeepSeek model. Ensure the `openai` client is installed and the API key is set. ```python import aisuite as ai client = ai.Client() provider = "deepseek" model_id = "deepseek-chat" messages = [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What’s the weather like in San Francisco?"}, ] response = client.chat.completions.create( model=f"{provider}:{model_id}", messages=messages, ) print(response.choices[0].message.content) ``` -------------------------------- ### Tool/Function Calling with Anthropic Source: https://github.com/andrewyng/aisuite/blob/main/aisuite-js/README.md Implement tool/function calling for LLMs. This example defines a 'get_weather' tool and demonstrates how to use it with the Anthropic provider. The interface is consistent across all supported providers. ```typescript const tools = [ { type: 'function' as const, function: { name: 'get_weather', description: 'Get current weather for a location', parameters: { type: 'object', properties: { location: { type: 'string', description: 'City name' } }, required: ['location'] } } } ]; // Works identically across all providers const response = await client.chat.completions.create({ model: 'anthropic:claude-3-haiku-20240307', messages: [{ role: 'user', content: 'What\'s the weather in NYC?' }], tools, tool_choice: 'auto' }); if (response.choices[0].message.tool_calls) { console.log('Tool calls:', response.choices[0].message.tool_calls); } ``` -------------------------------- ### Get Personalized Movie Recommendations Source: https://github.com/andrewyng/aisuite/blob/main/examples/agents/movie_buff_assistant.ipynb Use this snippet to ask the assistant for movie recommendations based on its memory of your preferences. It reminds you of liked movies and suggests new ones with explanations. ```python response = client.chat.completions.create( model="openai:gpt-4o", messages=[{ "role": "user", "content": """Tell me what you know about my movie preferences from memory, and suggest something new: 1. Remind me what movies I liked 2. Suggest 3 movies I'd probably enjoy 3. Explain why each recommendation fits my taste Be enthusiastic like a friend recommending movies!""" }], tools=memory_mcp.get_callable_tools(), max_turns=10 ) print("="*60) print("💡 PERSONALIZED RECOMMENDATIONS") print("="*60) print(response.choices[0].message.content) ```