Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dropdown suggestions for the 'Pull a model from Ollama.com' input box #1260

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions backend/apps/ollama/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import logging
from urllib.parse import urlparse
from typing import Optional, List, Union
from bs4 import BeautifulSoup


from apps.web.models.users import Users
Expand Down Expand Up @@ -161,6 +162,23 @@ async def get_all_models():
return models


@app.get("/api/scrape")
async def scrape_models(url="https://ollama.com/library"):
try:
response = requests.get(url)
response.raise_for_status()
soup = BeautifulSoup(response.text, "html.parser")
models = [h2.text.strip() for h2 in soup.find_all("h2")]

return {"models": models}
except Exception as e:
log.exception(e)
raise HTTPException(
status_code=500,
detail="Error scraping models",
)


@app.get("/api/tags")
@app.get("/api/tags/{url_idx}")
async def get_ollama_tags(
Expand Down
26 changes: 26 additions & 0 deletions src/lib/apis/ollama/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,32 @@ export const uploadModel = async (token: string, file: File, urlIdx: string | nu
return res;
};

export const scrapeModelsList = async (token: string) => {
let error = null;

const res = await fetch(`${OLLAMA_API_BASE_URL}/api/scrape`, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
}
}).catch((err) => {
console.log(err);
error = err;

if ('detail' in err) {
error = err.detail;
}

return null;
});
if (error) {
throw error;
}
return res;
};

// export const pullModel = async (token: string, tagName: string) => {
// return await fetch(`${OLLAMA_API_BASE_URL}/pull`, {
// method: 'POST',
Expand Down
5 changes: 4 additions & 1 deletion src/lib/components/admin/UserChatsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@
{/each} -->
</div>
{:else}
<div class="text-left text-sm w-full mb-8">{user.name} {$i18n.t('has no conversations.')}</div>
<div class="text-left text-sm w-full mb-8">
{user.name}
{$i18n.t('has no conversations.')}
</div>
{/if}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/layout/Sidebar/ChatMenu.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { DropdownMenu } from 'bits-ui';
import { flyAndScale } from '$lib/utils/transitions';
import { getContext } from 'svelte'
import { getContext } from 'svelte';

import Dropdown from '$lib/components/common/Dropdown.svelte';
import GarbageBin from '$lib/components/icons/GarbageBin.svelte';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/i18n/locales/de-DE/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
"Profile Image": "Profilbild",
"Prompt (e.g. Tell me a fun fact about the Roman Empire)": "Prompt (z.B. Erzähle mir eine interessante Tatsache über das Römische Reich.",
"Playground": "Spielplatz",

"Profile": "Profil",
"Prompt Content": "Prompt-Inhalt",
"Prompt suggestions": "Prompt-Vorschläge",
Expand Down