Skip to content

Commit

Permalink
feat: enhance model URL handling
Browse files Browse the repository at this point in the history
- Improved URL handling by encoding model names in API requests across multiple JavaScript files.
- Modified the URL pattern in the Django application to support path parameters for model names.
  • Loading branch information
psyray committed Nov 18, 2024
1 parent 5d489f7 commit 3809741
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion web/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
OllamaManager.as_view(),
name='ollama_manager'),
path(
'tool/ollama/<str:model_name>/',
'tool/ollama/<path:model_name>/',
OllamaDetailManager.as_view(),
name='ollama_detail_manager'),
path(
Expand Down
6 changes: 4 additions & 2 deletions web/scanEngine/templates/scanEngine/settings/llm_toolkit.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ <h4 class="modal-title">Add New Model</h4>
{% block page_level_script %}
<script type="text/javascript">
function deleteModel(model_name) {
const url = `/api/tool/ollama/${encodeURIComponent(model_name)}/`;
const encoded_model = encodeURIComponent(model_name);
const url = `/api/tool/ollama/${encoded_model}/`;

Swal.fire({
title: 'Are you sure?',
Expand Down Expand Up @@ -455,7 +456,8 @@ <h5 class="mt-0 mb-1">
}

function selectModel(model_name) {
const url = `/api/tool/ollama/${encodeURIComponent(model_name)}/`;
const encoded_model = encodeURIComponent(model_name);
const url = `/api/tool/ollama/${encoded_model}/`;

Swal.fire({
title: 'Updating...',
Expand Down
6 changes: 4 additions & 2 deletions web/static/custom/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -3355,7 +3355,8 @@ async function showModelSelectionDialog(endpoint_url, id, force_regenerate = fal

try {
// Update selected model in database first
const updateResponse = await fetch(`/api/tool/ollama/${selectedModel}`, {
const encoded_model = encodeURIComponent(selectedModel);
const updateResponse = await fetch(`/api/tool/ollama/${encoded_model}/`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -3629,7 +3630,8 @@ function selectLLMModel() {
}

// Update selected model in database
fetch(`/api/tool/ollama/${selectedModel}`, {
const encoded_model = encodeURIComponent(selectedModel);
fetch(`/api/tool/ollama/${encoded_model}/`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Expand Down

0 comments on commit 3809741

Please sign in to comment.