mirror of
https://github.com/ivanfioravanti/chatbot-ollama.git
synced 2023-12-01 22:17:38 +03:00
42 lines
802 B
TypeScript
42 lines
802 B
TypeScript
import { useCallback } from 'react';
|
|
|
|
import { useFetch } from '@/hooks/useFetch';
|
|
|
|
import {OllamaModel, OllamaModelDetail} from '@/types/ollama'
|
|
|
|
|
|
const useApiService = () => {
|
|
const fetchService = useFetch();
|
|
|
|
const getModels = useCallback(
|
|
(): Promise<OllamaModel[]> => {
|
|
return fetchService.get(`/api/models`, {
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
});
|
|
},
|
|
[fetchService],
|
|
);
|
|
|
|
const getModelDetails = useCallback(
|
|
(name: string) => {
|
|
return fetchService.post(`/api/modeldetails`, {
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: {name: name },
|
|
});
|
|
},
|
|
[fetchService],
|
|
);
|
|
|
|
return {
|
|
getModels,
|
|
getModelDetails
|
|
};
|
|
};
|
|
|
|
export default useApiService;
|
|
|