File size: 1,677 Bytes
b022cb9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { useLocalStorage } from "usehooks-ts"

import { defaultSettings } from "@/app/interface/settings-dialog/defaultSettings"
import { localStorageKeys } from "@/app/interface/settings-dialog/localStorageKeys"
import { LLMEngine, LLMVendor, LLMVendorConfig } from "@/types"

export function useLLMVendorConfig(): LLMVendorConfig {

  const [vendor, ] = useLocalStorage<LLMVendor>(
    localStorageKeys.llmVendor,
    defaultSettings.llmVendor
  )
  const [openaiApiKey, ] = useLocalStorage<string>(
    localStorageKeys.openaiApiKey,
    defaultSettings.openaiApiKey
  )
  const [openaiApiLanguageModel, ] = useLocalStorage<string>(
    localStorageKeys.openaiApiLanguageModel,
    defaultSettings.openaiApiLanguageModel
  )
  const [groqApiKey, ] = useLocalStorage<string>(
    localStorageKeys.groqApiKey,
    defaultSettings.groqApiKey
  )
  const [groqApiLanguageModel, ] = useLocalStorage<string>(
    localStorageKeys.groqApiLanguageModel,
    defaultSettings.groqApiLanguageModel
  )
  const [anthropicApiKey, ] = useLocalStorage<string>(
    localStorageKeys.anthropicApiKey,
    defaultSettings.anthropicApiKey
  )
  const [anthropicApiLanguageModel, ] = useLocalStorage<string>(
    localStorageKeys.anthropicApiLanguageModel,
    defaultSettings.anthropicApiLanguageModel
  )

  const apiKey =
    vendor === "ANTHROPIC" ? anthropicApiKey :
    vendor === "GROQ" ? groqApiKey :
    vendor === "OPENAI" ? openaiApiKey :
    ""
  
  const modelId =
    vendor === "ANTHROPIC" ? anthropicApiLanguageModel :
    vendor === "GROQ" ? groqApiLanguageModel :
    vendor === "OPENAI" ? openaiApiLanguageModel :
    ""

  return {
    vendor,
    apiKey,
    modelId,
  }
}