### Run ExLLM Example App Interactively Source: https://github.com/azmaveth/ex_llm/blob/master/examples/README.md Start the example application in interactive mode. Ensure Ollama is installed and running. ```bash # Ensure Ollama is running: ollama serve # if not already running # Run the example app interactively: ./example_app.exs ``` -------------------------------- ### Install Go Gemini Library Source: https://github.com/azmaveth/ex_llm/blob/master/docs/gemini/GEMINI-DOCS-03-LIBRARIES.md Install the recommended Go library for the Gemini API using go get. ```bash go get google.golang.org/genai ``` -------------------------------- ### Install and Serve Ollama Source: https://github.com/azmaveth/ex_llm/blob/master/TEST_SETUP.md Installs Ollama using a script and starts the Ollama service. A model is then pulled for testing. ```bash # Install Ollama curl -fsSL https://ollama.ai/install.sh | sh # Start Ollama service ollama serve # Pull a model for testing ollama pull llama3.2 # Set environment variable (if not using default port) export OLLAMA_HOST=http://localhost:11434 ``` -------------------------------- ### Create SFT Job with All Settings Source: https://github.com/azmaveth/ex_llm/blob/master/docs/fireworks/llms-full.txt Example of starting a supervised fine-tuning job with various optional settings. ```shell firectl create sftj \ --base-model llama-v3p1-8b-instruct \ --dataset cancerset \ --output-model my-tuned-model \ --job-id my-fine-tuning-job \ --learning-rate 0.0001 \ --epochs 2 \ --early-stop \ --evaluation-dataset my-eval-set ``` -------------------------------- ### Advanced Agent Example Setup Source: https://github.com/azmaveth/ex_llm/blob/master/docs/lmstudio/llms.txt Provides the initial Python imports for an advanced agent example that combines LM Studio models with custom functions. This setup allows the agent to perform actions like opening URLs, checking time, and analyzing file systems. ```python import json from urllib.parse import urlparse import webbrowser from datetime import datetime import os from openai import OpenAI ``` -------------------------------- ### Install and Serve Ollama Source: https://github.com/azmaveth/ex_llm/blob/master/test/README.md Installs Ollama locally and starts the Ollama service. This is required for running tests that depend on local LLM services. ```bash # Install Ollama curl -fsSL https://ollama.ai/install.sh | sh # Start Ollama service ollama serve ``` -------------------------------- ### Clone and Install ML-Agents Library Source: https://github.com/azmaveth/ex_llm/blob/master/docs/huggingface-hub/llms.txt Clone the ML-Agents repository and install the necessary packages. This is the initial setup required to work with ML-Agents. ```bash # Clone the repository git clone https://github.com/Unity-Technologies/ml-agents # Go inside the repository and install the package cd ml-agents pip3 install -e ./ml-agents-envs pip3 install -e ./ml-agents ``` -------------------------------- ### GitHub Actions CI/CD Configuration Example Source: https://github.com/azmaveth/ex_llm/blob/master/test/ENVIRONMENT_SETUP.md Example environment variable setup for a GitHub Actions workflow, enabling test caching and skipping Bumblebee tests. ```yaml # Example GitHub Actions setup env: EX_LLM_TEST_CACHE_ENABLED: true BUMBLEBEE_SKIP_TESTS: true # Add API keys as secrets ``` -------------------------------- ### Fal Provider Setup Source: https://github.com/azmaveth/ex_llm/blob/master/docs/vercel/llms.txt Install the Fal provider using npm, pnpm, or yarn. ```APIDOC ## Installation ### npm ```bash npm install @ai-sdk/fal ``` ### pnpm ```bash pnpm add @ai-sdk/fal ``` ### yarn ```bash yarn add @ai-sdk/fal ``` ``` -------------------------------- ### Quick Example: Chat with Llama Model (TypeScript) Source: https://github.com/azmaveth/ex_llm/blob/master/docs/lmstudio/llms.txt Demonstrates how to initialize the LMStudioClient, load a Llama model, and get a response to a prompt. Requires the @lmstudio/sdk package. ```typescript import { LMStudioClient } from "@lmstudio/sdk"; const client = new LMStudioClient(); const model = await client.llm.model("llama-3.2-1b-instruct"); const result = await model.respond("What is the meaning of life?"); console.info(result.content); ``` -------------------------------- ### Run OAuth2 Setup Script Source: https://github.com/azmaveth/ex_llm/blob/master/docs/gemini/OAUTH2_SETUP_GUIDE.md Execute the Elixir script to start a local web server, obtain authorization, and save access/refresh tokens to a file. ```bash # From the ex_llm directory elixir scripts/setup_oauth2.exs ``` -------------------------------- ### Generate Content with PHP (Guzzle) Source: https://github.com/azmaveth/ex_llm/blob/master/docs/openrouter/llms-full.txt This PHP example uses the Guzzle HTTP client to send a GET request. Make sure Guzzle is installed via Composer. ```php request('GET', 'https://openrouter.ai/api/v1/generation?id=id', [ 'headers' => [ 'Authorization' => 'Bearer ', ], ]); echo $response->getBody(); ?> ``` -------------------------------- ### Example: Create a Deployment Source: https://github.com/azmaveth/ex_llm/blob/master/docs/fireworks/llms-full.txt An example of creating a deployment for the 'falcon-7b' model. ```bash firectl create deployment falcon-7b ``` -------------------------------- ### Python: Get Text Embeddings with OpenAI Client Source: https://github.com/azmaveth/ex_llm/blob/master/docs/lmstudio/llms.txt Example of using the OpenAI Python client to generate text embeddings from LM Studio. Requires the 'openai' library to be installed. ```python from openai import OpenAI client = OpenAI(base_url="http://localhost:1234/v1", api_key="lm-studio") def get_embedding(text, model="model-identifier"): text = text.replace("\n", " ") return client.embeddings.create(input = [text], model=model).data[0].embedding print(get_embedding("Once upon a time, there was a cat.")) ``` -------------------------------- ### Run Reward Kit Examples Source: https://github.com/azmaveth/ex_llm/blob/master/docs/fireworks/llms-full.txt Navigate to the reward-kit directory, activate the virtual environment, and run the cosine_scaled_example.py script to see the reward function in action. ```bash # Make sure you're in the reward-kit directory cd /path/to/reward-kit # Activate the virtual environment source .venv/bin/activate # Run the example python examples/accuracy_length/cosine_scaled_example.py ``` -------------------------------- ### Get API Key using PHP (Guzzle) Source: https://github.com/azmaveth/ex_llm/blob/master/docs/openrouter/llms-full.txt This PHP example uses the Guzzle HTTP client to retrieve your API key. Make sure Guzzle is installed via Composer. ```php request('GET', 'https://openrouter.ai/api/v1/key', [ 'headers' => [ 'Authorization' => 'Bearer ', ], ]); echo $response->getBody(); ?> ``` -------------------------------- ### Provide Router Troubleshooting Context Source: https://github.com/azmaveth/ex_llm/blob/master/docs/gemini/GEMINI-DOCS-23-PROMPT-ENGINEERING.md Include specific troubleshooting guides in the prompt to get customized responses for device issues. This example shows how to provide router LED status information for accurate troubleshooting. ```text What should I do to fix my disconnected wifi? The light on my Google Wifi router is yellow and blinking slowly. ``` ```text A yellow blinking light on your Google Wifi router usually indicates a problem with the internet connection. Here are some steps to troubleshoot and fix the issue: 1. Restart your router and modem: - Unplug your modem from the power outlet and wait for 30 seconds. - Plug your modem back in and wait for it to fully boot up. - Unplug your Google Wifi router and wait for 30 seconds. - Plug your Google Wifi router back in and wait for it to fully boot up. ..... ``` ```text Answer the question using the text below. Respond with only the text provided. Question: What should I do to fix my disconnected wifi? The light on my Google Wifi router is yellow and blinking slowly. Text: Color: Slowly pulsing yellow What it means: There is a network error. What to do: Check that the Ethernet cable is connected to both your router and your modem and both devices are turned on. You might need to unplug and plug in each device again. Color: Fast blinking yellow What it means: You are holding down the reset button and are factory resetting this device. What to do: If you keep holding down the reset button, after about 12 seconds, the light will turn solid yellow. Once it is solid yellow, let go of the factory reset button. Color: Solid yellow What it means: Router is factory resetting. What to do: This can take up to 10 minutes. When it's done, the device will reset itself and start pulsing white, letting you know it's ready for setup. Color: Solid red What it means: Something is wrong. What to do: Critical failure. Factory reset the router. If the light stays red, contact Wifi customer support. ``` ```text Check that the Ethernet cable is connected to both your router and your modem and both devices are turned on. You might need to unplug and plug in each device again. ``` -------------------------------- ### Example: Create a Dataset Source: https://github.com/azmaveth/ex_llm/blob/master/docs/fireworks/llms-full.txt An example of creating a dataset named 'my-dataset' from a local JSONL file. ```bash firectl create dataset my-dataset /path/to/dataset.jsonl ``` -------------------------------- ### Install GitHub App via Claude Code CLI Source: https://github.com/azmaveth/ex_llm/blob/master/docs/anthropic/llms-full.txt Use the /install-github-app command in the Claude Code terminal to automate the setup of the GitHub app and required secrets for GitHub Actions integration. This is the recommended quickstart method for direct Anthropic API users. ```bash /install-github-app ``` -------------------------------- ### Get API Key using Python Source: https://github.com/azmaveth/ex_llm/blob/master/docs/openrouter/llms-full.txt This Python script uses the requests library to get your API key. Make sure to install the library if you haven't already (`pip install requests`). ```python import requests url = "https://openrouter.ai/api/v1/key" headers = {"Authorization": "Bearer "} response = requests.get(url, headers=headers) print(response.json()) ``` -------------------------------- ### example.py - Create File Tool Usage Source: https://github.com/azmaveth/ex_llm/blob/master/docs/lmstudio/llms.txt Demonstrates using the create_file tool with the LM Studio convenience API to generate a file based on an LLM's response. ```python import lmstudio as lms from create_file_tool import create_file model = lms.llm("qwen2.5-7b-instruct") model.act( "Please create a file named output.txt with your understanding of the meaning of life.", [create_file], ) ``` -------------------------------- ### Install Dependencies Source: https://github.com/azmaveth/ex_llm/blob/master/docs/QUICKSTART.md After adding ExLLM to your dependencies, run this command to fetch them. ```bash mix deps.get ``` -------------------------------- ### Completions API Example Source: https://github.com/azmaveth/ex_llm/blob/master/docs/openrouter/llms-full.txt This example demonstrates how to make a POST request to the /v1/completions endpoint to get text completions from a model. ```APIDOC ## POST /v1/completions ### Description This endpoint is used to get text completions from a selected model. It requires a model and a prompt. ### Method POST ### Endpoint https://openrouter.ai/api/v1/completions ### Parameters #### Request Body - **model** (string) - Required - The model to use for completion. - **prompt** (string) - Required - The prompt to send to the model. ### Request Example ```json { "model": "model", "prompt": "prompt" } ``` ### Response #### Success Response (200) - The response body will contain the completion details. ``` -------------------------------- ### Install Sample-Factory Library Source: https://github.com/azmaveth/ex_llm/blob/master/docs/huggingface-hub/llms.txt Install the Sample-Factory library using pip. This library is known to work on Linux and MacOS, with no Windows support currently available. ```bash pip install sample-factory ``` -------------------------------- ### Direct HTTPClient GET Call Source: https://github.com/azmaveth/ex_llm/blob/master/http_client_references.md Example of a direct GET request using the legacy HTTPClient. Found in circuit breaker logic. ```Elixir HTTPClient.get("/api/data") ``` -------------------------------- ### Install Replicate Provider with yarn Source: https://github.com/azmaveth/ex_llm/blob/master/docs/vercel/llms.txt Install the AI SDK and the Replicate provider using yarn. ```bash yarn add ai @ai-sdk/replicate ``` -------------------------------- ### ExLLM Example App CLI Commands Source: https://github.com/azmaveth/ex_llm/blob/master/examples/README.md Execute specific demos or list available options using command-line arguments. Useful for automation or testing specific functionalities. ```bash # Show help and available demos elixir example_app.exs --help # List all available demos elixir example_app.exs --list # Run a specific demo elixir example_app.exs basic-chat # Run a demo with custom arguments elixir example_app.exs basic-chat "What is the weather like?" ``` -------------------------------- ### Install Anthropic TypeScript SDK Source: https://github.com/azmaveth/ex_llm/blob/master/docs/anthropic/llms-full.txt Install the official Anthropic TypeScript SDK using npm. This is required to use the TypeScript code examples. ```bash npm install @anthropic-ai/sdk ``` -------------------------------- ### Install Anthropic Python SDK Source: https://github.com/azmaveth/ex_llm/blob/master/docs/anthropic/llms-full.txt Install the official Anthropic Python SDK using pip. This is required to use the Python code examples. ```bash pip install anthropic ``` -------------------------------- ### Install Replicate Provider with pnpm Source: https://github.com/azmaveth/ex_llm/blob/master/docs/vercel/llms.txt Install the AI SDK and the Replicate provider using pnpm. ```bash pnpm add ai @ai-sdk/replicate ``` -------------------------------- ### General Tool Use for User Requests Source: https://github.com/azmaveth/ex_llm/blob/master/docs/anthropic/llms-full.txt This example shows how to use tools to answer user requests. It includes thinking steps for tool selection and parameter inference. The model will ask for missing parameters if required ones are not provided. ```markdown Answer the user's request using relevant tools (if they are available). Before calling a tool, do some analysis within tags. First, think about which of the provided tools is the relevant tool to answer the user's request. Second, go through each of the required parameters of the relevant tool and determine if the user has directly provided or given enough information to infer a value. When deciding if the parameter can be inferred, carefully consider all the context to see if it supports a specific value. If all of the required parameters are present or can be reasonably inferred, close the thinking tag and proceed with the tool call. BUT, if one of the values for a required parameter is missing, DO NOT invoke the function (not even with fillers for the missing params) and instead, ask the user to provide the missing parameters. DO NOT ask for more information on optional parameters if it is not provided. ``` -------------------------------- ### Task Input Example Source: https://github.com/azmaveth/ex_llm/blob/master/docs/gemini/GEMINI-DOCS-23-PROMPT-ENGINEERING.md Provide clear, step-by-step instructions for tasks you want the model to perform. Specify constraints like the number of items. ```text Give me a simple list of just the things that I must bring on a camping trip. The list should have 5 items. ``` -------------------------------- ### Install Replicate Provider with npm Source: https://github.com/azmaveth/ex_llm/blob/master/docs/vercel/llms.txt Install the AI SDK and the Replicate provider using npm. ```bash npm install ai @ai-sdk/replicate ``` -------------------------------- ### Copying .env Example File Source: https://github.com/azmaveth/ex_llm/blob/master/test/README.md Create a local .env file by copying the example configuration file. This file is used to store sensitive API keys and environment-specific settings. ```bash cp .env.example .env ``` -------------------------------- ### Few-Shot Learning Example Source: https://github.com/azmaveth/ex_llm/blob/master/docs/gemini/GEMINI-DOCS-26-FILES-API.md Use few-shot examples to guide the model's output format and content. This helps the model understand the desired relationship between inputs and outputs. ```text Determine the city along with the landmark. city: Rome, landmark: the Colosseum. city: Beijing, landmark: Forbidden City city: Rio de Janeiro, landmark: Christ the Redeemer statue ``` -------------------------------- ### Few-shot Prompt Example for Concise Responses Source: https://github.com/azmaveth/ex_llm/blob/master/docs/gemini/GEMINI-DOCS-23-PROMPT-ENGINEERING.md A few-shot prompt that includes examples to guide the model towards producing concise responses, demonstrating preference for shorter explanations. ```plaintext Below are some examples showing a question, explanation, and answer format: Question: Why is the sky blue? Explanation1: The sky appears blue because of Rayleigh scattering, which causes shorter blue wavelengths of light to be scattered more easily than longer red wavelengths, making the sky look blue. Explanation2: Due to Rayleigh scattering effect. Answer: Explanation2 Question: What is the cause of earthquakes? Explanation1: Sudden release of energy in the Earth's crust. Explanation2: Earthquakes happen when tectonic plates suddenly slip or break apart, causing a release of energy that creates seismic waves that can shake the ground and cause damage. Answer: Explanation1 Now, Answer the following question given the example formats above: Question: How is snow formed? Explanation1: Snow is formed when water vapor in the air freezes into ice crystals in the atmosphere, which can combine and grow into snowflakes as they fall through the atmosphere and accumulate on the ground. Explanation2: Water vapor freezes into ice crystals forming snow. Answer: ``` -------------------------------- ### ExLLM Application Configuration Example Source: https://github.com/azmaveth/ex_llm/blob/master/MIGRATION_GUIDE_V1.md Shows how ExLLM application configuration in `config/config.exs` remains compatible with v1.0.0, including setting default providers and provider-specific options. ```elixir config :ex_llm, default_provider: :openai, openai: [ api_key: System.get_env("OPENAI_API_KEY"), model: "gpt-4" ] ``` -------------------------------- ### Full HTTP Stream Response Example Source: https://github.com/azmaveth/ex_llm/blob/master/docs/anthropic/llms-full.txt An example of a complete HTTP stream response from the Anthropic API, including message start, content blocks, and message stop events. ```JSON event: message_start data: {"type": "message_start", "message": {"id": "msg_1nZdL29xx5MUA1yADyHTEsnR8uuvGzszyY", "type": "message", "role": "assistant", "content": [], "model": "claude-opus-4-20250514", "stop_reason": null, "stop_sequence": null, "usage": {"input_tokens": 25, "output_tokens": 1}}} event: content_block_start data: {"type": "content_block_start", "index": 0, "content_block": {"type": "text", "text": ""}} event: ping data: {"type": "ping"} event: content_block_delta data: {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "Hello"}} event: content_block_delta data: {"type": "content_block_delta", "index": 0, "delta": {"type": "text_delta", "text": "!"}} event: content_block_stop data: {"type": "content_block_stop", "index": 0} event: message_delta data: {"type": "message_delta", "delta": {"stop_reason": "end_turn", "stop_sequence":null}, "usage": {"output_tokens": 15}} event: message_stop data: {"type": "message_stop"} ``` -------------------------------- ### Test Suite Setup: Environment File Source: https://github.com/azmaveth/ex_llm/blob/master/ENVIRONMENT.md Copy the test environment template and edit it to add API keys. ```bash # 1. Copy the test environment template cp .env.test.example .env.test # 2. Edit .env.test and add your API keys # Note: You don't need ALL keys - tests will skip providers without keys ``` -------------------------------- ### Example Computer Use Tool Actions (JSON) Source: https://github.com/azmaveth/ex_llm/blob/master/docs/anthropic/llms-full.txt Demonstrates common actions supported by the computer use tool, including taking screenshots, clicking at coordinates, typing text, and scrolling. These are examples of how the tool can be invoked. ```json // Take a screenshot { "action": "screenshot" } ``` ```json // Click at position { "action": "left_click", "coordinate": [500, 300] } ``` ```json // Type text { "action": "type", "text": "Hello, world!" } ``` ```json // Scroll down (Claude 4/3.7) { "action": "scroll", "coordinate": [500, 400], "scroll_direction": "down", "scroll_amount": 3 } ``` -------------------------------- ### Perplexity Provider Setup Source: https://github.com/azmaveth/ex_llm/blob/master/docs/vercel/llms.txt Install the Perplexity provider using npm, pnpm, or yarn. ```APIDOC ## Perplexity Provider Setup Install the Perplexity provider using: - **pnpm:** `pnpm add @ai-sdk/perplexity` - **npm:** `npm install @ai-sdk/perplexity` - **yarn:** `yarn add @ai-sdk/perplexity` ``` -------------------------------- ### Configure ExLLM Example App with Different Providers Source: https://github.com/azmaveth/ex_llm/blob/master/examples/README.md Set the PROVIDER environment variable to use different LLM services like OpenAI, Anthropic, Groq, X.AI, or a mock provider for testing. Ensure the necessary API keys are set. ```bash # Interactive mode examples: # OpenAI export OPENAI_API_KEY="your-key" PROVIDER=openai ./example_app.exs # Anthropic (Claude) export ANTHROPIC_API_KEY="your-key" PROVIDER=anthropic ./example_app.exs # Groq (Fast Cloud) export GROQ_API_KEY="your-key" PROVIDER=groq ./example_app.exs # X.AI (Grok) export XAI_API_KEY="your-key" PROVIDER=xai ./example_app.exs # Mock (Testing - no API key needed) PROVIDER=mock ./example_app.exs # Non-interactive mode examples: PROVIDER=openai elixir example_app.exs basic-chat "Hello from OpenAI!" PROVIDER=anthropic elixir example_app.exs function-calling PROVIDER=mock elixir example_app.exs provider-capabilities ``` -------------------------------- ### Initial OAuth2 Setup Script Source: https://github.com/azmaveth/ex_llm/blob/master/test/OAUTH2_TESTING.md Command to run the one-time setup script for performing the initial OAuth2 flow. This generates a `.gemini_tokens` file. ```bash # One-time setup to get initial tokens elixir scripts/setup_oauth2.exs ``` -------------------------------- ### Provide Example Customer Interactions Source: https://github.com/azmaveth/ex_llm/blob/master/docs/anthropic/llms-full.txt Includes sample 'good' customer interactions to guide Claude's response style and content. These examples help define guardrails and expected conversational flow. ```python EXAMPLES=""" Here are a few examples of how you can interact with customers: H: Hi, do you offer commercial insurance for small businesses? A: Ah! Unfortunately, we don't offer commercial insurance at this time. ``` -------------------------------- ### Install Adapters Library Source: https://github.com/azmaveth/ex_llm/blob/master/docs/huggingface-hub/llms.txt Install the Adapters library using pip. This is the first step to using adapters with Hugging Face transformers. ```bash pip install adapters ``` -------------------------------- ### Example YAML Section for Model Card Metadata Source: https://github.com/azmaveth/ex_llm/blob/master/docs/huggingface-hub/llms.txt This is an example of how to structure the YAML section in your README.md file to include various metadata fields. Ensure the file starts and ends with '---' to denote the YAML block. ```yaml --- language: - "List of ISO 639-1 code for your language" - lang1 - lang2 thumbnail: "url to a thumbnail used in social sharing" tags: - tag1 - tag2 license: "any valid license identifier" datasets: - dataset1 - dataset2 metrics: - metric1 - metric2 base_model: "base model Hub identifier" --- ``` -------------------------------- ### LM Studio Default Tool Use Example Source: https://github.com/azmaveth/ex_llm/blob/master/docs/lmstudio/llms.txt This example demonstrates the default tool use format provided by LM Studio when a model does not have native tool support. It shows the system prompt, available tools, rules, and an example user query. ```bash -> % lms log stream Streaming logs from LM Studio timestamp: 11/13/2024, 9:35:15 AM type: llm.prediction.input modelIdentifier: gemma-2-2b-it modelPath: lmstudio-community/gemma-2-2b-it-GGUF/gemma-2-2b-it-Q4_K_M.gguf input: "system You are a tool-calling AI. You can request calls to available tools with this EXACT format: [TOOL_REQUEST]{"name": "tool_name", "arguments": {"param1": "value1"}}[END_TOOL_REQUEST] AVAILABLE TOOLS: { "type": "toolArray", "tools": [ { "type": "function", "function": { "name": "get_delivery_date", "description": "Get the delivery date for a customer's order", "parameters": { "type": "object", "properties": { "order_id": { "type": "string" } }, "required": [ "order_id" ] } } } ] } RULES: - Only use tools from AVAILABLE TOOLS - Include all required arguments - Use one [TOOL_REQUEST] block per tool - Never use [TOOL_RESULT] - If you decide to call one or more tools, there should be no other text in your message Examples: "Check Paris weather" [TOOL_REQUEST]{"name": "get_weather", "arguments": {"location": "Paris"}}[END_TOOL_REQUEST] "Send email to John about meeting and open browser" [TOOL_REQUEST]{"name": "send_email", "arguments": {"to": "John", "subject": "meeting"}}[END_TOOL_REQUEST] [TOOL_REQUEST]{"name": "open_browser", "arguments": {}}[END_TOOL_REQUEST] Respond conversationally if no matching tools exist. user Get me delivery date for order 123 model " ``` -------------------------------- ### Import Default ElevenLabs Provider Source: https://github.com/azmaveth/ex_llm/blob/master/docs/vercel/llms.txt Import the default provider instance for ElevenLabs. This is the simplest way to get started. ```typescript import { elevenlabs } from '@ai-sdk/elevenlabs'; ``` -------------------------------- ### Tool Use Evaluation Setup Source: https://github.com/azmaveth/ex_llm/blob/master/docs/fireworks/llms-full.txt Sets up the schema and expected behavior for evaluating a 'search' tool. This is a common use case for assessing model tool utilization. ```python import json from reward_kit.rewards.function_calling import composite_function_call_reward # Define expected schema for search function search_schema = { "name": "search", "arguments": { "query": {"type": "string"} } } expected_behavior = """ The search function should be called: 1. When the user is asking for factual information 2. With a clear, specific query that captures what the user is looking for 3. Without including instructions, formatting requests, or explanations in the query """ ``` -------------------------------- ### Mistral AI Provider Setup Source: https://github.com/azmaveth/ex_llm/blob/master/docs/vercel/llms.txt Install the Mistral AI provider package using your preferred package manager. ```APIDOC ## Install Mistral AI Provider ### Description Installs the Mistral AI provider package. ### Package Manager - **pnpm** ```sh pnpm add @ai-sdk/mistral ``` - **npm** ```sh npm install @ai-sdk/mistral ``` - **yarn** ```sh yarn add @ai-sdk/mistral ``` ``` -------------------------------- ### Example: Set Theme Globally Source: https://github.com/azmaveth/ex_llm/blob/master/docs/anthropic/llms-full.txt This example demonstrates setting the color theme globally. Options are 'dark', 'light', 'light-daltonized', or 'dark-daltonized'. ```bash claude config set -g theme dark-daltonized ``` -------------------------------- ### Set Up OAuth2 for Google/Gemini Tests Source: https://github.com/azmaveth/ex_llm/blob/master/test/ENVIRONMENT_SETUP.md Configure environment variables for Google OAuth2 client ID and secret, then run a setup script to authenticate and create token files. ```bash # 1. Set environment variables export GOOGLE_CLIENT_ID=your_client_id export GOOGLE_CLIENT_SECRET=your_client_secret # 2. Run setup script elixir scripts/setup_oauth2.exs # 3. Follow the prompts to authenticate # This creates .gemini_tokens file ``` -------------------------------- ### Complete Request Lifecycle Logging Example Source: https://github.com/azmaveth/ex_llm/blob/master/docs/LOGGER.md An end-to-end example demonstrating how to log the entire lifecycle of a request, from context setup to API calls and error handling. It uses Logger.with_context for managing log context across operations. ```elixir defmodule MyApp.AI do alias ExLLM.Logger def generate_summary(text, user_id) do # Set up context Logger.with_context( operation: :summary, user_id: user_id, request_id: UUID.uuid4() ) do Logger.info("Starting summary generation") messages = [ %{role: "system", content: "You are a helpful assistant."}, %{role: "user", content: "Summarize: #{text}"} ] # The actual API call (logging handled internally) case ExLLM.chat(:openai, messages) do {:ok, response} -> Logger.info("Summary generated", tokens: response.usage.total_tokens, cost_usd: response.cost.total_cost ) {:ok, response.content} {:error, reason} -> Logger.error("Summary generation failed", error: reason) {:error, reason} end end end end ``` -------------------------------- ### Install Claude Code with User-Writable npm Prefix Source: https://github.com/azmaveth/ex_llm/blob/master/docs/anthropic/llms-full.txt This script guides you through setting up a dedicated directory for global npm packages, preventing permission errors and ensuring a clean installation. It includes steps to save existing packages, configure npm, update your shell's PATH, and install Claude Code. ```bash # First, save a list of your existing global packages for later migration npm list -g --depth=0 > ~/npm-global-packages.txt # Create a directory for your global packages mkdir -p ~/.npm-global # Configure npm to use the new directory path npm config set prefix ~/.npm-global # Note: Replace ~/.bashrc with ~/.zshrc, ~/.profile, or other appropriate file for your shell echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc # Apply the new PATH setting source ~/.bashrc # Now reinstall Claude Code in the new location npm install -g @anthropic-ai/claude-code # Optional: Reinstall your previous global packages in the new location # Look at ~/npm-global-packages.txt and install packages you want to keep # npm install -g package1 package2 package3... ``` -------------------------------- ### Instantiate LLM with Advanced Parameters Source: https://github.com/azmaveth/ex_llm/blob/master/docs/fireworks/llms-full.txt This snippet demonstrates advanced LLM instantiation, including optional parameters for deployment configuration, scaling, hardware, and performance. Adjust parameters like deployment_name, accelerator_type, and replica counts as needed. ```python llm = LLM( model="accounts/fireworks/models/llama-v3p2-3b-instruct", deployment_type="on-demand", deployment_name="my-custom-deployment", accelerator_type="NVIDIA_H100_80GB", min_replica_count=1, max_replica_count=3, scale_up_window=timedelta(seconds=30), scale_down_window=timedelta(minutes=10), enable_metrics=True ) ``` -------------------------------- ### Development Commands Source: https://github.com/azmaveth/ex_llm/blob/master/CLAUDE.md Provides essential commands for setting up and running the application during development, including installing dependencies. ```bash # Run the application iex -S mix # Install dependencies mix deps.get mix deps.compile ``` -------------------------------- ### Use Assistant Prefill for Guided Responses Source: https://github.com/azmaveth/ex_llm/blob/master/docs/openrouter/llms-full.txt Guide model responses by including a message with `role: "assistant"` at the end of the `messages` array. This is useful for setting a specific tone or starting point for the model's completion. ```typescript fetch('https://openrouter.ai/api/v1/chat/completions', { method: 'POST', headers: { Authorization: 'Bearer ', 'Content-Type': 'application/json', }, body: JSON.stringify({ model: 'openai/gpt-4o', messages: [ { role: 'user', content: 'What is the meaning of life?' }, { role: 'assistant', content: "I'm not sure, but my best guess is" }, ], }), }); ``` -------------------------------- ### Install Dependencies Source: https://github.com/azmaveth/ex_llm/blob/master/docs/fireworks/llms-full.txt Install the 'datasets' library from Hugging Face to load and prepare data for fine-tuning. ```bash pip install datasets ``` -------------------------------- ### Contextual Prompt Example Source: https://github.com/azmaveth/ex_llm/blob/master/docs/perplexity/llms-full.txt Provide critical context to guide the search, but keep prompts concise and focused on a single topic. ```text Explain the impact of the 2023 EU digital markets regulations on app store competition for small developers ``` -------------------------------- ### Anthropic SDK JavaScript Example Source: https://github.com/azmaveth/ex_llm/blob/master/docs/anthropic/llms-full.txt Demonstrates how to make an API request using the Anthropic SDK in JavaScript. Ensure the SDK is installed and configured. ```javascript const msg = await client.messages.create({ model: "claude-3-7-sonnet-v1@20250219", max_tokens: 2000, temperature: 1, system: "Help the user navigate a complex ethical dilemma by identifying core ethical principles, exploring different ethical frameworks, considering potential consequences, acknowledging complexity, encouraging personal reflection, and offering additional resources. Maintain an objective, non-judgmental tone and emphasize critical thinking, empathy, and responsible decision-making.", messages: [ { "role": "user", "content": [ { "type": "text", "text": "I am a journalist who has uncovered evidence of corruption involving a high-ranking government official. Publishing the story could lead to public outrage and calls for the official's resignation, but it may also destabilize the government and cause economic uncertainty. The official has offered me a significant bribe to keep the story quiet. Should I accept the bribe, publish the story, or find another solution?" } ] } ] }); console.log(msg); ``` -------------------------------- ### List API Keys (PHP) Source: https://github.com/azmaveth/ex_llm/blob/master/docs/openrouter/llms-full.txt PHP example using GuzzleHttp to retrieve API keys. Ensure GuzzleHttp is installed via Composer. ```php request('GET', 'https://openrouter.ai/api/v1/keys', [ 'headers' => [ 'Authorization' => 'Bearer ', ], ]); echo $response->getBody(); ?> ``` -------------------------------- ### Create API Key using Go Source: https://github.com/azmaveth/ex_llm/blob/master/docs/openrouter/llms-full.txt This Go program demonstrates creating an API key. Remember to replace '' with your actual token. ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://openrouter.ai/api/v1/keys" payload := strings.NewReader("{\n \"name\": \"name\"\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Example Request for Text Completions API Source: https://github.com/azmaveth/ex_llm/blob/master/docs/lmstudio/llms.txt Demonstrates how to make a POST request to the /api/v0/completions endpoint to get text completions from a specified model. ```bash curl http://localhost:1234/api/v0/completions \ -H "Content-Type: application/json" \ -d '{ "model": "granite-3.0-2b-instruct", "prompt": "the meaning of life is", "temperature": 0.7, "max_tokens": 10, "stream": false, "stop": "\n" }' ``` -------------------------------- ### Run Deployment Example Script Source: https://github.com/azmaveth/ex_llm/blob/master/docs/fireworks/llms-full.txt Executes the Python script to test and deploy a reward function to the Fireworks platform. Requires environment variables to be set. ```bash source .venv/bin/activate && FIREWORKS_API_KEY=$DEV_FIREWORKS_API_KEY FIREWORKS_API_BASE=https://dev.api.fireworks.ai python examples/deploy_example.py ``` -------------------------------- ### Refine Search with Latitude and Longitude Source: https://github.com/azmaveth/ex_llm/blob/master/docs/perplexity/llms-full.txt Use specific coordinates to get geographically relevant search results. This example approximates San Francisco. ```cURL curl --location 'https://api.perplexity.ai/chat/completions' \ --header 'Authorization: Bearer YOUR_API_KEY' \ --header 'Content-Type: application/json' \ --data '{ \ "model": "sonar-pro", \ "messages": [ \ {"role": "system", "content": "You are a helpful local guide."}, \ {"role": "user", "content": "What are some good coffee shops nearby?"} \ ], \ "web_search_options": { \ "user_location": { \ "latitude": 37.7749, \ "longitude": -122.4194 \ } \ } \ }' ``` ```Python import requests url = "https://api.perplexity.ai/chat/completions" headers = {"Authorization": "Bearer YOUR_API_KEY"} payload = { "model": "sonar-pro", "messages": [ {"role": "system", "content": "You are a helpful local guide."}, {"role": "user", "content": "What are some good coffee shops nearby?"} ], "web_search_options": { "user_location": { "latitude": 37.7749, "longitude": -122.4194 } } } response = requests.post(url, headers=headers, json=payload) print(response.json()) ``` -------------------------------- ### Basic Flight Task Evaluation Example Source: https://github.com/azmaveth/ex_llm/blob/master/docs/fireworks/llms-full.txt Example demonstrating how to set the agent model and run evaluation for a basic flight task. ```bash export MODEL_AGENT=openai/gpt-4o reward-kit agent-eval --task-dir ./examples/flight_task ```