MCPcopy Index your code
hub / github.com/DeveloperHarris/gptstatus / testOpenAIAPI

Function testOpenAIAPI

workers/utils.ts:9–154  ·  view source on GitHub ↗
(OPENAI_API_KEY: string, model: string)

Source from the content-addressed store, hash-verified

7const completions_url = "https://api.openai.com/v1/completions"
8
9export async function testOpenAIAPI(OPENAI_API_KEY: string, model: string) {
10 // Create request
11 const base = {
12 model,
13 temperature,
14 max_tokens,
15 stream: true,
16 }
17
18 let body
19 let url
20
21 if (model == "gpt-4" || model == "gpt-3.5-turbo") {
22 url = chat_url
23 body = JSON.stringify({
24 ...base,
25 messages: [
26 {
27 role: "system",
28 content: "You are an expert in quantum mechanics & computing.",
29 },
30 {
31 role: "user",
32 content:
33 "Can you please provide an extensive & in-depth overview of Quantum Cryptography, and the current research being done?",
34 },
35 ],
36 })
37 } else {
38 url = completions_url
39 body = JSON.stringify({
40 ...base,
41 prompt:
42 "Can you please provide an extensive & in-depth overview of Quantum Cryptography, and the current research being done?",
43 })
44 }
45
46 // Send request
47 let generationAttempts = 0
48 const maxGenerationAttempts = 3
49 let finishReason = null
50
51 let startDate
52
53 let ttfb
54 let duration
55
56 while (generationAttempts < maxGenerationAttempts) {
57 generationAttempts++
58
59 startDate = Date.now()
60
61 const response = await fetch(url, {
62 method: "POST",
63 headers: {
64 "Content-Type": "application/json",
65 Authorization: `Bearer ${OPENAI_API_KEY}`,
66 },

Callers 3

scheduledFunction · 0.90
scheduledFunction · 0.90
scheduledFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected