### Integrate Irona AI in 3 Lines of Code Source: https://docs.irona.ai/get-started/quickstart This snippet demonstrates how to initialize the Irona AI client and make a completion request using multiple models. It shows how to set the API key and provides an example of a system and user message. ```python from ironaai import ironaai client = ironaai.Client( # Optional - automatically loads from environment variable api_key='your_ironaai_api_key' ) chat_completions = irona.completions.create( messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Explain the golden ratio."} ], models=['openai/gpt-4o', 'anthropic/claude-3-5-sonnet-20240620'] ) print('LLM output:', chat_completions.content) print('Selected providers:', chat_completions.providers) ``` -------------------------------- ### Python Installation Source: https://docs.irona.ai/get-started/introduction Installs the Irona AI Python package. It is recommended to use a virtual environment for dependency management. ```python pip install ironaai ``` -------------------------------- ### Python Installation Source: https://docs.irona.ai/index Installs the Irona AI Python package. It is recommended to use a virtual environment for dependency management. ```python pip install ironaai ``` -------------------------------- ### API Authentication Example Source: https://docs.irona.ai/api-reference/introduction Demonstrates how to authenticate API requests using a Bearer Token with your API key. This is crucial for all interactions with the Irona AI API. ```shell cURL --header 'Authorization: Bearer ' ``` ```APIDOC Authorization: Bearer ``` -------------------------------- ### Model Select Endpoint Usage Source: https://docs.irona.ai/api-reference/introduction Provides an example of how to call the `/modelSelect` endpoint to get model recommendations. It includes the necessary headers and a sample JSON payload. ```shell curl -X POST https://api.irona.ai/v1/modelSelect \ -H "Authorization: Bearer " \ -H "Content-Type: application/json" \ -d '{ "messages": [...], "models": [...] }' ``` ```python import requests api_key = "" url = "https://api.irona.ai/v1/modelSelect" headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" } data = { "messages": [...], "models": [...] } response = requests.post(url, headers=headers, json=data) print(response.json()) ``` -------------------------------- ### Create Completion Example Source: https://docs.irona.ai/essentials/model-select Shows how to use the `create` function to generate LLM completions, suitable for new projects where you want to streamline LLM calls. It returns both the completion response and the selected model. ```python completion_response, selected_models = client.completions.create( messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Explain the golden ratio."} ], models=['openai/gpt-4o', 'anthropic/claude-3-5-sonnet-20240620'] ) ``` ```typescript const [completionResponse, selectedModels] = await client.completions.create( messages: [ { role: "system", content: "You are a helpful assistant." }, { role: "user", content: "Explain the golden ratio." } ], models:['openai/gpt-4o', 'anthropic/claude-3-5-sonnet-20240620'] ); ``` -------------------------------- ### Model Select Example Source: https://docs.irona.ai/essentials/model-select Demonstrates how to use the `model_select` function to choose the best-suited LLM for a given set of messages. This is ideal for integrating Irona AI into existing projects. ```python selected_models = client.chat.completions.model_select( messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Explain the golden ratio."} ], models=['openai/gpt-4o', 'anthropic/claude-3-5-sonnet-20240620'] ) ## Response output # selected_models = 'openai/gpt-4o' ``` ```typescript const selectedModels = await client.chat.completions.modelSelect( messages: [ { role: "system", content: "You are a helpful assistant." }, { role: "user", content: "Explain the golden ratio." } ], models:['openai/gpt-4o', 'anthropic/claude-3-5-sonnet-20240620'] ); // selectedModels = 'openai/gpt-4o' ``` -------------------------------- ### Define Tool as Dictionary Source: https://docs.irona.ai/essentials/function_calling Example of defining a tool as a dictionary for use with IronaAI. This includes the tool's type, name, description, and parameters with their types and requirements. ```json [ { "type": "function", "function": { "name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": { "type": "object", "properties": { "location": {"type": "string", "description": "The city, e.g., San Francisco"}, "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]} }, "required": ["location"] } } } ] ``` -------------------------------- ### Define Tool using LangChain Source: https://docs.irona.ai/essentials/function_calling Example of defining a tool using LangChain's `@tool` decorator. This allows for easy integration of LangChain tools with IronaAI. ```python from langchain_core.tools import tool @tool def multiply(a: int, b: int) -> int: """Multiply two integers.""" return a * b ``` -------------------------------- ### TypeScript and REST API Support Source: https://docs.irona.ai/get-started/introduction Information on using Irona AI with TypeScript or directly via its REST API, providing alternatives to the Python SDK. ```typescript Use our [TypeScript Client](https://www.npmjs.com/package/ironaai) ``` ```rest Directly call our [REST API endpoint](https://docs.irona.ai/api-reference/introduction) ``` -------------------------------- ### TypeScript and REST API Support Source: https://docs.irona.ai/index Information on using Irona AI with TypeScript or directly via its REST API, providing alternatives to the Python SDK. ```typescript Use our [TypeScript Client](https://www.npmjs.com/package/ironaai) ``` ```rest Directly call our [REST API endpoint](https://docs.irona.ai/api-reference/introduction) ``` -------------------------------- ### Supported LLM Providers and Models Source: https://docs.irona.ai/get-started/model Lists the LLM providers and their corresponding models supported by Irona AI. This includes model names and any available aliases for easier reference. ```APIDOC Provider | Model name | Alias ---|---|--- **OpenAI** | openai/gpt-4o-2024-08-06 | openai/gpt-4o | openai/gpt-4o-2024-05-13 | | openai/gpt-4-turbo-2024-04-09 | openai/gpt-4-turbo | openai/gpt-4-0125-preview | openai/gpt-4-turbo-2024-04-09 | openai/gpt-4-1106-preview | | openai/gpt-4-0613 | openai/gpt-4 | openai/gpt-3.5-turbo-0125 | openai/gpt-3.5-turbo | openai/gpt-4o-mini-2024-07-18 | openai/gpt-4o-mini | openai/o1-preview-2024-09-12 | openai/o1-preview | openai/o1-mini-2024-09-12 | openai/o1-mini **Anthropic** | anthropic/claude-3-5-sonnet-20240620 | | anthropic/claude-3-opus-20240229 | | anthropic/claude-3-sonnet-20240229 | | anthropic/claude-3-haiku-20240307 | | anthropic/claude-2.1 | **Google** | google/gemini-1.5-pro-latest | | google/gemini-1.5-flash-latest | | google/gemini-1.0-pro-latest | google/gemini-pro **Mistral** | mistral/open-mixtral-8x22b | | mistral/codestral-latest | | mistral/open-mixtral-8x7b | | mistral/mistral-large-2407 | mistral/mistral-large-latest | mistral/mistral-large-2402 | | mistral/mistral-medium-latest | | mistral/mistral-small-latest | | mistral/open-mistral-7b | | mistral/open-mistral-nemo | **Replicate** | replicate/meta-llama-3-70b-instruct | | replicate/meta-llama-3-8b-instruct | | replicate/mixtral-8x7b-instruct-v0.1 | | replicate/mistral-7b-instruct-v0.2 | | replicate/meta-llama-3.1-405b-instruct | **TogetherAI** | togetherai/Llama-3-70b-chat-hf | | togetherai/Llama-3-8b-chat-hf | | togetherai/Meta-Llama-3.1-8B-Instruct-Turbo | | togetherai/Meta-Llama-3.1-70B-Instruct-Turbo | | togetherai/Meta-Llama-3.1-405B-Instruct-Turbo | | togetherai/Qwen2-72B-Instruct | | togetherai/Mixtral-8x22B-Instruct-v0.1 | | togetherai/Mixtral-8x7B-Instruct-v0.1 | | togetherai/Mistral-7B-Instruct-v0.2 | **Perplexity** | perplexity/llama-3.1-sonar-large-128k-online | **Cohere** | cohere/command-r-plus | | cohere/command-r | ``` -------------------------------- ### Make Function Call with IronaAI Client Source: https://docs.irona.ai/essentials/function_calling Demonstrates how to bind tools to the IronaAI client and make a completion request that includes tool calls. The response may contain a `tool_calls` attribute if the model chooses to use a tool. ```python # Bind the tool to the client client = IronaAI() completion_with_tools = client.bind_tools([multiply]) response = client.completion_with_tools( messages=[{"role": "user", "content": "What's the weather like in San Francisco?"}], tools=tools, tool_choice="auto" ) ``` -------------------------------- ### Using a PDF URL for Input Source: https://docs.irona.ai/essentials/multimodal_input This snippet demonstrates how to send a PDF file located at a URL as input to the IronaAI client. It constructs a messages list with text and an image_url pointing to the PDF, then prints the model's response. ```python response = client.completions.create( messages=[ { "role": "user", "content": [ {"type": "text", "text": "What’s in this PDF?"}, { "type": "image_url", "image_url": "https://example.com/document.pdf" } ] } ], model="openai/gpt-4o" ) print(response.choices[0].message.content) ``` -------------------------------- ### Pydantic Model Response Format Source: https://docs.irona.ai/essentials/structure-output Illustrates how to use Pydantic models for structured outputs with IronaAI. Define a Pydantic model for complex data structures and pass it to the `response_format` parameter. The response will be an instance of the specified model, enabling direct attribute access. ```python from pydantic import BaseModel class CalendarEvent(BaseModel): name: str date: str participants: list[str] class EventsList(BaseModel): events: list[CalendarEvent] messages = [{"role": "user", "content": "List 5 important events in the XIX century"}] resp = client.completions.create( messages=messages, response_format=EventsList ) print(resp) ``` -------------------------------- ### Using Base64 Encoded PDF for Input Source: https://docs.irona.ai/essentials/multimodal_input This snippet shows how to read a local PDF file, encode its content into a base64 string, and then send it as input to the IronaAI client. The base64 encoded PDF is included in the messages list with the appropriate data URI scheme. ```python import base64 with open("document.pdf", "rb") as pdf_file: encoded_pdf = base64.b64encode(pdf_file.read()).decode("utf-8") response = client.completions.create( messages=[ { "role": "user", "content": [ {"type": "text", "text": "What’s in this PDF?"}, { "type": "image_url", "image_url": f"data:application/pdf;base64,{encoded_pdf}" } ] } ], model="openai/gpt-4o" ) print(response.choices[0].message.content) ``` -------------------------------- ### Checking Model Support for Media Types Source: https://docs.irona.ai/essentials/multimodal_input This snippet demonstrates how to check if a specific model supports vision and PDF inputs using the IronaAI client's helper functions. It prints boolean values indicating the support status for the given model. ```python model = "openai/gpt-4o" print(f"Supports vision: {client.supports_vision(model)}") # True print(f"Supports PDFs: {client.supports_pdf_input(model)}") # True ``` -------------------------------- ### Sending Image URL to IronaAI Source: https://docs.irona.ai/essentials/multimodal_input Demonstrates how to send an image via its URL to the IronaAI API for processing. This method is useful when the image is publicly accessible online. It requires the 'openai/gpt-4o' model and sends a text prompt along with the image URL. ```python response = client.completions.create( messages=[ { "role": "user", "content": [ {"type": "text", "text": "What’s in this image?"}, { "type": "image_url", "image_url": "https://example.com/image.jpg" } ] } ], model="openai/gpt-4o" ) print(response.choices[0].message.content) ``` -------------------------------- ### Model Select Endpoint Source: https://docs.irona.ai/api-reference/endpoint/model/select The Model Select endpoint allows you to route requests to the most appropriate LLM based on provided messages, LLM provider configurations, and optional parameters like tradeoff and preference ID. It returns a label indicating the selected LLM. ```APIDOC POST /model-select Description: Given an array of messages and the selection of LLMs you want to route between, `/model-select` will return a label for which LLM you should call. Request Body: - Authorization (string, header, required): Bearer authentication header of the form `Bearer `. - messages (object[], required): The messages array in OpenAI format. - role (string): The role of the message author (e.g., 'system', 'user', 'assistant'). - content (string): The content of the message. - llm_providers (object[], required): A list of LLM providers to route between. Custom attributes like price and latency can be optionally defined. - name (string): The name of the LLM provider. - price (number): The price associated with the provider. - latency (number): The latency associated with the provider. - attributes (object): Custom attributes for the provider. - tools (object[]): A list of tools the model may call. Currently, only functions are supported. - name (string): The name of the tool. - description (string): A description of the tool. - parameters (object): The parameters the tool accepts. - max_model_depth (integer): The maximum depth considered in the ranked LLM providers list. - tradeoff (string): Additional routing tradeoffs. Valid values are "cost" and "latency". - preference_id (string): The preference ID created on the Not Diamond dashboard to influence the ranking algorithm. - hash_content (boolean, default:false): Whether to hash the content of messages. - previous_session (string): The session ID from a previous API call to link recommendations. Responses: - 200: Successful response. - llm_label (string): The label of the selected LLM. - 400: Bad Request. - 404: Not Found. - 500: Internal Server Error. Example Usage: ```curl curl -X POST https://api.irona.ai/api/v1/model-select \ -H "Authorization: Bearer " \ -H "Content-Type: application/json" \ -d '{ \ "messages": [ \ {"role": "system", "content": "You are a world class software developer."}, \ {"role": "assistant", "content": "How can I help you today?"}, \ {"role": "user", "content": "Write a merge sort in Python."} \ ], \ "llm_providers": [ \ { \ "provider": "openai", \ "model": "gpt-4-1106-preview" \ }, \ { \ "provider": "anthropic", \ "model": "claude-3-opus-20240229" \ } \ ], \ }' ``` ``` ```curl curl --request POST \ --url https://app.irona.ai/api/v1/model-select \ --header 'Authorization: Bearer ' \ --header 'Content-Type: application/json' \ --data '{ \ "messages": [ \ { \ "role": "system", \ "content": "" \ } \ ], \ "llm_providers": [ \ { \ "name": "", \ "price": 123, \ "latency": 123, \ "attributes": {} \ } \ ], \ "tools": [ \ { \ "name": "", \ "description": "", \ "parameters": {} \ } \ ], \ "max_model_depth": 123, \ "tradeoff": "", \ "preference_id": "", \ "hash_content": false, \ "previous_session": "" \ }' ``` -------------------------------- ### JSON Object Response Format Source: https://docs.irona.ai/essentials/structure-output Demonstrates how to configure IronaAI to return responses as a JSON object. This is useful for generating structured data that can be easily parsed. It requires setting the `response_format` parameter to `{"type": "json_object"}`. ```python response = client.completions.create( response_format={"type": "json_object"}, messages=[ {"role": "system", "content": "You are a helpful assistant designed to output JSON."}, {"role": "user", "content": "Who won the world series in 2020?"} ] ) print(response.choices[0].message.content) ``` -------------------------------- ### Sending Base64 Encoded Image to IronaAI Source: https://docs.irona.ai/essentials/multimodal_input Shows how to send a base64 encoded image to the IronaAI API. This is useful for local images or when direct URLs are not feasible. The code reads an image file, encodes it to base64, and includes it in the message content with the correct MIME type. ```python import base64 with open("image.jpg", "rb") as image_file: encoded_image = base64.b64encode(image_file.read()).decode("utf-8") response = client.completions.create( messages=[ { "role": "user", "content": [ {"type": "text", "text": "What’s in this image?"}, { "type": "image_url", "image_url": f"data:image/jpeg;base64,{encoded_image}" } ] } ], model="openai/gpt-4o" ) print(response.choices[0].message.content) ``` -------------------------------- ### Model Selection Response Source: https://docs.irona.ai/api-reference/endpoint/model/select Details the successful response codes and the 'llm_label' field for the model selection endpoint. The 'llm_label' is a required string indicating which LLM to call. ```APIDOC Endpoint: /model/select Response Codes: 200: Successful response 400: Bad Request 404: Not Found 500: Internal Server Error Content Type: application/json Response Body: { "llm_label": "string" // required, Label of the LLM you should call. } Related Resources: - [Response LLM Label Documentation](https://docs.irona.ai/api-reference/endpoint/model/select#response-llm-label) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.