Skip to content

Commit

Permalink
feat: add support for assistant temperature and top_p (#788)
Browse files Browse the repository at this point in the history
  • Loading branch information
realdavidvega authored Sep 12, 2024
1 parent f51bbb3 commit 0d2574c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class Assistant(
tools: List<AssistantObjectToolsInner> = arrayListOf(),
toolResources: CreateAssistantRequestToolResources? = null,
metadata: JsonObject? = null,
temperature: Double? = null,
topP: Double? = null,
toolsConfig: List<Tool.Companion.ToolConfig<*, *>> = emptyList(),
config: Config = Config(),
assistantsApi: Assistants = OpenAI(config, logRequests = false).assistants,
Expand All @@ -110,7 +112,9 @@ class Assistant(
instructions = instructions,
tools = tools,
toolResources = toolResources,
metadata = metadata
metadata = metadata,
temperature = temperature,
topP = topP
),
toolsConfig,
config,
Expand Down Expand Up @@ -195,6 +199,8 @@ class Assistant(
}
},
toolResources = toolResourcesRequest,
temperature = parsed["temperature"]?.literalContentOrNull?.toDoubleOrNull(),
topP = parsed["top_p"]?.literalContentOrNull?.toDoubleOrNull(),
)
return if (assistantRequest.assistantId != null) {
val assistant =
Expand Down Expand Up @@ -225,7 +231,9 @@ class Assistant(
)
)
},
metadata = null // assistantRequest.metadata
metadata = null, // assistantRequest.metadata
temperature = assistantRequest.temperature,
topP = assistantRequest.topP
)
)
} else
Expand All @@ -241,7 +249,9 @@ class Assistant(
metadata =
assistantRequest.metadata
?.map { (k, v) -> k to JsonPrimitive(v) }
?.let { JsonObject(it.toMap()) }
?.let { JsonObject(it.toMap()) },
temperature = assistantRequest.temperature,
topP = assistantRequest.topP
),
toolsConfig = toolsConfig,
config = config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,42 @@ data class AssistantRequest(
@SerialName(value = "assistant_id") val assistantId: String? = null,
@SerialName(value = "model") @Required val model: CreateAssistantRequestModel,

/* The name of the assistant. The maximum length is 256 characters. */
/** The name of the assistant. The maximum length is 256 characters. */
@SerialName(value = "name") val name: String? = null,

/* The description of the assistant. The maximum length is 512 characters. */
/** The description of the assistant. The maximum length is 512 characters. */
@SerialName(value = "description") val description: String? = null,

/* The system instructions that the assistant uses. The maximum length is 32768 characters. */
/** The system instructions that the assistant uses. The maximum length is 32768 characters. */
@SerialName(value = "instructions") val instructions: String? = null,

/* A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types `code_interpreter`, `retrieval`, or `function`. */
/**
* A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant.
* Tools can be of types `code_interpreter`, `retrieval`, or `function`.
*/
@SerialName(value = "tools") val tools: List<AssistantTool>? = arrayListOf(),
@SerialName(value = "tool_resources")
val toolResources: CreateAssistantRequestToolResources? = null,

/* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. */
@SerialName(value = "metadata") val metadata: Map<String, String>? = null
/**
* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing
* additional information about the object in a structured format. Keys can be a maximum of 64
* characters long and values can be a maxium of 512 characters long.
*/
@SerialName(value = "metadata") val metadata: Map<String, String>? = null,

/**
* What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output
* more random, while lower values like 0.2 will make it more focused and deterministic.
*/
@SerialName(value = "temperature") val temperature: Double? = null,

/**
* An alternative to sampling with temperature, called nucleus sampling, where the model considers
* the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising
* the top 10% probability mass are considered.
*/
@SerialName(value = "top_p") val topP: Double? = null,
)

@Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.xebia.functional.xef.assistants

import com.xebia.functional.xef.llm.assistants.*
import com.xebia.functional.xef.llm.assistants.Assistant
import com.xebia.functional.xef.llm.assistants.AssistantThread
import com.xebia.functional.xef.llm.assistants.MessageWithFiles
import com.xebia.functional.xef.llm.assistants.RunDelta
import com.xebia.functional.xef.llm.assistants.Tool

suspend fun main() {
// val filesApi = fromEnvironment(::FilesApi)
Expand Down Expand Up @@ -34,6 +38,8 @@ suspend fun main() {
use_case: "Customer support"
language: "English"
additional_info: "This assistant is continuously updated with the latest information."
temperature: "0.0"
top_p: "1.0"
"""
.trimIndent()
val tools = listOf(Tool.toolOf(SumTool()))
Expand Down

0 comments on commit 0d2574c

Please sign in to comment.