MCPcopy
hub / github.com/wandb/openui / convert

Function convert

frontend/src/api/openai.ts:212–254  ·  view source on GitHub ↗
(
	options: ConvertOptions,
	callback: (response: string) => void
)

Source from the content-addressed store, hash-verified

210that are repeated atleast 3 times into a shared constant. Leave comments when necessary.`
211
212export async function convert(
213 options: ConvertOptions,
214 callback: (response: string) => void
215) {
216 const { framework, model, temperature, html } = options
217
218 const systemPromptCompiled = systemPromptConvert.replaceAll(
219 '$FRAMEWORK',
220 framework
221 )
222 const messages: OpenAI.Chat.Completions.ChatCompletionMessageParam[] = [
223 {
224 role: 'system',
225 content: systemPromptCompiled
226 }
227 ]
228 /*
229 Let inputTok = ''
230 const encoder = encoding_for_model('gpt-3.5-turbo')
231 inputTok += systemPromptCompiled + '\n'
232 */
233 const userPrompt = `Please turn this into a ${framework} component.`
234 const instructions = `Given the following HTML:\n\n${html}\n\n${userPrompt}`
235 // InputTok += instructions + '\n'
236 messages.push({
237 role: 'user',
238 content: instructions
239 })
240 /*
241 Const tokens = encoder.encode(inputTok)
242 encoder.free()
243 // TODO: use a bigger model if we're length limited
244 */
245 const response = await openai.chat.completions.create({
246 model,
247 messages,
248 temperature,
249 stream: true
250 })
251 for await (const chunk of response) {
252 callback(chunk.choices[0]?.delta?.content ?? '')
253 }
254}

Callers 1

PromptFunction · 0.90

Calls 1

callbackFunction · 0.85

Tested by

no test coverage detected