Client
openwebui_client.client
OpenWebUI client for interacting with the OpenWebUI API.
OpenWebUIChat
Bases: Chat
Custom Chat class that uses OpenWebUICompletions.
Source code in openwebui_client/client.py
OpenWebUIClient
Bases: OpenAI
Client for interacting with the OpenWebUI API.
This client extends the OpenAI client with OpenWebUI-specific features like file attachments in chat completions.
Source code in openwebui_client/client.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
__init__(api_key=None, base_url='http://localhost:5000', default_model='gpt-4', **kwargs)
Initialize the OpenWebUI client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_key
|
Optional[str]
|
Your OpenWebUI API key |
None
|
base_url
|
str
|
Base URL for the API (defaults to OpenWebUI's local instance) |
'http://localhost:5000'
|
default_model
|
str
|
Default model to use for completions |
'gpt-4'
|
**kwargs
|
Any
|
Additional arguments to pass to the OpenAI client |
{}
|
Source code in openwebui_client/client.py
chat()
chat_with_tools(messages, tools=None, tool_params=None, model=None, max_tool_calls=5, files=[])
Send a chat completion request and handle tool calls automatically.
This will automatically execute tool calls and include their results in subsequent API calls until the model returns a final response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
messages
|
List[ChatCompletionMessageParam]
|
List of message dictionaries with 'role' and 'content' keys |
required |
tools
|
Optional[Sequence[str]]
|
List of tool names to use (None for all registered tools) |
None
|
tool_params
|
Optional[Dict[str, Dict[str, Any]]]
|
Optional parameters to pass to the tools when they are called |
None
|
model
|
Optional[str]
|
Model to use (defaults to the client's default model) |
None
|
max_tool_calls
|
int
|
Maximum number of tool call rounds to allow |
5
|
files
|
Iterable[Path]
|
Optional list of Path objects to files that should be included with the request |
[]
|
Returns:
Type | Description |
---|---|
str
|
The final assistant message content (str) after all tool calls are processed |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the maximum number of tool calls is exceeded |
Example
client = OpenWebUIClient() client.tool_registry.register(get_weather) response = client.chat_with_tools( ... messages=[{"role": "user", "content": "What's the weather in Paris?"}], ... max_tool_calls=3 ... ) print(response)
Source code in openwebui_client/client.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|