|
1 | 1 | package io.cequence.openaiscala.service.adapter
|
2 | 2 |
|
| 3 | +import io.cequence.openaiscala.domain.NonOpenAIModelId |
3 | 4 | import io.cequence.openaiscala.domain.settings.{
|
4 | 5 | ChatCompletionResponseFormatType,
|
5 | 6 | CreateChatCompletionSettings
|
6 | 7 | }
|
| 8 | +import io.cequence.openaiscala.domain.settings.GroqCreateChatCompletionSettingsOps._ |
7 | 9 | import org.slf4j.LoggerFactory
|
8 | 10 |
|
9 | 11 | object ChatCompletionSettingsConversions {
|
@@ -107,4 +109,42 @@ object ChatCompletionSettingsConversions {
|
107 | 109 | val o1: SettingsConversion = generic(o1BaseConversions)
|
108 | 110 |
|
109 | 111 | val o1Preview: SettingsConversion = generic(o1PreviewConversions)
|
| 112 | + |
| 113 | + private lazy val groqConversions = Seq( |
| 114 | + // max tokens |
| 115 | + FieldConversionDef( |
| 116 | + settings => |
| 117 | + settings.model.endsWith( |
| 118 | + NonOpenAIModelId.deepseek_r1_distill_llama_70b |
| 119 | + ) && settings.max_tokens.isDefined, |
| 120 | + settings => |
| 121 | + settings.copy(max_tokens = None).setMaxCompletionTokens(settings.max_tokens.get), |
| 122 | + Some( |
| 123 | + "Groq deepseek R1 model doesn't support max_tokens, converting to max_completion_tokens." |
| 124 | + ) |
| 125 | + ), |
| 126 | + // json mode |
| 127 | + FieldConversionDef( |
| 128 | + settings => |
| 129 | + settings.model.endsWith( |
| 130 | + NonOpenAIModelId.deepseek_r1_distill_llama_70b |
| 131 | + ) && (settings.response_format_type.contains( |
| 132 | + ChatCompletionResponseFormatType.json_object |
| 133 | + ) || settings.response_format_type |
| 134 | + .contains(ChatCompletionResponseFormatType.json_schema)), |
| 135 | + settings => settings.copy(response_format_type = None).setJsonMode(true), |
| 136 | + Some( |
| 137 | + "Groq deepseek R1 model doesn't support the json schema / object response format type, converting it to json_mode flag instead." |
| 138 | + ) |
| 139 | + ) |
| 140 | + ) |
| 141 | + |
| 142 | + def groq( |
| 143 | + reasoningFormat: Option[ReasoningFormat] = None |
| 144 | + ): SettingsConversion = { |
| 145 | + val conversions = generic(groqConversions) |
| 146 | + reasoningFormat |
| 147 | + .map(reasoningFormat => conversions.andThen(_.setReasoningFormat(reasoningFormat))) |
| 148 | + .getOrElse(conversions) |
| 149 | + } |
110 | 150 | }
|
0 commit comments