-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathCreateChatFunCompletion.scala
56 lines (49 loc) · 1.72 KB
/
CreateChatFunCompletion.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package io.cequence.openaiscala.examples
import io.cequence.openaiscala.domain.AssistantTool.FunctionTool
import io.cequence.openaiscala.domain.{BaseMessage, UserMessage}
import scala.concurrent.Future
object CreateChatFunCompletion extends Example {
val messages: Seq[BaseMessage] = Seq(
UserMessage("What's the weather like in Boston?")
)
// as a param type we can use "number", "string", "boolean", "object", "array", and "null"
val functions: Seq[FunctionTool] = Seq(
FunctionTool(
name = "get_current_weather",
description = Some("Get the current weather in a given location"),
parameters = Map(
"type" -> "object",
"properties" -> Map(
"location" -> Map(
"type" -> "string",
"description" -> "The city and state, e.g. San Francisco, CA"
),
"unit" -> Map(
"type" -> "string",
"enum" -> Seq("celsius", "fahrenheit")
)
),
"required" -> Seq("location")
)
)
)
def run: Future[Unit] =
// if we want to force the model to use the above function as a response
// we can do so by passing: responseFunctionName = Some("get_current_weather")`
service
.createChatFunCompletion(
messages = messages,
functions = functions,
responseFunctionName = None
)
.map { response =>
val chatFunCompletionMessage = response.choices.head.message
val functionCall = chatFunCompletionMessage.function_call
println(
"function call name : " + functionCall.map(_.name).getOrElse("N/A")
)
println(
"function call arguments : " + functionCall.map(_.arguments).getOrElse("N/A")
)
}
}