Skip to content

Commit 806ffb0

Browse files
author
michal.zyga
committed
add properties to translation & assistant API
1 parent 3ffae34 commit 806ffb0

File tree

6 files changed

+72
-37
lines changed

6 files changed

+72
-37
lines changed

core/src/main/scala/sttp/openai/OpenAI.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,8 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
463463
Some(multipart("model", model.value)),
464464
prompt.map(multipart("prompt", _)),
465465
responseFormat.map(format => multipart("response_format", format)),
466-
temperature.map(multipart("temperature", _))
466+
temperature.map(multipart("temperature", _)),
467+
language.map(multipart("language", _))
467468
).flatten
468469
}
469470
.response(asJson_parseErrors[AudioResponse])

core/src/main/scala/sttp/openai/requests/assistants/AssistantsRequestBody.scala

+47-12
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,31 @@ object AssistantsRequestBody {
88
/** @param model
99
* ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for
1010
* descriptions of them.
11-
*
1211
* @param name
1312
* The name of the assistant. The maximum length is 256 characters.
14-
*
1513
* @param description
1614
* The description of the assistant. The maximum length is 512 characters.
17-
*
1815
* @param instructions
1916
* The system instructions that the assistant uses. The maximum length is 32768 characters.
20-
*
17+
* @param reasoningEffort
18+
* o1 and o3-mini models only Constrains effort on reasoning for reasoning models. Currently supported values are low, medium, and
19+
* high. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.
2120
* @param tools
2221
* 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,
2322
* file_search, or function.
24-
*
2523
* @param toolResources
2624
* A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the
2725
* code_interpreter tool requires a list of file IDs, while the file_search tool requires a list of vector store IDs.
28-
*
2926
* @param metadata
3027
* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object
3128
* in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long.
29+
* @param temperature
30+
* What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like
31+
* 0.2 will make it more focused and deterministic.
32+
* @param topP
33+
* An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p
34+
* probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend
35+
* altering this or temperature but not both.
3236
*
3337
* For more information please visit: [[https://platform.openai.com/docs/api-reference/assistants/createAssistant]]
3438
*/
@@ -37,9 +41,12 @@ object AssistantsRequestBody {
3741
name: Option[String] = None,
3842
description: Option[String] = None,
3943
instructions: Option[String] = None,
44+
reasoningEffort: Option[ReasoningEffort] = None,
4045
tools: Seq[Tool] = Seq.empty,
4146
toolResources: Option[ToolResources] = None,
42-
metadata: Option[Map[String, String]] = None
47+
metadata: Option[Map[String, String]] = None,
48+
temperature: Option[Float] = None,
49+
topP: Option[Float] = None
4350
)
4451
object CreateAssistantBody {
4552
implicit val createAssistantBodyW: SnakePickle.Writer[CreateAssistantBody] = SnakePickle.macroW[CreateAssistantBody]
@@ -48,26 +55,33 @@ object AssistantsRequestBody {
4855
/** @param model
4956
* ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for
5057
* descriptions of them.
51-
*
5258
* @param name
5359
* The name of the assistant. The maximum length is 256 characters.
54-
*
5560
* @param description
5661
* The description of the assistant. The maximum length is 512 characters.
57-
*
5862
* @param instructions
5963
* The system instructions that the assistant uses. The maximum length is 32768 characters.
64+
* @param reasoningEffort
65+
* o1 and o3-mini models only
6066
*
67+
* Constrains effort on reasoning for reasoning models. Currently supported values are low, medium, and high. Reducing reasoning effort
68+
* can result in faster responses and fewer tokens used on reasoning in a response.
6169
* @param tools
6270
* 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,
6371
* file_search, or function.
64-
*
6572
* @param toolResources
6673
* A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the
6774
* code_interpreter tool requires a list of file IDs, while the file_search tool requires a list of vector store IDs. v
6875
* @param metadata
6976
* Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object
7077
* in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long.
78+
* @param temperature
79+
* What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like
80+
* 0.2 will make it more focused and deterministic.
81+
* @param topP
82+
* An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p
83+
* probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend
84+
* altering this or temperature but not both.
7185
*
7286
* For more information please visit: [[https://platform.openai.com/docs/api-reference/assistants/modifyAssistant]]
7387
*/
@@ -76,12 +90,33 @@ object AssistantsRequestBody {
7690
name: Option[String] = None,
7791
description: Option[String] = None,
7892
instructions: Option[String] = None,
93+
reasoningEffort: Option[ReasoningEffort] = None,
7994
tools: Seq[Tool] = Seq.empty,
8095
toolResources: Option[ToolResources] = None,
81-
metadata: Map[String, String] = Map.empty
96+
metadata: Map[String, String] = Map.empty,
97+
temperature: Option[Float] = None,
98+
topP: Option[Float] = None
8299
)
83100

84101
object ModifyAssistantBody {
85102
implicit val modifyAssistantBodyW: SnakePickle.Writer[ModifyAssistantBody] = SnakePickle.macroW[ModifyAssistantBody]
86103
}
87104
}
105+
106+
sealed abstract class ReasoningEffort(val value: String)
107+
108+
object ReasoningEffort {
109+
110+
implicit val reasoningEffortW: SnakePickle.Writer[ReasoningEffort] = SnakePickle
111+
.writer[ujson.Value]
112+
.comap[ReasoningEffort](reasoningEffort => SnakePickle.writeJs(reasoningEffort.value))
113+
114+
case object Low extends ReasoningEffort("low")
115+
116+
case object Medium extends ReasoningEffort("medium")
117+
118+
case object High extends ReasoningEffort("high")
119+
120+
case class CustomReasoningEffort(customReasoningEffort: String) extends ReasoningEffort(customReasoningEffort)
121+
122+
}

core/src/main/scala/sttp/openai/requests/audio/translations/TranslationConfig.scala

+4-19
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import sttp.openai.requests.audio.RecognitionModel
44
import sttp.openai.requests.images.ResponseFormat
55

66
import java.io.File
7-
import java.nio.file.Paths
87

98
/** @param file
109
* The audio file to translate, in one of these formats: mp3, mp4, mpeg, mpga, m4a, wav, or webm.
@@ -18,28 +17,14 @@ import java.nio.file.Paths
1817
* The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will
1918
* make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature
2019
* until certain thresholds are hit.
20+
* @param language
21+
* The language of the input audio. Supplying the input language in ISO-639-1 (e.g. en) format will improve accuracy and latency.
2122
*/
2223
case class TranslationConfig(
2324
file: File,
2425
model: RecognitionModel,
2526
prompt: Option[String] = None,
2627
responseFormat: Option[ResponseFormat] = None,
27-
temperature: Option[Float] = None
28+
temperature: Option[Float] = None,
29+
language: Option[String] = None
2830
)
29-
30-
object TranslationConfig {
31-
def createTranslationConfigWithSystemPaths(
32-
systemPath: String,
33-
model: RecognitionModel,
34-
prompt: Option[String] = None,
35-
responseFormat: Option[ResponseFormat] = None,
36-
temperature: Option[Float] = None
37-
): TranslationConfig =
38-
TranslationConfig(
39-
Paths.get(systemPath).toFile,
40-
model,
41-
prompt,
42-
responseFormat,
43-
temperature
44-
)
45-
}

core/src/main/scala/sttp/openai/requests/embeddings/EmbeddingsRequestBody.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ object EmbeddingsRequestBody {
1212
* Input text to get embeddings for, encoded as a string or array of tokens.
1313
* @param user
1414
* A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
15+
* @param dimensions
16+
* The number of dimensions for the embeddings. Only supported in text-embedding-3 and later models.
1517
*/
16-
case class EmbeddingsBody(model: EmbeddingsModel, input: EmbeddingsInput, user: Option[String] = None)
18+
case class EmbeddingsBody(model: EmbeddingsModel, input: EmbeddingsInput, user: Option[String] = None, dimensions: Option[Int] = None)
1719

1820
object EmbeddingsBody {
1921
implicit val embeddingsBodyWriter: SnakePickle.Writer[EmbeddingsBody] = SnakePickle.macroW

core/src/test/scala/sttp/openai/fixtures/AssistantsFixture.scala

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ object AssistantsFixture {
77
| "instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
88
| "name": "Math Tutor",
99
| "tools": [{"type": "code_interpreter"}],
10-
| "model": "gpt-4"
10+
| "model": "gpt-4",
11+
| "reasoning_effort": "low",
12+
| "temperature": 1.0,
13+
| "top_p": 1.0
1114
|}""".stripMargin
1215

1316
val jsonCreateAssistantResponse: String =
@@ -113,7 +116,10 @@ object AssistantsFixture {
113116
| "file_search": {
114117
| "vector_store_ids": ["vs_1", "vs_3"]
115118
| }
116-
| }
119+
| },
120+
| "reasoning_effort": "low",
121+
| "temperature": 1.0,
122+
| "top_p": 1.0
117123
|}
118124
|""".stripMargin
119125

core/src/test/scala/sttp/openai/requests/assistants/AssistantsDataSpec.scala

+8-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ class AssistantsDataSpec extends AnyFlatSpec with Matchers with EitherValues {
2020
instructions = Some("You are a personal math tutor. When asked a question, write and run Python code to answer the question."),
2121
name = Some("Math Tutor"),
2222
tools = Seq(CodeInterpreterTool),
23-
model = "gpt-4"
23+
model = "gpt-4",
24+
reasoningEffort = Some(ReasoningEffort.Low),
25+
temperature = Some(1.0f),
26+
topP = Some(1.0f)
2427
)
2528

2629
val jsonRequest: ujson.Value = ujson.read(fixtures.AssistantsFixture.jsonCreateAssistantRequest)
@@ -213,7 +216,10 @@ class AssistantsDataSpec extends AnyFlatSpec with Matchers with EitherValues {
213216
),
214217
tools = Seq(FileSearchTool),
215218
model = Some("gpt-4"),
216-
toolResources = Some(ToolResources(None, Some(FileSearchToolResource(Some(Seq("vs_1", "vs_3"))))))
219+
toolResources = Some(ToolResources(None, Some(FileSearchToolResource(Some(Seq("vs_1", "vs_3")))))),
220+
reasoningEffort = Some(ReasoningEffort.Low),
221+
temperature = Some(1.0f),
222+
topP = Some(1.0f)
217223
)
218224

219225
val jsonRequest: ujson.Value = ujson.read(fixtures.AssistantsFixture.jsonModifyAssistantRequest)

0 commit comments

Comments
 (0)