app.tsx 4.19 KB
Newer Older
Jeffrey Morgan's avatar
Jeffrey Morgan committed
1
import { useState } from 'react'
2
import copy from 'copy-to-clipboard'
3
import { exec as cbExec } from 'child_process'
4
5
6
7
8
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'
9
import { promisify } from 'util'
10

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

14
async function installCLI() {
15
16
17
  const symlinkPath = '/usr/local/bin/ollama'

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

21
  const command = `do shell script "ln -F -s ${ollama} /usr/local/bin/ollama" with administrator privileges`
Jeffrey Morgan's avatar
Jeffrey Morgan committed
22

23
24
25
26
27
28
  try {
    await exec(`osascript -e '${command}'`)
  } catch (error) {
    console.error(`cli: failed to install cli: ${error.message}`)
    return
  }
Jeffrey Morgan's avatar
Jeffrey Morgan committed
29
}
Jeffrey Morgan's avatar
Jeffrey Morgan committed
30

Jeffrey Morgan's avatar
Jeffrey Morgan committed
31
32
33
34
35
36
enum Step {
  WELCOME = 0,
  CLI,
  FINISH,
}

Jeffrey Morgan's avatar
Jeffrey Morgan committed
37
export default function () {
Jeffrey Morgan's avatar
Jeffrey Morgan committed
38
  const [step, setStep] = useState<Step>(Step.WELCOME)
39
40

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

Jeffrey Morgan's avatar
Jeffrey Morgan committed
42
  return (
Jeffrey Morgan's avatar
Jeffrey Morgan committed
43
44
    <div className='drag mx-auto flex min-h-screen w-full flex-col justify-between bg-white px-4 pt-16'>
      {step === Step.WELCOME && (
45
        <>
Jeffrey Morgan's avatar
Jeffrey Morgan committed
46
47
48
49
          <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.
50
51
52
53
54
            </p>
            <button
              onClick={() => {
                setStep(1)
              }}
Jeffrey Morgan's avatar
Jeffrey Morgan committed
55
              className='rounded-dm mx-auto my-8 w-[40%] rounded-md bg-black px-4 py-2 text-sm text-white hover:brightness-110'
56
57
            >
              Next
Jeffrey Morgan's avatar
Jeffrey Morgan committed
58
            </button>
59
          </div>
Jeffrey Morgan's avatar
Jeffrey Morgan committed
60
          <div className='mx-auto'>
61
62
63
64
            <OllamaIcon />
          </div>
        </>
      )}
Jeffrey Morgan's avatar
Jeffrey Morgan committed
65
      {step === Step.CLI && (
66
        <>
Jeffrey Morgan's avatar
Jeffrey Morgan committed
67
68
69
70
          <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'>
71
              <button
72
73
74
75
                onClick={async () => {
                  await installCLI()
                  window.focus()
                  setStep(2)
76
                }}
Jeffrey Morgan's avatar
Jeffrey Morgan committed
77
                className='rounded-dm mx-auto w-[60%] rounded-md bg-black px-4 py-2 text-sm text-white hover:brightness-110'
78
79
80
              >
                Install
              </button>
Jeffrey Morgan's avatar
Jeffrey Morgan committed
81
              <p className='mx-auto my-4 w-[70%] text-xs text-gray-400'>
82
83
84
85
86
87
                You will be prompted for administrator access
              </p>
            </div>
          </div>
        </>
      )}
Jeffrey Morgan's avatar
Jeffrey Morgan committed
88
      {step === Step.FINISH && (
89
        <>
Jeffrey Morgan's avatar
Jeffrey Morgan committed
90
91
92
93
94
          <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'>
95
96
97
98
99
100
101
102
                  {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
103
                  <DocumentDuplicateIcon className='h-4 w-4 text-gray-500' />
104
                </button>
Jeffrey Morgan's avatar
Jeffrey Morgan committed
105
              </div>
Jeffrey Morgan's avatar
Jeffrey Morgan committed
106
              <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
107
            </div>
108
109
110
111
            <button
              onClick={() => {
                window.close()
              }}
Jeffrey Morgan's avatar
Jeffrey Morgan committed
112
              className='rounded-dm mx-auto w-[60%] rounded-md bg-black px-4 py-2 text-sm text-white hover:brightness-110'
113
114
115
116
117
            >
              Finish
            </button>
          </div>
        </>
Jeffrey Morgan's avatar
Jeffrey Morgan committed
118
      )}
Jeffrey Morgan's avatar
Jeffrey Morgan committed
119
120
    </div>
  )
Jeffrey Morgan's avatar
Jeffrey Morgan committed
121
}