package main import ( "bytes" "encoding/json" "io" "net/http" "strings" "github.com/gofiber/fiber/v2" ) type TogetherChatCompletionResponse struct { ID string `json:"id"` Object string `json:"object"` Created int64 `json:"created"` Model string `json:"model"` Usage OpenaiUsage `json:"usage"` Choices []TogetherChoice `json:"choices"` } type TogetherChoice struct { Text string `json:"text"` FinishReason string `json:"finish_reason"` Index int `json:"index"` } var TogetherErrorCodes map[string]string func init() { TogetherErrorCodes = make(map[string]string) TogetherErrorCodes["400"] = "Provider error: Invalid Request - Please contact the support." TogetherErrorCodes["401"] = "Provider error: nvalid Authentication - Ensure that the API key is still valid." TogetherErrorCodes["403"] = "Provider error: et max_tokens to a lower number. Or leave it empty for using max value." TogetherErrorCodes["404"] = "Provider error: odel not found." TogetherErrorCodes["429"] = "Provider error: ate limit reached for requests - You are sending requests too quickly." TogetherErrorCodes["500"] = "Provider error: ssue on Together AI servers - Retry your request after a brief wait and contact Together AI if the issue persists." TogetherErrorCodes["503"] = "Provider error: ervers are experiencing high traffic - Please retry your requests after a brief wait." TogetherErrorCodes["504"] = "Provider error: ervers are experiencing high traffic - Please retry your requests after a brief wait." TogetherErrorCodes["520"] = "Provider error: n unexpected error has occurred internal to Together’s systems." TogetherErrorCodes["524"] = "Provider error: n unexpected error has occurred internal to Together’s systems." TogetherErrorCodes["529"] = "Provider error: n unexpected error has occurred internal to Together’s systems." } func RequestTogether(c *fiber.Ctx, llm LLM, messages []Message) string { model := llm.Model.ModelID temperature := float64(llm.Temperature) context := llm.Context maxTokens := int(llm.MaxToken) var apiKey string err := edgeGlobalClient.WithGlobals(map[string]interface{}{"ext::auth::client_token": c.Cookies("jade-edgedb-auth-token")}).QuerySingle(edgeCtx, ` with filtered_keys := ( select Key { key } filter .company.name = $0 AND .$0 LIMIT 1 `, &usedModelInfo, model) if err != nil { logErrorCode.Println("07-00-0006") return "JADE internal error: 07-00-0006. Please contact the support." } var inputCost float32 = float32(chatCompletionResponse.Usage.PromptTokens) * usedModelInfo.InputPrice var outputCost float32 = float32(chatCompletionResponse.Usage.CompletionTokens) * usedModelInfo.OutputPrice addUsage(c, inputCost, outputCost, chatCompletionResponse.Usage.PromptTokens, chatCompletionResponse.Usage.CompletionTokens, model) if len(chatCompletionResponse.Choices) == 0 { logErrorCode.Println("07-03-0007 -", resp.Status, "-", string(body)) return "JADE internal error: 07-03-0007. Please contact the support." } return chatCompletionResponse.Choices[0].Text }