From 6a27003a060946958a986b3b1714722484088ca1 Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:24:07 +0800 Subject: [PATCH] logprobs feature completed --- kcpp_docs.embd | 214 +++++++++++++++++++++++++++++++++++++++++++++++++ klite.embd | 132 +++++++++++++++++++++++++++--- koboldcpp.py | 93 ++++++++++++++------- 3 files changed, 396 insertions(+), 43 deletions(-) diff --git a/kcpp_docs.embd b/kcpp_docs.embd index dbf353a182888..8277072410578 100644 --- a/kcpp_docs.embd +++ b/kcpp_docs.embd @@ -257,6 +257,11 @@ "minimum": 0, "type": "number" }, + "logprobs": { + "default": false, + "description": "If true, return up to 5 top logprobs for generated tokens. Incurs performance overhead.", + "type": "boolean" + }, }, "required": [ "prompt" @@ -808,6 +813,215 @@ ] } }, + "/api/extra/last_logprobs": { + "post": { + "description": "Obtains the token logprobs of the most recent request. A unique genkey previously submitted is required in multiuser mode.", + "requestBody": { + "content": { + "application/json": { + "example": { + "genkey": "KCPP2342" + }, + "schema": { + "properties": { + "genkey": { + "type": "string", + "description": "A unique key used to identify the previous generation." + } + }, + "type": "object" + } + } + }, + "required": false + }, + "responses": { + "200": { + "content": { + "application/json": { + "example": { + "logprobs": { + "content": [ + { + "token": "Hello", + "logprob": -0.31725305, + "bytes": [72, 101, 108, 108, 111], + "top_logprobs": [ + { + "token": "Hello", + "logprob": -0.31725305, + "bytes": [72, 101, 108, 108, 111] + }, + { + "token": "Hi", + "logprob": -1.3190403, + "bytes": [72, 105] + } + ] + }, + { + "token": "!", + "logprob": -0.02380986, + "bytes": [ + 33 + ], + "top_logprobs": [ + { + "token": "!", + "logprob": -0.02380986, + "bytes": [33] + }, + { + "token": " there", + "logprob": -3.787621, + "bytes": [32, 116, 104, 101, 114, 101] + } + ] + }, + { + "token": " How", + "logprob": -0.000054669687, + "bytes": [32, 72, 111, 119], + "top_logprobs": [ + { + "token": " How", + "logprob": -0.000054669687, + "bytes": [32, 72, 111, 119] + }, + { + "token": "<|end|>", + "logprob": -10.953937, + "bytes": null + } + ] + }, + { + "token": " can", + "logprob": -0.015801601, + "bytes": [32, 99, 97, 110], + "top_logprobs": [ + { + "token": " can", + "logprob": -0.015801601, + "bytes": [32, 99, 97, 110] + }, + { + "token": " may", + "logprob": -4.161023, + "bytes": [32, 109, 97, 121] + } + ] + }, + { + "token": " I", + "logprob": -3.7697225e-6, + "bytes": [ + 32, + 73 + ], + "top_logprobs": [ + { + "token": " I", + "logprob": -3.7697225e-6, + "bytes": [32, 73] + }, + { + "token": " assist", + "logprob": -13.596657, + "bytes": [32, 97, 115, 115, 105, 115, 116] + } + ] + }, + { + "token": " assist", + "logprob": -0.04571125, + "bytes": [32, 97, 115, 115, 105, 115, 116], + "top_logprobs": [ + { + "token": " assist", + "logprob": -0.04571125, + "bytes": [32, 97, 115, 115, 105, 115, 116] + }, + { + "token": " help", + "logprob": -3.1089056, + "bytes": [32, 104, 101, 108, 112] + } + ] + }, + { + "token": " you", + "logprob": -5.4385737e-6, + "bytes": [32, 121, 111, 117], + "top_logprobs": [ + { + "token": " you", + "logprob": -5.4385737e-6, + "bytes": [32, 121, 111, 117] + }, + { + "token": " today", + "logprob": -12.807695, + "bytes": [32, 116, 111, 100, 97, 121] + } + ] + }, + { + "token": " today", + "logprob": -0.0040071653, + "bytes": [32, 116, 111, 100, 97, 121], + "top_logprobs": [ + { + "token": " today", + "logprob": -0.0040071653, + "bytes": [32, 116, 111, 100, 97, 121] + }, + { + "token": "?", + "logprob": -5.5247097, + "bytes": [63] + } + ] + }, + { + "token": "?", + "logprob": -0.0008108172, + "bytes": [63], + "top_logprobs": [ + { + "token": "?", + "logprob": -0.0008108172, + "bytes": [63] + }, + { + "token": "?\n", + "logprob": -7.184561, + "bytes": [63, 10] + } + ] + } + ] + } + }, + "schema": { + "properties": { + "logprobs": { + "type": "object", + "description": "A logprobs object in the same format as OpenAI API." + } + } + } + } + }, + "description": "Successful request" + } + }, + "summary": "Obtains the token logprobs of the most recent request.", + "tags": [ + "api/extra" + ] + } + }, "/api/extra/tokencount": { "post": { "description": "Counts the number of tokens in a string.", diff --git a/klite.embd b/klite.embd index b3fa6e0a0cdfc..ab7faf382ae6d 100644 --- a/klite.embd +++ b/klite.embd @@ -12,7 +12,7 @@ Current version indicated by LITEVER below. -->