Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect mapping of JSON keys #5

Open
jpenna opened this issue Oct 15, 2024 · 0 comments
Open

Incorrect mapping of JSON keys #5

jpenna opened this issue Oct 15, 2024 · 0 comments

Comments

@jpenna
Copy link

jpenna commented Oct 15, 2024

Hello and thanks for this project!

I wasn't getting the FinishReason, so I looked into the response sent by Groq and found that the mapping is wrong. Instead of camel case, they are using snake case:

{
  "id": "chatcmpl-038eb64d-d89d-4095-9ae0-aa28f15ee894",
  "object": "chat.completion",
  "created": 1729027271,
  "model": "mixtral-8x7b-32768",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "{\n  \"title\": \"thread_relevance\",\n  \"description\": \"The relevance data of this thread\",\n  \"type\": \"object\",\n  \"required\": [\n    \"relevance\"\n  ],\n  \"properties\": {\n    \"relevance\": \"regular\",\n    \"description\": \"Discussing the upcoming team meeting agenda\",\n    \"whyMatters\": \"Affects the entire team's schedule and tasks\"\n  }\n}"
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "queue_time": 0.0009843939999999995,
    "prompt_tokens": 319,
    "prompt_time": 0.018412544,
    "completion_tokens": 110,
    "completion_time": 0.176677053,
    "total_tokens": 429,
    "total_time": 0.195089597
  },
  "system_fingerprint": "fp_c5f20b5bb1",
  "x_groq": { "id": "req_01ja90wtajf6497an9fnywdy5y" }
}

The lib expects the keys to be camel case:

type Choice struct {
	FinishReason string         `json:"finishReason"`
	Index        int            `json:"index"`
	Logprobs     ChoiceLogprobs `json:"logprobs"`
	Message      ChoiceMessage  `json:"message"`
}

// Usage struct to handle usage data
type Usage struct {
	CompletionTime   *float64 `json:"completionTime,omitempty"`
	CompletionTokens *int     `json:"completionTokens,omitempty"`
	PromptTime       *float64 `json:"promptTime,omitempty"`
	PromptTokens     *int     `json:"promptTokens,omitempty"`
	QueueTime        *float64 `json:"queueTime,omitempty"`
	TotalTime        *float64 `json:"totalTime,omitempty"`
	TotalTokens      *int     `json:"totalTokens,omitempty"`
}

I don't know if this was changed later by the Groq team?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant