@@ -9,11 +9,12 @@ import {
9
9
import { Paragraph , Title } from "@cocalc/frontend/components" ;
10
10
import { LLMModelName } from "@cocalc/frontend/components/llm-name" ;
11
11
import {
12
- LanguageModelCore ,
13
12
LLMServiceName ,
14
13
LLM_PROVIDER ,
14
+ LanguageModelCore ,
15
15
USER_SELECTABLE_LLMS_BY_VENDOR ,
16
16
isCoreLanguageModel ,
17
+ toCustomOpenAIModel ,
17
18
toOllamaModel ,
18
19
} from "@cocalc/util/db-schema/llm-utils" ;
19
20
import { getRandomColor , trunc_middle } from "@cocalc/util/misc" ;
@@ -26,6 +27,7 @@ export function TestLLMAdmin() {
26
27
const globallyEnabledLLMs = customize . getEnabledLLMs ( ) ;
27
28
const selectableLLMs = useTypedRedux ( "customize" , "selectable_llms" ) ;
28
29
const ollama = useTypedRedux ( "customize" , "ollama" ) ;
30
+ const custom_openai = useTypedRedux ( "customize" , "custom_openai" ) ;
29
31
const [ test , setTest ] = useState < number | null > ( 0 ) ;
30
32
// TODO: this is used to trigger sending queries – makes no sense that all of them disable it. fix this.
31
33
const [ querying , setQuerying ] = useState < boolean > ( ) ;
@@ -66,6 +68,70 @@ export function TestLLMAdmin() {
66
68
) ;
67
69
}
68
70
71
+ function renderCustomOpenAI ( ) {
72
+ return (
73
+ < Col key = { "custom_openai" } md = { 12 } xs = { 24 } >
74
+ < Title level = { 5 } > Custom OpenAI</ Title >
75
+ { Object . entries ( custom_openai ?. toJS ( ) ?? { } ) . map ( ( [ key , _val ] ) => {
76
+ const model = toCustomOpenAIModel ( key ) ;
77
+
78
+ return (
79
+ < Row
80
+ gutter = { [ 10 , 20 ] }
81
+ style = { llmStyle ( model ) }
82
+ key = { `custom_openai-${ key } ` }
83
+ >
84
+ < Col md = { 24 } >
85
+ < Space >
86
+ < Value val = { true } /> < LLMModelName model = { model } />
87
+ </ Space >
88
+ </ Col >
89
+ < Col md = { 24 } >
90
+ < TestLLM
91
+ test = { test }
92
+ model = { model }
93
+ queryState = { [ querying , setQuerying ] }
94
+ />
95
+ </ Col >
96
+ </ Row >
97
+ ) ;
98
+ } ) }
99
+ </ Col >
100
+ ) ;
101
+ }
102
+
103
+ function renderOllama ( ) {
104
+ return (
105
+ < Col key = { "ollama" } md = { 12 } xs = { 24 } >
106
+ < Title level = { 5 } > Ollama</ Title >
107
+ { Object . entries ( ollama ?. toJS ( ) ?? { } ) . map ( ( [ key , _val ] ) => {
108
+ const model = toOllamaModel ( key ) ;
109
+
110
+ return (
111
+ < Row
112
+ gutter = { [ 10 , 20 ] }
113
+ style = { llmStyle ( model ) }
114
+ key = { `ollama-${ key } ` }
115
+ >
116
+ < Col md = { 24 } >
117
+ < Space >
118
+ < Value val = { true } /> < LLMModelName model = { model } />
119
+ </ Space >
120
+ </ Col >
121
+ < Col md = { 24 } >
122
+ < TestLLM
123
+ test = { test }
124
+ model = { model }
125
+ queryState = { [ querying , setQuerying ] }
126
+ />
127
+ </ Col >
128
+ </ Row >
129
+ ) ;
130
+ } ) }
131
+ </ Col >
132
+ ) ;
133
+ }
134
+
69
135
return (
70
136
< div >
71
137
< Paragraph >
@@ -108,7 +174,7 @@ export function TestLLMAdmin() {
108
174
< Row gutter = { [ 10 , 10 ] } >
109
175
{ Object . entries ( USER_SELECTABLE_LLMS_BY_VENDOR ) . map (
110
176
( [ vendor , llms ] ) =>
111
- vendor !== "ollama" ? (
177
+ vendor !== "ollama" && vendor !== "custom_openai" ? (
112
178
< Col key = { vendor } md = { 12 } xs = { 24 } >
113
179
< Title level = { 5 } > { LLM_PROVIDER [ vendor ] . name } </ Title >
114
180
{ llms
@@ -117,38 +183,15 @@ export function TestLLMAdmin() {
117
183
</ Col >
118
184
) : undefined ,
119
185
) }
120
- < Col key = { "ollama" } md = { 12 } xs = { 24 } >
121
- < Title level = { 5 } > Ollama</ Title >
122
- { Object . entries ( ollama ?. toJS ( ) ?? { } ) . map ( ( [ key , val ] ) => {
123
- const model = toOllamaModel ( val . model ) ;
124
-
125
- return (
126
- < Row
127
- gutter = { [ 10 , 20 ] }
128
- style = { llmStyle ( model ) }
129
- key = { `ollama-${ key } ` }
130
- >
131
- < Col md = { 24 } >
132
- < Space >
133
- < Value val = { true } /> < LLMModelName model = { model } />
134
- </ Space >
135
- </ Col >
136
- < Col md = { 24 } >
137
- < TestLLM
138
- test = { test }
139
- model = { model }
140
- queryState = { [ querying , setQuerying ] }
141
- />
142
- </ Col >
143
- </ Row >
144
- ) ;
145
- } ) }
146
- </ Col >
186
+ { renderOllama ( ) }
187
+ { renderCustomOpenAI ( ) }
147
188
</ Row >
148
189
</ Paragraph >
149
190
150
191
< Title level = { 5 } > Ollama configuration</ Title >
151
192
< Value val = { ollama } />
193
+ < Title level = { 5 } > Custom OpenAI API</ Title >
194
+ < Value val = { custom_openai } />
152
195
</ div >
153
196
) ;
154
197
}
0 commit comments