Skip to content

Commit d8a20c2

Browse files
README - Update token count example
1 parent 83d89a9 commit d8a20c2

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ For this to work you need to use `OpenAIServiceStreamedFactory` from `openai-sca
363363
}
364364
```
365365

366-
- 🔥 **New**: Count expected used tokens before calling `createChatCompletions` or `createChatFunCompletions`, this help you select proper model ex. `gpt-3.5-turbo` or `gpt-3.5-turbo-16k` and reduce costs. This is an experimental feature and it may not work for all models. Requires `openai-scala-count-tokens` lib.
366+
- 🔥 **New**: Count expected used tokens before calling `createChatCompletions` or `createChatFunCompletions`, this helps you select proper model ex. `gpt-3.5-turbo` or `gpt-3.5-turbo-16k` and reduce costs. This is an experimental feature and it may not work for all models. Requires `openai-scala-count-tokens` lib.
367367

368368
```scala
369369
import io.cequence.openaiscala.service.OpenAICountTokensHelper
@@ -372,7 +372,20 @@ import io.cequence.openaiscala.domain.{ChatRole, FunMessageSpec, FunctionSpec}
372372
class MyCompletionService extends OpenAICountTokensHelper {
373373
def exec = {
374374
val messages: Seq[FunMessageSpec] = ??? // messages to be sent to OpenAI
375-
val function: FunctionSpec = ??? // function to be called
375+
// function to be called
376+
val function: FunctionSpec = FunctionSpec(
377+
name = "getWeather",
378+
parameters = Map(
379+
"type" -> "object",
380+
"properties" -> ListMap(
381+
"location" -> ListMap(
382+
"type" -> "string",
383+
"description" -> "The city to get the weather for"
384+
),
385+
"unit" -> ListMap("type" -> "string", "enum" -> List("celsius", "fahrenheit"))
386+
)
387+
)
388+
)
376389

377390
val tokens = countFunMessageTokens(model, messages, Seq(function), Some(function.name))
378391
}

0 commit comments

Comments
 (0)