app.tsx 4.09 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
export default function () {
32
33
34
  const [step, setStep] = useState(0)

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

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