( messages: ChatGPTMessage[], put: "in" | "out", model: string, )
| 96 | } |
| 97 | |
| 98 | export function openAiCost( |
| 99 | messages: ChatGPTMessage[], |
| 100 | put: "in" | "out", |
| 101 | model: string, |
| 102 | ): number { |
| 103 | let costPerThousand; |
| 104 | |
| 105 | switch (put) { |
| 106 | case "in": |
| 107 | costPerThousand = model.startsWith("ft:gpt-3.5-turbo-0613") |
| 108 | ? 0.003 |
| 109 | : model === "gpt-3.5-turbo-16k" |
| 110 | ? 0.0005 |
| 111 | : model.includes("gpt-3.5") |
| 112 | ? 0.0005 |
| 113 | : 0.03; |
| 114 | break; |
| 115 | case "out": { |
| 116 | costPerThousand = model.startsWith("ft:gpt-3.5-turbo-0613") |
| 117 | ? 0.006 |
| 118 | : model === "gpt-3.5-turbo-16k" |
| 119 | ? 0.0015 |
| 120 | : model.includes("gpt-3.5") |
| 121 | ? 0.0015 |
| 122 | : 0.06; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | const nTokens = getTokenCount(messages); |
| 127 | // For the 8k context model |
| 128 | return nTokens * (costPerThousand / 1000); |
| 129 | } |
| 130 | |
| 131 | export function getTokenCount(prompt: ChatGPTMessage[] | string): number { |
| 132 | let chatGptMessages: ChatMessage[]; |
no test coverage detected