Skip to content

Commit 90812ad

Browse files
ishandhananitheFong
authored andcommitted
cloudflare public works
1 parent 0cddf61 commit 90812ad

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

pkg/cmd/ollama/ollama.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ import (
2020
)
2121

2222
var (
23-
ollamaLong = "Start an AI/ML model workspace with specified model types"
23+
ollamaLong = "Start an Ollama server with specified model types"
2424
ollamaExample = `
2525
brev ollama --model llama3
26-
brev ollama --model mistral7b
2726
`
28-
modelTypes = []string{"llama2", "llama3", "mistral7b"}
27+
modelTypes = []string{"llama3"}
2928
)
3029

3130
//go:embed ollamaverb.yaml
@@ -38,7 +37,7 @@ type OllamaStore interface {
3837
CreateWorkspace(organizationID string, options *store.CreateWorkspacesOptions) (*entity.Workspace, error)
3938
GetWorkspace(workspaceID string) (*entity.Workspace, error)
4039
BuildVerbContainer(workspaceID string, verbYaml string) (*store.BuildVerbRes, error)
41-
ModifyPublicity(workspace *entity.Workspace, publicity bool) (*entity.Tunnel, error)
40+
ModifyPublicity(workspace *entity.Workspace, applicationName string, publicity bool) (*entity.Tunnel, error)
4241
}
4342

4443
func validateModelType(modelType string) bool {
@@ -188,12 +187,18 @@ func runOllamaWorkspace(t *terminal.Terminal, model string, ollamaStore OllamaSt
188187

189188
s.Stop()
190189

191-
link, err := getOllamaTunnelLink(w, ollamaStore)
190+
// Reload workspace to get the latest status
191+
w, err = ollamaStore.GetWorkspace(w.ID)
192192
if err != nil {
193193
return breverrors.WrapAndTrace(err)
194194
}
195195

196-
_, err = makeTunnelPublic(w, ollamaStore)
196+
link, name, err := getOllamaTunnelLink(w)
197+
if err != nil {
198+
return breverrors.WrapAndTrace(err)
199+
}
200+
201+
_, err = makeTunnelPublic(w, name, ollamaStore)
197202
if err != nil {
198203
return breverrors.WrapAndTrace(err)
199204
}
@@ -224,7 +229,7 @@ func pollInstanceUntilVMReady(workspace *entity.Workspace, interval time.Duratio
224229
time.Sleep(interval)
225230
elapsedTime += interval
226231
}
227-
return false, breverrors.New("timeout waiting for instance to start")
232+
return false, breverrors.New("Timeout waiting for machine to start")
228233
}
229234

230235
func pollInstanceUntilVerbContainerReady(workspace *entity.Workspace, interval time.Duration, timeout time.Duration, ollamaStore OllamaStore) (bool, error) {
@@ -240,29 +245,25 @@ func pollInstanceUntilVerbContainerReady(workspace *entity.Workspace, interval t
240245
time.Sleep(interval)
241246
elapsedTime += interval
242247
}
243-
return false, breverrors.New("timeout waiting for instance to start")
248+
return false, breverrors.New("Timeout waiting for container to build")
244249
}
245250

246-
func getOllamaTunnelLink(workspace *entity.Workspace, ollamaStore OllamaStore) (string, error) {
247-
w, err := ollamaStore.GetWorkspace(workspace.ID)
248-
if err != nil {
249-
return "", breverrors.WrapAndTrace(err)
250-
}
251-
for _, v := range w.Tunnel.Applications {
251+
func getOllamaTunnelLink(workspace *entity.Workspace) (string, string, error) {
252+
for _, v := range workspace.Tunnel.Applications {
252253
if v.Port == 11434 {
253-
return v.Hostname, nil
254+
return v.Hostname, v.Name, nil
254255
}
255256
}
256-
return "", breverrors.New("Could not find Ollama tunnel")
257+
return "", "", breverrors.New("Could not find Ollama tunnel")
257258
}
258259

259-
// TODO: stubs for granular permissioning
260+
// TODO: stub for granular permissioning
260261
// func generateCloudflareAPIKeys(workspace *entity.Workspace, ollamaStore OllamaStore) (bool, error) {
261262
// return false, nil
262263
// }
263264

264-
func makeTunnelPublic(workspace *entity.Workspace, ollamaStore OllamaStore) (bool, error) {
265-
t, err := ollamaStore.ModifyPublicity(workspace, true)
265+
func makeTunnelPublic(workspace *entity.Workspace, applicationName string, ollamaStore OllamaStore) (bool, error) {
266+
t, err := ollamaStore.ModifyPublicity(workspace, applicationName, true)
266267
if err != nil {
267268
return false, breverrors.WrapAndTrace(err)
268269
}

pkg/store/workspace.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,14 +627,14 @@ type ModifyApplicationPublicityRequest struct {
627627
}
628628

629629
// Modify publicity of tunnel after creation
630-
func (s AuthHTTPStore) ModifyPublicity(workspace *entity.Workspace, publicity bool) (*entity.Tunnel, error) {
630+
func (s AuthHTTPStore) ModifyPublicity(workspace *entity.Workspace, applicationName string, publicity bool) (*entity.Tunnel, error) {
631631
var result entity.Tunnel
632632

633633
res, err := s.authHTTPClient.restyClient.R().
634634
SetHeader("Content-Type", "application/json").
635635
SetPathParam(workspaceIDParamName, workspace.ID).
636636
SetBody(ModifyApplicationPublicityRequest{
637-
ApplicationName: workspace.Name,
637+
ApplicationName: applicationName,
638638
Public: publicity,
639639
}).
640640
SetResult(&result).

0 commit comments

Comments
 (0)