MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / extractModelNameFromGeminiPath

Function extractModelNameFromGeminiPath

middleware/distributor.go:308–331  ·  view source on GitHub ↗

extractModelNameFromGeminiPath 从 Gemini API URL 路径中提取模型名 输入格式: /v1beta/models/gemini-2.0-flash:generateContent 输出: gemini-2.0-flash

(path string)

Source from the content-addressed store, hash-verified

306// 输入格式: /v1beta/models/gemini-2.0-flash:generateContent
307// 输出: gemini-2.0-flash
308func extractModelNameFromGeminiPath(path string) string {
309 // 查找 "/models/" 的位置
310 modelsPrefix := "/models/"
311 modelsIndex := strings.Index(path, modelsPrefix)
312 if modelsIndex == -1 {
313 return ""
314 }
315
316 // 从 "/models/" 之后开始提取
317 startIndex := modelsIndex + len(modelsPrefix)
318 if startIndex >= len(path) {
319 return ""
320 }
321
322 // 查找 ":" 的位置,模型名在 ":" 之前
323 colonIndex := strings.Index(path[startIndex:], ":")
324 if colonIndex == -1 {
325 // 如果没有找到 ":",返回从 "/models/" 到路径结尾的部分
326 return path[startIndex:]
327 }
328
329 // 返回模型名部分
330 return path[startIndex : startIndex+colonIndex]
331}

Callers 1

getModelRequestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected