MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / openAiCost

Function openAiCost

lib/utils.ts:98–129  ·  view source on GitHub ↗
(
  messages: ChatGPTMessage[],
  put: "in" | "out",
  model: string,
)

Source from the content-addressed store, hash-verified

96}
97
98export 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
131export function getTokenCount(prompt: ChatGPTMessage[] | string): number {
132 let chatGptMessages: ChatMessage[];

Callers 3

BertieFunction · 0.90
DottieFunction · 0.90
AngelaFunction · 0.90

Calls 1

getTokenCountFunction · 0.85

Tested by

no test coverage detected