forestwanglin / openai-java

OpenAi GPT API for Java. Including all API from OpenAI except deprecated. It especially includes stream client and jtokkit with function calculation. Including Baidu AI.
MIT License
57 stars 9 forks source link

Token Count Difference (Followup) #5

Closed abhatia-07 closed 8 months ago

abhatia-07 commented 8 months ago

The token count for Tools is still having a difference of 1. Request Body:

{
    "model": "gpt-4",
    "messages": [
        {
            "role": "assistant",
            "content": null,
            "tool_calls": [
                {
                    "id": "call_Id8ycVMsW8gdsf7kSXfgAcf1",
                    "type": "function",
                    "function": {
                        "name": "get_current_weather",
                        "arguments": "{\n  \"location\": \"Boston, MA\"\n}"
                    }
                }
            ]
        },
        {
            "role": "tool",
            "tool_call_id": "call_Id8ycVMsW8gdsf7kSXfgAcf1",
            "name": "get_current_weather",
            "content": "29 degree celcius"
        }
    ]
}

My count: 34 OpenAI Count: 35

My guess is that even "tool" role requires 3 tokens.

Thanks

abhatia-07 commented 8 months ago

I just saw you've reopened #4 , closing this one as duplicate.