Skip to content

Commit 3493033

Browse files
authored
1.1.13 (#89)
* rm logs * Update ChatModel.kt * tmp * 1.1.13 * deepseek
1 parent bcaaf69 commit 3493033

File tree

8 files changed

+53
-93
lines changed

8 files changed

+53
-93
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Gradle Releases -> https://github.com/gradle/gradle/releases
22
libraryGroup=com.simiacryptus
3-
libraryVersion=1.1.12
3+
libraryVersion=1.1.13
44
gradleVersion=7.6.1
55
kotlin.daemon.jvmargs=-Xmx4g

src/main/kotlin/com/simiacryptus/jopenai/ChatClient.kt

Lines changed: 11 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,17 @@ open class ChatClient(
135135
return post(request)
136136
}
137137

138-
private fun post(request: HttpPost): String = withClient { EntityUtils.toString(it.execute(request).entity) }
138+
private fun post(request: HttpPost): String = withClient {
139+
log(
140+
level = Level.DEBUG,
141+
msg = String.format(
142+
"POST %s\nPrefix:\n\t%s\n",
143+
request.uri,
144+
EntityUtils.toString(request.entity).replace("\n", "\n\t")
145+
)
146+
)
147+
EntityUtils.toString(it.execute(request).entity)
148+
}
139149

140150
@Throws(IOException::class)
141151
protected open fun authorize(request: HttpRequest, apiProvider: APIProvider) {
@@ -202,14 +212,6 @@ open class ChatClient(
202212
}), model)
203213
val json = JsonUtil.objectMapper().writerWithDefaultPrettyPrinter()
204214
.writeValueAsString(geminiChatRequest)
205-
log(
206-
level = Level.DEBUG,
207-
msg = String.format(
208-
"Chat Request %s\nPrefix:\n\t%s\n",
209-
requestID,
210-
json.replace("\n", "\n\t")
211-
)
212-
)
213215
fromGemini(
214216
post(
215217
"${apiBase[apiProvider]}/v1beta/${model.modelName}:generateContent?key=${key[apiProvider]}",
@@ -223,14 +225,6 @@ open class ChatClient(
223225
val anthropicChatRequest = mapToAnthropicChatRequest(chatRequest, model)
224226
val json = JsonUtil.objectMapper().writerWithDefaultPrettyPrinter()
225227
.writeValueAsString(anthropicChatRequest)
226-
log(
227-
level = Level.DEBUG,
228-
msg = String.format(
229-
"Chat Request %s\nPrefix:\n\t%s\n",
230-
requestID,
231-
json.replace("\n", "\n\t")
232-
)
233-
)
234228
val request = HttpPost("${apiBase[apiProvider]}/messages")
235229
request.addHeader("Content-Type", "application/json")
236230
request.addHeader("Accept", "application/json")
@@ -245,42 +239,18 @@ open class ChatClient(
245239
val json =
246240
JsonUtil.objectMapper().writerWithDefaultPrettyPrinter()
247241
.writeValueAsString(chatRequest.copy(stop = null))
248-
log(
249-
level = Level.DEBUG,
250-
msg = String.format(
251-
"Chat Request %s\nPrefix:\n\t%s\n",
252-
requestID,
253-
json.replace("\n", "\n\t")
254-
)
255-
)
256242
post("${apiBase[apiProvider]}/chat/completions", json, apiProvider)
257243
}
258244

259245
apiProvider == APIProvider.Mistral -> {
260246
val json = JsonUtil.objectMapper().writerWithDefaultPrettyPrinter()
261247
.writeValueAsString(toGroq(chatRequest))
262-
log(
263-
level = Level.DEBUG,
264-
msg = String.format(
265-
"Chat Request %s\nPrefix:\n\t%s\n",
266-
requestID,
267-
json.replace("\n", "\n\t")
268-
)
269-
)
270248
post("${apiBase[apiProvider]}/chat/completions", json, apiProvider)
271249
}
272250

273251
apiProvider == APIProvider.Groq -> {
274252
val json = JsonUtil.objectMapper().writerWithDefaultPrettyPrinter()
275253
.writeValueAsString(toGroq(chatRequest))
276-
log(
277-
level = Level.DEBUG,
278-
msg = String.format(
279-
"Chat Request %s\nPrefix:\n\t%s\n",
280-
requestID,
281-
json.replace("\n", "\n\t")
282-
)
283-
)
284254
post("${apiBase[apiProvider]}/chat/completions", json, apiProvider)
285255
}
286256

@@ -289,14 +259,6 @@ open class ChatClient(
289259
val json =
290260
JsonUtil.objectMapper().writerWithDefaultPrettyPrinter()
291261
.writeValueAsString(toModelsLab(chatRequest))
292-
log(
293-
level = Level.DEBUG,
294-
msg = String.format(
295-
"Chat Request %s\nPrefix:\n\t%s\n",
296-
requestID,
297-
json.replace("\n", "\n\t")
298-
)
299-
)
300262
fromModelsLab(post("${apiBase[apiProvider]}/llm/chat", json, apiProvider))
301263
}
302264
}
@@ -308,13 +270,6 @@ open class ChatClient(
308270
.credentialsProvider(awsCredentials(awsAuth))
309271
.region(Region.of(awsAuth.region))
310272
.build()
311-
log(
312-
level = Level.DEBUG,
313-
msg = String.format(
314-
"Chat Request %s\nPrefix:\n\t%s\n",
315-
requestID, JsonUtil.toJson(chatRequest).replace("\n", "\n\t")
316-
)
317-
)
318273
val invokeModelResponse = bedrockRuntimeClient
319274
.invokeModel(invokeModelRequest)
320275
val responseBody = invokeModelResponse.body().asString(Charsets.UTF_8)
@@ -324,14 +279,6 @@ open class ChatClient(
324279
else -> {
325280
val json =
326281
JsonUtil.objectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(chatRequest)
327-
log(
328-
level = Level.DEBUG,
329-
msg = String.format(
330-
"Chat Request %s\nPrefix:\n\t%s\n",
331-
requestID,
332-
json.replace("\n", "\n\t")
333-
)
334-
)
335282
post("${apiBase[apiProvider]}/chat/completions", json, apiProvider)
336283
}
337284
}

src/main/kotlin/com/simiacryptus/jopenai/models/APIProvider.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class APIProvider private constructor(name: String, val base: String? = null) :
2222
val Perplexity = APIProvider("Perplexity", "https://api.perplexity.ai")
2323
val ModelsLab = APIProvider("ModelsLab", "https://modelslab.com/api/v6")
2424
val Mistral = APIProvider("Mistral", "https://api.mistral.ai/v1")
25+
val DeepSeek = APIProvider("DeepSeek", "https://api.deepseek.com")
2526

2627
init {
2728
logger.info("Registering API providers")
@@ -33,6 +34,7 @@ class APIProvider private constructor(name: String, val base: String? = null) :
3334
register(APIProvider::class.java, Perplexity)
3435
register(APIProvider::class.java, ModelsLab)
3536
register(APIProvider::class.java, Mistral)
37+
register(APIProvider::class.java, DeepSeek)
3638
}
3739

3840
@JvmStatic

src/main/kotlin/com/simiacryptus/jopenai/models/AnthropicModels.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ object AnthropicModels {
44

55
val Claude35Sonnet = ChatModel(
66
name = "AnthropicClaude35Sonnet",
7-
modelName = "claude-3-5-sonnet-20240620",
7+
modelName = "claude-3-5-sonnet-latest",
88
maxTotalTokens = 200000,
99
maxOutTokens = 4096,
1010
provider = APIProvider.Anthropic,
1111
inputTokenPricePerK = 3.0 / 1000.0,
1212
outputTokenPricePerK = 15.0 / 1000.0
1313
)
14-
val Claude35Sonnet_2 = ChatModel(
15-
name = "AnthropicClaude35Sonnet_2",
16-
modelName = "claude-3-5-sonnet-20241022",
14+
val Claude35Haiku = ChatModel(
15+
name = "Claude3Haiku",
16+
modelName = "claude-3-5-haiku-latest",
1717
maxTotalTokens = 200000,
1818
maxOutTokens = 4096,
1919
provider = APIProvider.Anthropic,
20-
inputTokenPricePerK = 3.0 / 1000.0,
21-
outputTokenPricePerK = 15.0 / 1000.0
20+
inputTokenPricePerK = 15.0 / 1000.0,
21+
outputTokenPricePerK = 75.0 / 1000.0
2222
)
2323
val Claude3Opus = ChatModel(
2424
name = "Claude3Opus",

src/main/kotlin/com/simiacryptus/jopenai/models/ChatModel.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,12 @@ open class ChatModel(
135135

136136
"AnthropicClaude3Opus" to AnthropicModels.Claude3Opus,
137137
"AnthropicClaude35Sonnet" to AnthropicModels.Claude35Sonnet,
138-
"AnthropicClaude35Sonnet_2" to AnthropicModels.Claude35Sonnet_2,
138+
"AnthropicClaude35Haiku" to AnthropicModels.Claude35Haiku,
139139
"AnthropicClaude3Sonnet" to AnthropicModels.Claude3Sonnet,
140140
"AnthropicClaude3Haiku" to AnthropicModels.Claude3Haiku,
141141

142+
"DeepSeekChat" to DeepSeekModels.DeepSeekChat,
143+
"DeepSeekCoder" to DeepSeekModels.DeepSeekCoder,
142144

143145
"GeminiPro_15" to GoogleModels.GeminiPro_15,
144146
"GeminiFlash_15" to GoogleModels.GeminiFlash_15,
@@ -163,4 +165,8 @@ class ChatModelsDeserializer : JsonDeserializer<ChatModel>() {
163165
logger.debug("Deserializing ChatModel with name: {}", modelName)
164166
return values()[modelName] ?: throw IllegalArgumentException("Unknown model name: $modelName")
165167
}
166-
}
168+
}
169+
170+
fun String.chatModel() = values().entries.find {
171+
it.key.equals(this, true) || it.value.modelName.equals(this, true)
172+
}?.value ?: throw IllegalArgumentException("Unknown model: $this")
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.simiacryptus.jopenai.models
2+
3+
object DeepSeekModels {
4+
val DeepSeekChat = ChatModel(
5+
name = "DeepSeekChat",
6+
modelName = "deepseek-chat",
7+
maxTotalTokens = 64000,
8+
maxOutTokens = 4096,
9+
provider = APIProvider.DeepSeek,
10+
inputTokenPricePerK = 0.014 / 1000.0,
11+
outputTokenPricePerK = 0.14 / 1000.0
12+
)
13+
val DeepSeekCoder = ChatModel(
14+
name = "DeepSeekCoder",
15+
modelName = "deepseek-coder",
16+
maxTotalTokens = 64000,
17+
maxOutTokens = 4096,
18+
provider = APIProvider.DeepSeek,
19+
inputTokenPricePerK = 0.014 / 1000.0,
20+
outputTokenPricePerK = 0.14 / 1000.0
21+
)
22+
}

src/main/kotlin/com/simiacryptus/jopenai/models/chatModel.kt

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/main/kotlin/com/simiacryptus/util/JsonUtil.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ object JsonUtil {
5959
}
6060

6161
open fun toJson(data: Any): String {
62-
log.debug("Serializing object to JSON: {}", data)
62+
// log.debug("Serializing object to JSON: {}", data)
6363
return objectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(data)
6464
}
6565

6666
open fun <T> fromJson(data: String, type: Type): T {
67-
log.debug("Deserializing JSON to object of type: {}", type)
67+
// log.debug("Deserializing JSON to object of type: {}", type)
6868
if (type is Class<*> && type.isAssignableFrom(String::class.java)) return data as T
6969
val objectMapper = objectMapper()
7070
val value = objectMapper.readValue(data, objectMapper.typeFactory.constructType(type)) as T
71-
log.info("Deserialized JSON to object: {}", value)
71+
// log.info("Deserialized JSON to object: {}", value)
7272
return value
7373
}
7474
// companion object : JsonUtil()

0 commit comments

Comments
 (0)