+svelte FE

This commit is contained in:
Miki 2024-06-05 11:32:46 +02:00
parent b8ff360407
commit fbf9fc0fff
36 changed files with 111 additions and 37 deletions

View file

@ -22,6 +22,7 @@ FROM gcr.io/distroless/base-debian11 AS build-release-stage
WORKDIR /
COPY --from=build-stage /GPT-backend /GPT-backend
COPY static/ ./static
EXPOSE 4000

97
main.go
View file

@ -30,11 +30,13 @@ type Containers struct {
}
type Container struct {
Name string `json:"names"`
Port int `json:"port"`
IP string `json:"ip"`
Image string `json:"image"`
ID string `json:"id"`
Name string `json:"names"`
Port int `json:"port"`
IP string `json:"ip"`
Image string `json:"image"`
ID string `json:"id"`
Status string `json:"status"`
State string `json:"state"`
}
type Details struct {
@ -54,6 +56,7 @@ type Model struct {
Details Details `json:"details"`
Ip string `json:"ip"`
Port int `json:"port"`
State string `json:"state"`
}
type Models struct {
@ -66,7 +69,7 @@ func get_ollama_tags(hosts Hosts) (Models, error) {
for _, host := range hosts.Hosts {
fmt.Printf("%s -> %s\n", host.Name, host.IP)
ctr.Adds(get_ollama_containers(host))
ctr.Adds(get_ollama_containers(host, false))
// ctr = append(ctr, get_ollama_containers(host)...)
fmt.Println(ctr)
}
@ -74,39 +77,44 @@ func get_ollama_tags(hosts Hosts) (Models, error) {
retval := []Model{}
for _, ollama := range ctr.Containers {
url := fmt.Sprintf("http://%s:%d/api/tags", ollama.IP, ollama.Port)
resp, err := http.Get(url)
if err != nil {
return Models{}, fmt.Errorf("failed to get %s: %v", url, err)
if ollama.State != "running" {
retval = append(retval, Model{Ip: ollama.IP, Port: ollama.Port, State: "stopped"})
} else {
url := fmt.Sprintf("http://%s:%d/api/tags", ollama.IP, ollama.Port)
resp, err := http.Get(url)
if err != nil {
return Models{}, fmt.Errorf("failed to get %s: %v", url, err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return Models{}, fmt.Errorf("failed to read body: %v", err)
}
mods := Models{}
err = json.Unmarshal(body, &mods)
if err != nil {
return Models{}, fmt.Errorf("failed to unmarshal JSON: %v", err)
}
fmt.Printf("%+v\n", mods)
for n := range mods.Models {
mods.Models[n].Ip = ollama.IP
mods.Models[n].Port = ollama.Port
mods.Models[n].State = "running"
}
fmt.Printf("mod: %+v\n", mods)
retval = append(retval, mods.Models...)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return Models{}, fmt.Errorf("failed to read body: %v", err)
}
mods := Models{}
err = json.Unmarshal(body, &mods)
if err != nil {
return Models{}, fmt.Errorf("failed to unmarshal JSON: %v", err)
}
fmt.Printf("%+v\n", mods)
for n := range mods.Models {
mods.Models[n].Ip = ollama.IP
mods.Models[n].Port = ollama.Port
}
fmt.Printf("mod: %+v\n", mods)
retval = append(retval, mods.Models...)
}
return Models{Models: retval}, nil
}
func get_ollama_containers(host Host) Containers {
func get_ollama_containers(host Host, all bool) Containers {
ctr_list := Containers{}
@ -117,22 +125,26 @@ func get_ollama_containers(host Host) Containers {
}
defer cli.Close()
containers, err := cli.ContainerList(context.Background(), container.ListOptions{All: false})
containers, err := cli.ContainerList(context.Background(), container.ListOptions{All: all})
if err != nil {
panic(err)
}
for _, ctr := range containers {
if strings.Contains(ctr.Names[0], "ollama") && ctr.Image == "ollama/ollama" {
c := Container{ID: ctr.ID, Name: ctr.Names[0], Image: ctr.Image}
fmt.Println(ctr.Ports[0])
c := Container{ID: ctr.ID, Name: ctr.Names[0], Image: ctr.Image, State: ctr.State, Status: ctr.Status}
if ctr.State == "running" {
fmt.Println(ctr.Ports[0])
c.Port = int(ctr.Ports[0].PublicPort)
}
c.IP = host.IP
c.Port = int(ctr.Ports[0].PublicPort)
ctr_list.Add(c)
// ctr_list = append(ctr_list, c)
}
}
fmt.Println(ctr_list)
return ctr_list
}
@ -169,6 +181,17 @@ func main() {
c.JSON(200, models)
})
sapp := r.Group("/_app")
sapp.Static("/", "./static/_app")
static := r.Group("/static")
static.Static("/", "./static/static")
r.StaticFile("/", "./static/index.html")
r.StaticFile("/favicon.png", "./static/favicon.png")
r.ForwardedByClientIP = true
fmt.Println("liste")
r.Run(":" + port)

1
static/_app/env.js Normal file
View file

@ -0,0 +1 @@
export const env={}

1
static/_app/env.js.br Normal file
View file

@ -0,0 +1 @@
€export const env={}

BIN
static/_app/env.js.gz Normal file

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1 @@
function k(){}function x(t,n){for(const e in n)t[e]=n[e];return t}function w(t){return t()}function z(){return Object.create(null)}function j(t){t.forEach(w)}function F(t){return typeof t=="function"}function P(t,n){return t!=t?n==n:t!==n||t&&typeof t=="object"||typeof t=="function"}function S(t){return Object.keys(t).length===0}function E(t,...n){if(t==null){for(const o of n)o(void 0);return k}const e=t.subscribe(...n);return e.unsubscribe?()=>e.unsubscribe():e}function U(t,n,e){t.$$.on_destroy.push(E(n,e))}function A(t,n,e,o){if(t){const r=g(t,n,e,o);return t[0](r)}}function g(t,n,e,o){return t[1]&&o?x(e.ctx.slice(),t[1](o(n))):e.ctx}function B(t,n,e,o){if(t[2]&&o){const r=t[2](o(e));if(n.dirty===void 0)return r;if(typeof r=="object"){const a=[],f=Math.max(n.dirty.length,r.length);for(let s=0;s<f;s+=1)a[s]=n.dirty[s]|r[s];return a}return n.dirty|r}return n.dirty}function C(t,n,e,o,r,a){if(r){const f=g(n,e,o,a);t.p(f,r)}}function D(t){if(t.ctx.length>32){const n=[],e=t.ctx.length/32;for(let o=0;o<e;o++)n[o]=-1;return n}return-1}let i;function d(t){i=t}function m(){if(!i)throw new Error("Function called outside component initialization");return i}function G(t){m().$$.on_mount.push(t)}function H(t){m().$$.after_update.push(t)}const l=[],p=[];let u=[];const b=[],y=Promise.resolve();let h=!1;function v(){h||(h=!0,y.then(q))}function I(){return v(),y}function O(t){u.push(t)}const _=new Set;let c=0;function q(){if(c!==0)return;const t=i;do{try{for(;c<l.length;){const n=l[c];c++,d(n),M(n.$$)}}catch(n){throw l.length=0,c=0,n}for(d(null),l.length=0,c=0;p.length;)p.pop()();for(let n=0;n<u.length;n+=1){const e=u[n];_.has(e)||(_.add(e),e())}u.length=0}while(l.length);for(;b.length;)b.pop()();h=!1,_.clear(),d(t)}function M(t){if(t.fragment!==null){t.update(),j(t.before_update);const n=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,n),t.after_update.forEach(O)}}function J(t){const n=[],e=[];u.forEach(o=>t.indexOf(o)===-1?n.push(o):e.push(o)),e.forEach(o=>o()),u=n}export{B as a,U as b,A as c,H as d,p as e,z as f,D as g,q as h,F as i,S as j,O as k,J as l,i as m,k as n,G as o,d as p,w as q,j as r,P as s,I as t,C as u,l as v,v as w};

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1 @@
import{a as t}from"../chunks/entry.CfOJIY_S.js";export{t as start};

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1 @@
import{s as u,c as _,u as f,g as p,a as d}from"../chunks/scheduler.BvLojk_z.js";import{S as h,i as m,e as y,s as g,h as b,c as j,d as c,a as $,b as i,f as v,g as S,t as k,j as T}from"../chunks/index.DWCBnklA.js";const E=!1,I="always",W=Object.freeze(Object.defineProperty({__proto__:null,ssr:E,trailingSlash:I},Symbol.toStringTag,{value:"Module"}));function L(o){let s,l,a;const r=o[1].default,e=_(r,o,o[0],null);return{c(){s=y("link"),l=g(),e&&e.c(),this.h()},l(t){const n=b("svelte-op2tqx",document.head);s=j(n,"LINK",{href:!0,rel:!0,integrity:!0,crossorigin:!0}),n.forEach(c),l=$(t),e&&e.l(t),this.h()},h(){document.title="GPT Backend",i(s,"href","https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"),i(s,"rel","stylesheet"),i(s,"integrity","sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"),i(s,"crossorigin","anonymous")},m(t,n){v(document.head,s),S(t,l,n),e&&e.m(t,n),a=!0},p(t,[n]){e&&e.p&&(!a||n&1)&&f(e,r,t,t[0],a?d(r,t[0],n,null):p(t[0]),null)},i(t){a||(k(e,t),a=!0)},o(t){T(e,t),a=!1},d(t){t&&c(l),c(s),e&&e.d(t)}}}function O(o,s,l){let{$$slots:a={},$$scope:r}=s;return o.$$set=e=>{"$$scope"in e&&l(0,r=e.$$scope)},[r,a]}class Y extends h{constructor(s){super(),m(this,s,O,L,u,{})}}export{Y as component,W as universal};

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1 @@
import{s as S,n as _,b as x}from"../chunks/scheduler.BvLojk_z.js";import{S as k,i as q,e as f,k as d,s as y,c as g,l as h,m as v,d as l,a as C,g as m,f as $,n as E}from"../chunks/index.DWCBnklA.js";import{s as H}from"../chunks/entry.CfOJIY_S.js";const P=()=>{const s=H;return{page:{subscribe:s.page.subscribe},navigating:{subscribe:s.navigating.subscribe},updated:s.updated}},j={subscribe(s){return P().page.subscribe(s)}};function w(s){var b;let t,r=s[0].status+"",n,o,i,c=((b=s[0].error)==null?void 0:b.message)+"",u;return{c(){t=f("h1"),n=d(r),o=y(),i=f("p"),u=d(c)},l(e){t=g(e,"H1",{});var a=h(t);n=v(a,r),a.forEach(l),o=C(e),i=g(e,"P",{});var p=h(i);u=v(p,c),p.forEach(l)},m(e,a){m(e,t,a),$(t,n),m(e,o,a),m(e,i,a),$(i,u)},p(e,[a]){var p;a&1&&r!==(r=e[0].status+"")&&E(n,r),a&1&&c!==(c=((p=e[0].error)==null?void 0:p.message)+"")&&E(u,c)},i:_,o:_,d(e){e&&(l(t),l(o),l(i))}}}function z(s,t,r){let n;return x(s,j,o=>r(0,n=o)),[n]}let F=class extends k{constructor(t){super(),q(this,t,z,w,S,{})}};export{F as component};

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1 @@
import{s as J,n as G}from"../chunks/scheduler.BvLojk_z.js";import{S as K,i as U,e as g,s as D,c as b,o as I,a as S,l as T,d as m,p as V,b as W,g as q,f,q as X,k as E,m as z,n as k}from"../chunks/index.DWCBnklA.js";function N(l){return(l==null?void 0:l.length)!==void 0?l:Array.from(l)}async function Y(){return{containers:await fetch("/api/tags",{mode:"cors",headers:{"Access-Control-Allow-Origin":"*"}}).then(l=>l.json())}}const nt=Object.freeze(Object.defineProperty({__proto__:null,load:Y},Symbol.toStringTag,{value:"Module"}));function Q(l,t,o){const a=l.slice();return a[1]=t[o],a}function Z(l){let t,o=l[1].ip+"",a;return{c(){t=g("td"),a=E(o)},l(e){t=b(e,"TD",{});var i=T(t);a=z(i,o),i.forEach(m)},m(e,i){q(e,t,i),f(t,a)},p(e,i){i&1&&o!==(o=e[1].ip+"")&&k(a,o)},d(e){e&&m(t)}}}function $(l){let t,o=l[1].ip+"",a,e,i=l[1].port+"",p;return{c(){t=g("td"),a=E(o),e=E(":"),p=E(i)},l(h){t=b(h,"TD",{});var r=T(t);a=z(r,o),e=z(r,":"),p=z(r,i),r.forEach(m)},m(h,r){q(h,t,r),f(t,a),f(t,e),f(t,p)},p(h,r){r&1&&o!==(o=h[1].ip+"")&&k(a,o),r&1&&i!==(i=h[1].port+"")&&k(p,i)},d(h){h&&m(t)}}}function F(l){let t,o,a=l[1].name+"",e,i,p,h,r=l[1].details.parameter_size+"",c,s,u,n=l[1].details.quantization_level+"",C,H,P,j=l[1].state+"",A,L;function M(_,d){return _[1].state=="running"?$:Z}let w=M(l),v=w(l);return{c(){t=g("tr"),o=g("td"),e=E(a),i=D(),v.c(),p=D(),h=g("td"),c=E(r),s=D(),u=g("td"),C=E(n),H=D(),P=g("td"),A=E(j),L=D()},l(_){t=b(_,"TR",{});var d=T(t);o=b(d,"TD",{});var O=T(o);e=z(O,a),O.forEach(m),i=S(d),v.l(d),p=S(d),h=b(d,"TD",{});var y=T(h);c=z(y,r),y.forEach(m),s=S(d),u=b(d,"TD",{});var B=T(u);C=z(B,n),B.forEach(m),H=S(d),P=b(d,"TD",{});var R=T(P);A=z(R,j),R.forEach(m),L=S(d),d.forEach(m)},m(_,d){q(_,t,d),f(t,o),f(o,e),f(t,i),v.m(t,null),f(t,p),f(t,h),f(h,c),f(t,s),f(t,u),f(u,C),f(t,H),f(t,P),f(P,A),f(t,L)},p(_,d){d&1&&a!==(a=_[1].name+"")&&k(e,a),w===(w=M(_))&&v?v.p(_,d):(v.d(1),v=w(_),v&&(v.c(),v.m(t,p))),d&1&&r!==(r=_[1].details.parameter_size+"")&&k(c,r),d&1&&n!==(n=_[1].details.quantization_level+"")&&k(C,n),d&1&&j!==(j=_[1].state+"")&&k(A,j)},d(_){_&&m(t),v.d()}}}function x(l){let t,o="GPT Backend",a,e,i,p="<th>Name</th> <th>IP:Port</th> <th>Size</th> <th>Quantization</th> <th>Status</th>",h,r=N(l[0].containers.models),c=[];for(let s=0;s<r.length;s+=1)c[s]=F(Q(l,r,s));return{c(){t=g("h1"),t.textContent=o,a=D(),e=g("table"),i=g("tr"),i.innerHTML=p,h=D();for(let s=0;s<c.length;s+=1)c[s].c();this.h()},l(s){t=b(s,"H1",{style:!0,"data-svelte-h":!0}),I(t)!=="svelte-1hqwykg"&&(t.textContent=o),a=S(s),e=b(s,"TABLE",{class:!0});var u=T(e);i=b(u,"TR",{"data-svelte-h":!0}),I(i)!=="svelte-1jdic5z"&&(i.innerHTML=p),h=S(u);for(let n=0;n<c.length;n+=1)c[n].l(u);u.forEach(m),this.h()},h(){V(t,"text-align","center"),W(e,"class","table table-bordered table-hover")},m(s,u){q(s,t,u),q(s,a,u),q(s,e,u),f(e,i),f(e,h);for(let n=0;n<c.length;n+=1)c[n]&&c[n].m(e,null)},p(s,[u]){if(u&1){r=N(s[0].containers.models);let n;for(n=0;n<r.length;n+=1){const C=Q(s,r,n);c[n]?c[n].p(C,u):(c[n]=F(C),c[n].c(),c[n].m(e,null))}for(;n<c.length;n+=1)c[n].d(1);c.length=r.length}},i:G,o:G,d(s){s&&(m(t),m(a),m(e)),X(c,s)}}}function tt(l,t,o){let{data:a}=t;return l.$$set=e=>{"data"in e&&o(0,a=e.data)},[a]}class at extends K{constructor(t){super(),U(this,t,tt,x,J,{data:0})}}export{at as component,nt as universal};

Binary file not shown.

Binary file not shown.

1
static/_app/version.json Normal file
View file

@ -0,0 +1 @@
{"version":"1717579609103"}

BIN
static/_app/version.json.br Normal file

Binary file not shown.

BIN
static/_app/version.json.gz Normal file

Binary file not shown.

BIN
static/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

34
static/index.html Normal file
View file

@ -0,0 +1,34 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="modulepreload" href="/_app/immutable/entry/start.DxV7aNzM.js">
<link rel="modulepreload" href="/_app/immutable/chunks/entry.CfOJIY_S.js">
<link rel="modulepreload" href="/_app/immutable/chunks/scheduler.BvLojk_z.js">
<link rel="modulepreload" href="/_app/immutable/entry/app.XEpr6ULy.js">
<link rel="modulepreload" href="/_app/immutable/chunks/index.DWCBnklA.js">
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">
<script>
{
__sveltekit_1rf3k0j = {
base: ""
};
const element = document.currentScript.parentElement;
Promise.all([
import("/_app/immutable/entry/start.DxV7aNzM.js"),
import("/_app/immutable/entry/app.XEpr6ULy.js")
]).then(([kit, app]) => {
kit.start(app, element);
});
}
</script>
</div>
</body>
</html>

2
static/index.html.br Normal file
View file

@ -0,0 +1,2 @@

 ŒÔQÍæÙ®­•¡$†ôæÎ©ìEEÛ¢dR§‡“YD¬Ñ¨¯I4¿·D"×uÓãˆÅhµé1P¨Û¾ò [<5B>ZÂfq·ÃÒ½cAŠÏdw±Èª<14>§Ò(wö(bf¤%¤Å(ÖžŽ¥–¬³>„uÛ¾ën‡§ßˆø»¯Uš}†!ãJKp…¨Ý³sE<73>f¨®Œ{Ý-ã‰þ‰K¨ö¸†É> ʲê)†6M¸¤ƒwKÒ4ÖõšcZU"“ã'„Kœ¹>dë&›ú-ˆm%qrMâ_`9C(ö¨_œ3†>Ç¢%nF R$r ÅÂÓJkš—éØ}¼2Ë„ýàŒ¤ºâ'=5ÇoÌ7òåÙ÷$¿8æyŒëio íþµr¼9:z/¤õìÍØ €ÊžKz3<7A>¸Ý<C2B8><C39D>hšzóó€ò×»µûñ÷z

BIN
static/index.html.gz Normal file

Binary file not shown.