-
Notifications
You must be signed in to change notification settings - Fork 14
feat: enhance model configuration support #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: enhance model configuration support #9
Conversation
LGTM. I'll review it in several days. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would agree that the idea to support a more detailed configuration is good, but we need backward compatiblility and make most of the configuration things default.
I think a little more hacky way is good: define a custom serializer to accept both plain model name and ModelConfig block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is too much dumplicate code.
Most of the parameters can be put in the ChatCompletionRequest
instance, and we don't need to log for every modification..
|
||
suspend fun createStreamingChatCompletion( | ||
baseUrl: String, | ||
apiKey: String, | ||
request: ChatCompletionRequest | ||
request: ChatCompletionRequest, | ||
extraTopLevelParams: Map<String, JsonElement>? = null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we need a ChatCompletionRequest
with more fields, we can just add a nullable property to it.
If we need to add more field into a JSON request, we can just create a Merge<A, B>
class and define special serialization strategy for it.
|
||
/** | ||
* Convert a string value to the appropriate JsonElement type. | ||
* It tries to parse as a JSON object/array first, then falls back to primitive types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We know YAML is compatible with JSON. So just let users write YAML in the config and we can transform it into JSON easily.
@alexzeitgeist I suggest you to take a look at kaml. This repository uses it to parse YAML config, and we can do some more flexible parsing by hacking its implementation. For polymorphism serialization, you can refer to kotlinx.serialization.json.JsonContentPolymorphicSerializer. |
For config format design, I hope it to be like this: OpenAI:
type: OpenAi
baseUrl: ...
modelList:
- modelWithSimpleDeclaration
- modelWithParameter:
parameterA: value
parameterB: value
additionalRequestBody:
fieldA: value This may be more natural, with a optional parameter block. |
I think your idea is great. If you need help, I would like to work with you on this |
Enhanced model configuration support
Overview
Replace simple string-based model lists with a more comprehensive
ModelConfig
system. This allows fine-grained control over model behavior through per-model configuration of parameters.FWIW: JetBrains AI Assistant always sends temperature=1.0, which is too high for most non-reasoning models. Which is why I think this configuration is important. 😊
Breaking Changes
modelList: ["gpt-4", "gpt-3.5-turbo"]
modelList: [{ name: "gpt-4" }, { name: "gpt-3.5-turbo" }]
New Features
1. ModelConfig Data Class
Added
ModelConfig.kt
with support for:name
: Model identifier (required)temperature
: Override default temperature for specific modelsextraParameters
: Top-level API parameters to include in requestsextraBody
: Additional parameters to merge into request body2. Enhanced Parameter Handling
The OpenAI client now processes model configurations:
Supported Extra Parameters:
max_tokens
: Maximum tokens in responsetop_p
: Nucleus sampling parameterfrequency_penalty
: Token frequency penaltypresence_penalty
: Token presence penaltystop
: Stop sequences (string or array)seed
: Random seed for deterministic outputn
: Number of completions to generateUnknown parameters are passed as top-level JSON elements to support provider-specific features.
3. Example Configuration