app.tsx 4.24 KB
Newer Older
Jeffrey Morgan's avatar
Jeffrey Morgan committed
1
import { useState } from 'react'
2
3
4
5
6
7
8
9
import copy from 'copy-to-clipboard'
import { exec } from 'child_process'
import * as path from 'path'
import * as fs from 'fs'
import { DocumentDuplicateIcon } from '@heroicons/react/24/outline'
import { app } from '@electron/remote'
import OllamaIcon from './ollama.svg'

Jeffrey Morgan's avatar
Jeffrey Morgan committed
10
const ollama = app.isPackaged ? path.join(process.resourcesPath, 'ollama') : path.resolve(process.cwd(), '..', 'ollama')
11

Jeffrey Morgan's avatar
Jeffrey Morgan committed
12
async function installCLI(callback: () => void) {
13
14
15
16
  const symlinkPath = '/usr/local/bin/ollama'

  if (fs.existsSync(symlinkPath) && fs.readlinkSync(symlinkPath) === ollama) {
    callback && callback()
Jeffrey Morgan's avatar
Jeffrey Morgan committed
17
18
19
    return
  }

20
21
22
23
24
25
26
27
  const command = `
    do shell script "ln -F -s ${ollama} /usr/local/bin/ollama" with administrator privileges
  `
  exec(`osascript -e '${command}'`, (error: Error | null, stdout: string, stderr: string) => {
    if (error) {
      console.error(`cli: failed to install cli: ${error.message}`)
      callback && callback()
      return
Jeffrey Morgan's avatar
Jeffrey Morgan committed
28
    }
Jeffrey Morgan's avatar
Jeffrey Morgan committed
29

30
31
    callback && callback()
  })
Jeffrey Morgan's avatar
Jeffrey Morgan committed
32
}
Jeffrey Morgan's avatar
Jeffrey Morgan committed
33

Jeffrey Morgan's avatar
Jeffrey Morgan committed
34
export default function () {
35
36
37
  const [step, setStep] = useState(0)

  const command = 'ollama run orca'
Jeffrey Morgan's avatar
Jeffrey Morgan committed
38

Jeffrey Morgan's avatar
Jeffrey Morgan committed
39
  return (
Jeffrey Morgan's avatar
Jeffrey Morgan committed
40
    <div className='mx-auto flex min-h-screen w-full flex-col justify-between bg-white px-4 pt-16'>
41
42
      {step === 0 && (
        <>
Jeffrey Morgan's avatar
Jeffrey Morgan committed
43
44
45
46
          <div className='mx-auto text-center'>
            <h1 className='mb-6 mt-4 text-2xl tracking-tight text-gray-900'>Welcome to Ollama</h1>
            <p className='mx-auto w-[65%] text-sm text-gray-400'>
              Let's get you up and running with your own large language models.
47
48
49
50
51
            </p>
            <button
              onClick={() => {
                setStep(1)
              }}
Jeffrey Morgan's avatar
Jeffrey Morgan committed
52
              className='rounded-dm mx-auto my-8 w-[40%] rounded-md bg-black px-4 py-2 text-sm text-white hover:brightness-110'
53
54
            >
              Next
Jeffrey Morgan's avatar
Jeffrey Morgan committed
55
            </button>
56
          </div>
Jeffrey Morgan's avatar
Jeffrey Morgan committed
57
          <div className='mx-auto'>
58
59
60
61
62
63
            <OllamaIcon />
          </div>
        </>
      )}
      {step === 1 && (
        <>
Jeffrey Morgan's avatar
Jeffrey Morgan committed
64
65
66
67
          <div className='mx-auto flex flex-col space-y-28 text-center'>
            <h1 className='mt-4 text-2xl tracking-tight text-gray-900'>Install the command line</h1>
            <pre className='mx-auto text-4xl text-gray-400'>&gt; ollama</pre>
            <div className='mx-auto'>
68
69
70
71
72
73
74
75
              <button
                onClick={() => {
                  // install the command line
                  installCLI(() => {
                    window.focus()
                    setStep(2)
                  })
                }}
Jeffrey Morgan's avatar
Jeffrey Morgan committed
76
                className='rounded-dm mx-auto w-[60%] rounded-md bg-black px-4 py-2 text-sm text-white hover:brightness-110'
77
78
79
              >
                Install
              </button>
Jeffrey Morgan's avatar
Jeffrey Morgan committed
80
              <p className='mx-auto my-4 w-[70%] text-xs text-gray-400'>
81
82
83
84
85
86
87
88
                You will be prompted for administrator access
              </p>
            </div>
          </div>
        </>
      )}
      {step === 2 && (
        <>
Jeffrey Morgan's avatar
Jeffrey Morgan committed
89
90
91
92
93
          <div className='mx-auto flex flex-col space-y-20 text-center'>
            <h1 className='mt-4 text-2xl tracking-tight text-gray-900'>Run your first model</h1>
            <div className='flex flex-col'>
              <div className='group relative flex items-center'>
                <pre className='language-none text-2xs w-full rounded-md bg-gray-100 px-4 py-3 text-start leading-normal'>
94
95
96
97
98
99
100
101
                  {command}
                </pre>
                <button
                  className='absolute right-[5px] rounded-md border bg-white/90 px-2 py-2 text-gray-400 opacity-0 backdrop-blur-xl hover:text-gray-600 group-hover:opacity-100'
                  onClick={() => {
                    copy(command)
                  }}
                >
Jeffrey Morgan's avatar
Jeffrey Morgan committed
102
                  <DocumentDuplicateIcon className='h-4 w-4 text-gray-500' />
103
                </button>
Jeffrey Morgan's avatar
Jeffrey Morgan committed
104
              </div>
Jeffrey Morgan's avatar
Jeffrey Morgan committed
105
              <p className='mx-auto my-4 w-[70%] text-xs text-gray-400'>Run this command in your favorite terminal.</p>
Jeffrey Morgan's avatar
Jeffrey Morgan committed
106
            </div>
107
108
109
110
            <button
              onClick={() => {
                window.close()
              }}
Jeffrey Morgan's avatar
Jeffrey Morgan committed
111
              className='rounded-dm mx-auto w-[60%] rounded-md bg-black px-4 py-2 text-sm text-white hover:brightness-110'
112
113
114
115
116
            >
              Finish
            </button>
          </div>
        </>
Jeffrey Morgan's avatar
Jeffrey Morgan committed
117
      )}
Jeffrey Morgan's avatar
Jeffrey Morgan committed
118
119
    </div>
  )
Jeffrey Morgan's avatar
Jeffrey Morgan committed
120
}