8000 [pull] dev from menloresearch:dev by pull[bot] · Pull Request #10 · phpmooc/jan · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[pull] dev from menloresearch:dev #10

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

Merged
merged 3 commits into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/src/browser/extensions/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ export abstract class ModelExtension
* Delete a model source
*/
abstract deleteSource(source: string): Promise<void>

/**
* Fetch models hub
*/
abstract fetchModelsHub(): Promise<void>
}
4 changes: 2 additions & 2 deletions extensions/model-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default class JanModelExtension extends ModelExtension {
}

// Sync with cortexsohub
this.fetchCortexsoModels()
this.fetchModelsHub()
}

/**
Expand Down Expand Up @@ -450,7 +450,7 @@ export default class JanModelExtension extends ModelExtension {
/**
* Fetch models from cortex.so
*/
private fetchCortexsoModels = async () => {
fetchModelsHub = async () => {
const models = await this.fetchModels()

return this.queue.add(() =>
Expand Down
38 changes: 34 additions & 4 deletions web/containers/ModelSearch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@ import { SearchIcon } from 'lucide-react'

import { useDebouncedCallback } from 'use-debounce'

import {
useGetModelSources,
useModelSourcesMutation,
} from '@/hooks/useModelSource'

import Spinner from '../Loader/Spinner'

type Props = {
supportModelImport?: boolean
onSearchLocal?: (searchText: string) => void
}

const ModelSearch = ({ onSearchLocal }: Props) => {
const ModelSearch = ({ supportModelImport, onSearchLocal }: Props) => {
const [searchText, setSearchText] = useState('')
const [isSearching, setSearching] = useState(false)
const { mutate } = useGetModelSources()
const { addModelSource } = useModelSourcesMutation()
const inputRef = useRef<HTMLInputElement | null>(null)
const debounced = useDebouncedCallback(async () => {
if (searchText.indexOf('/') === -1) {
Expand All @@ -20,6 +31,15 @@ const ModelSearch = ({ onSearchLocal }: Props) => {
}
// Attempt to search local
onSearchLocal?.(searchText)

setSearching(true)
// Attempt to search model source
if (supportModelImport)
addModelSource(searchText)
.then(() => mutate())
.then(() => onSearchLocal?.(searchText))
.catch(console.debug)
.finally(() => setSearching(false))
}, 300)

const >
Expand Down 8000 Expand Up @@ -50,14 +70,24 @@ const ModelSearch = ({ onSearchLocal }: Props) => {
return (
<Input
ref={inputRef}
prefixIcon={<SearchIcon size={16} />}
placeholder="Search models..."
prefixIcon={
isSearching ? (
<Spinner size={16} strokeWidth={2} />
) : (
<SearchIcon size={16} />
)
}
placeholder={
supportModelImport
? 'Search or enter Hugging Face URL'
: 'Search models'
}
>
>
value={searchText}
clearable={searchText.length > 0}
>
className="border-1 bg-[hsla(var(--app-bg))]"
className="bg-[hsla(var(--app-bg))]"
=> {
onSearchLocal?.(inputRef.current?.value ?? '')
}}
Expand Down
19 changes: 19 additions & 0 deletions web/hooks/useEngineManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ModelEvent,
ModelSource,
ModelSibling,
ModelExtension,
} from '@janhq/core'
import { useAtom, useAtomValue } from 'jotai'
import { atomWithStorage } from 'jotai/utils'
Expand Down Expand Up @@ -497,3 +498,21 @@ export const useRefreshModelList = (engine: string) => {

return { refreshingModels, refreshModels }
}

export const useFetchModelsHub = () => {
const extension = useMemo(
() => extensionManager.get<ModelExtension>(ExtensionTypeEnum.Model) ?? null,
[]
)

const { data, error, mutate } = useSWR(
extension ? 'fetchModelsHub' : null,
() => extension?.fetchModelsHub(),
{
revalidateOnFocus: false,
revalidateOnReconnect: true,
}
)

return { modelsHub: data, error, mutate }
}
15 changes: 13 additions & 2 deletions web/screens/Hub/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
import CenterPanelContainer from '@/containers/CenterPanelContainer'
import ModelSearch from '@/containers/ModelSearch'

import { useGetEngineModelSources } from '@/hooks/useEngineManagement'
import {
useFetchModelsHub,
useGetEngineModelSources,
} from '@/hooks/useEngineManagement'
import { setImportModelStageAtom } from '@/hooks/useImportModel'

import {
Expand Down Expand Up @@ -85,6 +88,7 @@
const HubScreen = () => {
const { sources } = useGetModelSources()
const { sources: remoteModelSources } = useGetEngineModelSources()
const { mutate: fetchModelsHub } = useFetchModelsHub()
const { addModelSource } = useModelSourcesMutation()
const [searchValue, setSearchValue] = useState('')
const [sortSelected, setSortSelected] = useState('newest')
Expand Down Expand Up @@ -149,7 +153,7 @@

return isCompatible && matchesCtxLen && matchesMinSize && matchesMaxSize
})
}, [

Check warning on line 156 in web/screens/Hub/index.tsx

View workflow job for this annotation

GitHub Actions / test-on-macos-pr-target

React Hook useMemo has a missing dependency: 'largestModel?.size'. Either include it or remove the dependency array

Check warning on line 156 in web/screens/Hub/index.tsx

View workflow job for this annot 6D40 ation

GitHub Actions / test-on-macos

React Hook useMemo has a missing dependency: 'largestModel?.size'. Either include it or remove the dependency array

Check warning on line 156 in web/screens/Hub/index.tsx

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

React Hook useMemo has a missing dependency: 'largestModel?.size'. Either include it or remove the dependency array

Check warning on line 156 in web/screens/Hub/index.tsx

View workflow job for this annotation

GitHub Actions / test-on-ubuntu-pr-target

React Hook useMemo has a missing dependency: 'largestModel?.size'. Either include it or remove the dependency array

Check warning on line 156 in web/screens/Hub/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

React Hook useMemo has a missing dependency: 'largestModel?.size'. Either include it or remove the dependency array

Check warning on line 156 in web/screens/Hub/index.tsx

View workflow job for this annotation

GitHub Actions / test-on-windows-pr-target

React Hook useMemo has a missing dependency: 'largestModel?.size'. Either include it or remove the dependency array
sources,
compatible,
ctxLenFilter,
Expand Down Expand Up @@ -189,7 +193,7 @@
)
)
}
}, [largestModel])

Check warning on line 196 in web/screens/Hub/index.tsx

View workflow job for this annotation

GitHub Actions / test-on-macos-pr-target

React Hook useEffect has a missing dependency: 'setMaxModelSizeFilter'. Either include it or remove the dependency array

Check warning on line 196 in web/screens/Hub/index.tsx

View workflow job for this annotation

GitHub Actions / test-on-macos

React Hook useEffect has a missing dependency: 'setMaxModelSizeFilter'. Either include it or remove the dependency array

Check warning on line 196 in web/screens/Hub/index.tsx

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

React Hook useEffect has a missing dependency: 'setMaxModelSizeFilter'. Either include it or remove the dependency array

Check warning on line 196 in web/screens/Hub/index.tsx

View workflow job for this annotation

GitHub Actions / test-on-ubuntu-pr-target

React Hook useEffect has a missing dependency: 'setMaxModelSizeFilter'. Either include it or remove the dependency array

Check warning on line 196 in web/screens/Hub/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

React Hook useEffect has a missing dependency: 'setMaxModelSizeFilter'. Either include it or remove the dependency array

Check warning on line 196 in web/screens/Hub/index.tsx

View workflow job for this annotation

GitHub Actions / test-on-windows-pr-target

React Hook useEffect has a missing dependency: 'setMaxModelSizeFilter'. Either include it or remove the dependency array

useEffect(() => {
if (selectedModel) {
Expand Down Expand Up @@ -268,6 +272,10 @@
},
})

useEffect(() => {
fetchModelsHub()
}, [])

return (
<CenterPanelContainer>
<m.div
Expand Down Expand Up @@ -422,7 +430,10 @@
<div className="absolute left-1/2 top-1/2 z-10 mx-auto w-4/5 -translate-x-1/2 -translate-y-1/2 rounded-xl sm:w-2/6">
<div className="flex flex-col items-center justify-between gap-2 sm:flex-row">
<div className="w-full" ref={dropdownRef}>
<ModelSearch />
<ModelSearch
>
supportModelImport
/>
<div
className={twMerge(
'invisible absolute mt-2 max-h-[400px] w-full overflow-y-auto rounded-lg border border-[hsla(var(--app-border))] bg-[hsla(var(--app-bg))] shadow-lg',
Expand Down
3 changes: 2 additions & 1 deletion web/utils/messageRequestBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ export class MessageRequestBuilder {
const stack = new Stack<ChatCompletionMessage>()
for (const message of messages) {
// Handle message content such as reasoning tags
message.content = this.reasoningTagHandle(message)
if (message.role === ChatCompletionRole.Assistant)
message.content = this.reasoningTagHandle(message)
if (stack.isEmpty()) {
stack.push(message)
continue
Expand Down
Loading
0