|
| 1 | +# Ollama (OpenAI compatible) connector blueprint example for chat |
| 2 | + |
| 3 | +This is an AI connector blueprint for Ollama or any other local/self-hosted LLM as long as it is OpenAI compatible (Ollama, llama.cpp, vLLM, etc) |
| 4 | + |
| 5 | +## 1. Add connector endpoint to trusted URLs |
| 6 | + |
| 7 | +```json |
| 8 | +PUT /_cluster/settings |
| 9 | +{ |
| 10 | + "persistent": { |
| 11 | + "plugins.ml_commons.trusted_connector_endpoints_regex": [ |
| 12 | + "^https://127\\.0\\.0/.*$" |
| 13 | + ] |
| 14 | + } |
| 15 | +} |
| 16 | +``` |
| 17 | + |
| 18 | +## 2. Enable private addresses |
| 19 | + |
| 20 | +```json |
| 21 | +PUT /_cluster/settings |
| 22 | +{ |
| 23 | + "persistent": { |
| 24 | + "plugins.ml_commons.connector.private_ip_enabled": true |
| 25 | + } |
| 26 | +} |
| 27 | +``` |
| 28 | + |
| 29 | +## 3. Create the connector |
| 30 | + |
| 31 | +```json |
| 32 | +POST /_plugins/_ml/connectors/_create |
| 33 | +{ |
| 34 | + "name": "<YOUR CONNECTOR NAME>", |
| 35 | + "description": "<YOUR CONNECTOR DESCRIPTION>", |
| 36 | + "version": "<YOUR CONNECTOR VERSION>", |
| 37 | + "protocol": "http", |
| 38 | + "parameters": { |
| 39 | + "endpoint": "127.0.0.1:11434", |
| 40 | + "model": "qwen3:4b" |
| 41 | + }, |
| 42 | + "credential": { |
| 43 | + "openAI_key": "<YOUR API KEY HERE IF NEEDED>" |
| 44 | + }, |
| 45 | + "actions": [ |
| 46 | + { |
| 47 | + "action_type": "predict", |
| 48 | + "method": "POST", |
| 49 | + "url": "https://${parameters.endpoint}/v1/chat/completions", |
| 50 | + "headers": { |
| 51 | + "Authorization": "Bearer ${credential.openAI_key}" |
| 52 | + }, |
| 53 | + "request_body": "{ \"model\": \"${parameters.model}\", \"messages\": ${parameters.messages} }" |
| 54 | + } |
| 55 | + ] |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +### Sample response |
| 60 | + |
| 61 | +```json |
| 62 | +{ |
| 63 | + "connector_id": "DUFXiofepXVT9_cf1h0s_" |
| 64 | +} |
| 65 | +``` |
| 66 | + |
| 67 | +### 4. Corresponding Predict request example |
| 68 | + |
| 69 | +Notice how you have to create the whole message structure, not just the message to send. |
| 70 | + |
| 71 | +```json |
| 72 | +POST /_plugins/_ml/models/<ENTER MODEL ID HERE>/_predict |
| 73 | +{ |
| 74 | + "parameters": { |
| 75 | + "messages": [ |
| 76 | + { |
| 77 | + "role": "system", |
| 78 | + "content": "You are a helpful assistant." |
| 79 | + }, |
| 80 | + { |
| 81 | + "role": "user", |
| 82 | + "content": "Why is the sky blue" |
| 83 | + } |
| 84 | + ] |
| 85 | + } |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +### Sample response |
| 90 | + |
| 91 | +```json |
| 92 | +{ |
| 93 | + "inference_results": [ |
| 94 | + { |
| 95 | + "output": [ |
| 96 | + { |
| 97 | + "name": "response", |
| 98 | + "dataAsMap": { |
| 99 | + "choices": [ |
| 100 | + { |
| 101 | + "finish_reason": "stop", |
| 102 | + "index": 0, |
| 103 | + "message": { |
| 104 | + "role": "assistant", |
| 105 | + "content": """The sky appears blue due to a phenomenon called Rayleigh scattering. Here's a simple explanation: |
| 106 | + |
| 107 | +1. **Sunlight Composition**: Sunlight appears white, but it's actually a mix of all colors of the visible spectrum (red, orange, yellow, green, blue, indigo, violet). |
| 108 | + |
| 109 | +2. **Atmospheric Scattering**: When sunlight enters Earth's atmosphere, it interacts with the gas molecules and tiny particles in the air. Shorter wavelengths of light (like blue and violet) are scattered more than other colors because they travel in shorter, smaller waves. |
| 110 | + |
| 111 | +3. **Why Blue Dominates**: Although violet light is scattered even more than blue light, the sky appears blue, not violet, because: |
| 112 | + - Our eyes are more sensitive to blue light than violet light. |
| 113 | + - The sun emits more blue light than violet light. |
| 114 | + - Some of the violet light gets absorbed by the upper atmosphere. |
| 115 | + |
| 116 | +4. **Time of Day**: The sky appears blue during the day because we're seeing the scattered blue light from all directions. At sunrise or sunset, the light has to pass through more of the atmosphere, scattering the blue light away and leaving mostly red and orange hues. |
| 117 | + |
| 118 | +This scattering effect is named after Lord Rayleigh, who mathematically described the phenomenon in the 19th century.""" |
| 119 | + } |
| 120 | + } |
| 121 | + ], |
| 122 | + "created": 1757369906, |
| 123 | + "model": "qwen3:4b", |
| 124 | + "system_fingerprint": "b6259-cebb30fb", |
| 125 | + "object": "chat.completion", |
| 126 | + "usage": { |
| 127 | + "completion_tokens": 264, |
| 128 | + "prompt_tokens": 563, |
| 129 | + "total_tokens": 827 |
| 130 | + }, |
| 131 | + "id": "chatcmpl-iHioFpaxa8K2SXgAHd4FhQnbewLQ9PjB", |
| 132 | + "timings": { |
| 133 | + "prompt_n": 563, |
| 134 | + "prompt_ms": 293.518, |
| 135 | + "prompt_per_token_ms": 0.5213463587921847, |
| 136 | + "prompt_per_second": 1918.1106439809487, |
| 137 | + "predicted_n": 264, |
| 138 | + "predicted_ms": 5084.336, |
| 139 | + "predicted_per_token_ms": 19.258848484848485, |
| 140 | + "predicted_per_second": 51.92418439693993 |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | + ], |
| 145 | + "status_code": 200 |
| 146 | + } |
| 147 | +``` |
0 commit comments