AI models: add context length support for Ollama
This commit is contained in:
		
							parent
							
								
									5c7f20a151
								
							
						
					
					
						commit
						dd6bdcf614
					
				@ -272,6 +272,7 @@ class Langchain4jChatModelConfigurerImpl implements Langchain4jChatModelConfigur
 | 
			
		||||
                .temperature(chatModelConfig.temperature())
 | 
			
		||||
                .topP(chatModelConfig.topP())
 | 
			
		||||
                .topK(chatModelConfig.topK())
 | 
			
		||||
                .numCtx(chatModelConfig.contextLength())
 | 
			
		||||
                .numPredict(chatModelConfig.maxOutputTokens())
 | 
			
		||||
                .timeout(toDuration(chatModelConfig.timeoutSeconds()))
 | 
			
		||||
                .maxRetries(chatModelConfig.maxRetries())
 | 
			
		||||
 | 
			
		||||
@ -33,7 +33,7 @@ public record AmazonBedrockChatModelConfig(
 | 
			
		||||
        @NotBlank String modelId,
 | 
			
		||||
        @PositiveOrZero Double temperature,
 | 
			
		||||
        @Positive @Max(1) Double topP,
 | 
			
		||||
        @Positive Integer maxOutputTokens,
 | 
			
		||||
        Integer maxOutputTokens,
 | 
			
		||||
        @With @Positive Integer timeoutSeconds,
 | 
			
		||||
        @With @PositiveOrZero Integer maxRetries
 | 
			
		||||
) implements AiChatModelConfig<AmazonBedrockChatModelConfig> {
 | 
			
		||||
 | 
			
		||||
@ -34,7 +34,7 @@ public record AnthropicChatModelConfig(
 | 
			
		||||
        @PositiveOrZero Double temperature,
 | 
			
		||||
        @Positive @Max(1) Double topP,
 | 
			
		||||
        @PositiveOrZero Integer topK,
 | 
			
		||||
        @Positive Integer maxOutputTokens,
 | 
			
		||||
        Integer maxOutputTokens,
 | 
			
		||||
        @With @Positive Integer timeoutSeconds,
 | 
			
		||||
        @With @PositiveOrZero Integer maxRetries
 | 
			
		||||
) implements AiChatModelConfig<AnthropicChatModelConfig> {
 | 
			
		||||
 | 
			
		||||
@ -35,7 +35,7 @@ public record AzureOpenAiChatModelConfig(
 | 
			
		||||
        @Positive @Max(1) Double topP,
 | 
			
		||||
        Double frequencyPenalty,
 | 
			
		||||
        Double presencePenalty,
 | 
			
		||||
        @Positive Integer maxOutputTokens,
 | 
			
		||||
        Integer maxOutputTokens,
 | 
			
		||||
        @With @Positive Integer timeoutSeconds,
 | 
			
		||||
        @With @PositiveOrZero Integer maxRetries
 | 
			
		||||
) implements AiChatModelConfig<AzureOpenAiChatModelConfig> {
 | 
			
		||||
 | 
			
		||||
@ -35,7 +35,7 @@ public record GitHubModelsChatModelConfig(
 | 
			
		||||
        @Positive @Max(1) Double topP,
 | 
			
		||||
        Double frequencyPenalty,
 | 
			
		||||
        Double presencePenalty,
 | 
			
		||||
        @Positive Integer maxOutputTokens,
 | 
			
		||||
        Integer maxOutputTokens,
 | 
			
		||||
        @With @Positive Integer timeoutSeconds,
 | 
			
		||||
        @With @PositiveOrZero Integer maxRetries
 | 
			
		||||
) implements AiChatModelConfig<GitHubModelsChatModelConfig> {
 | 
			
		||||
 | 
			
		||||
@ -36,7 +36,7 @@ public record GoogleAiGeminiChatModelConfig(
 | 
			
		||||
        @PositiveOrZero Integer topK,
 | 
			
		||||
        Double frequencyPenalty,
 | 
			
		||||
        Double presencePenalty,
 | 
			
		||||
        @Positive Integer maxOutputTokens,
 | 
			
		||||
        Integer maxOutputTokens,
 | 
			
		||||
        @With @Positive Integer timeoutSeconds,
 | 
			
		||||
        @With @PositiveOrZero Integer maxRetries
 | 
			
		||||
) implements AiChatModelConfig<GoogleAiGeminiChatModelConfig> {
 | 
			
		||||
 | 
			
		||||
@ -36,7 +36,7 @@ public record GoogleVertexAiGeminiChatModelConfig(
 | 
			
		||||
        @PositiveOrZero Integer topK,
 | 
			
		||||
        Double frequencyPenalty,
 | 
			
		||||
        Double presencePenalty,
 | 
			
		||||
        @Positive Integer maxOutputTokens,
 | 
			
		||||
        Integer maxOutputTokens,
 | 
			
		||||
        @With @Positive Integer timeoutSeconds,
 | 
			
		||||
        @With @PositiveOrZero Integer maxRetries
 | 
			
		||||
) implements AiChatModelConfig<GoogleVertexAiGeminiChatModelConfig> {
 | 
			
		||||
 | 
			
		||||
@ -35,7 +35,7 @@ public record MistralAiChatModelConfig(
 | 
			
		||||
        @Positive @Max(1) Double topP,
 | 
			
		||||
        Double frequencyPenalty,
 | 
			
		||||
        Double presencePenalty,
 | 
			
		||||
        @Positive Integer maxOutputTokens,
 | 
			
		||||
        Integer maxOutputTokens,
 | 
			
		||||
        @With @Positive Integer timeoutSeconds,
 | 
			
		||||
        @With @PositiveOrZero Integer maxRetries
 | 
			
		||||
) implements AiChatModelConfig<MistralAiChatModelConfig> {
 | 
			
		||||
 | 
			
		||||
@ -34,7 +34,8 @@ public record OllamaChatModelConfig(
 | 
			
		||||
        @PositiveOrZero Double temperature,
 | 
			
		||||
        @Positive @Max(1) Double topP,
 | 
			
		||||
        @PositiveOrZero Integer topK,
 | 
			
		||||
        @Positive Integer maxOutputTokens,
 | 
			
		||||
        Integer contextLength,
 | 
			
		||||
        Integer maxOutputTokens,
 | 
			
		||||
        @With @Positive Integer timeoutSeconds,
 | 
			
		||||
        @With @PositiveOrZero Integer maxRetries
 | 
			
		||||
) implements AiChatModelConfig<OllamaChatModelConfig> {
 | 
			
		||||
 | 
			
		||||
@ -35,7 +35,7 @@ public record OpenAiChatModelConfig(
 | 
			
		||||
        @Positive @Max(1) Double topP,
 | 
			
		||||
        Double frequencyPenalty,
 | 
			
		||||
        Double presencePenalty,
 | 
			
		||||
        @Positive Integer maxOutputTokens,
 | 
			
		||||
        Integer maxOutputTokens,
 | 
			
		||||
        @With @Positive Integer timeoutSeconds,
 | 
			
		||||
        @With @PositiveOrZero Integer maxRetries
 | 
			
		||||
) implements AiChatModelConfig<OpenAiChatModelConfig> {
 | 
			
		||||
 | 
			
		||||
@ -151,7 +151,7 @@
 | 
			
		||||
              </mat-form-field>
 | 
			
		||||
            }
 | 
			
		||||
            @if (providerFieldsList.includes('baseUrl')) {
 | 
			
		||||
              <mat-form-field class="mat-block flex-1" appearance="outline" subscriptSizing="dynamic">
 | 
			
		||||
              <mat-form-field class="mat-block flex-1" appearance="outline">
 | 
			
		||||
                <mat-label translate>ai-models.baseurl</mat-label>
 | 
			
		||||
                <input required matInput formControlName="baseUrl">
 | 
			
		||||
                <mat-error *ngIf="aiModelForms.get('configuration').get('providerConfig').get('baseUrl').hasError('required')">
 | 
			
		||||
@ -264,15 +264,18 @@
 | 
			
		||||
              </div>
 | 
			
		||||
              <mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
 | 
			
		||||
                <input matInput formControlName="maxOutputTokens"
 | 
			
		||||
                       type="number" min="1" step="1" placeholder="{{ 'ai-models.set' | translate }}">
 | 
			
		||||
                <mat-icon matSuffix
 | 
			
		||||
                          matTooltipPosition="above"
 | 
			
		||||
                          matTooltipClass="tb-error-tooltip"
 | 
			
		||||
                          [matTooltip]="'ai-models.max-output-tokens-min' | translate"
 | 
			
		||||
                          *ngIf="aiModelForms.get('configuration').get('maxOutputTokens').hasError('min')"
 | 
			
		||||
                          class="tb-error">
 | 
			
		||||
                  warning
 | 
			
		||||
                </mat-icon>
 | 
			
		||||
                       type="number" step="1" placeholder="{{ 'ai-models.set' | translate }}">
 | 
			
		||||
              </mat-form-field>
 | 
			
		||||
            </div>
 | 
			
		||||
          }
 | 
			
		||||
          @if (modelFieldsList.includes('contextLength')) {
 | 
			
		||||
            <div class="tb-form-row space-between">
 | 
			
		||||
              <div tb-hint-tooltip-icon="{{ 'ai-models.context-length-hint' | translate }}">
 | 
			
		||||
                {{ 'ai-models.context-length' | translate }}
 | 
			
		||||
              </div>
 | 
			
		||||
              <mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
 | 
			
		||||
                <input matInput formControlName="contextLength"
 | 
			
		||||
                       type="number" step="1" placeholder="{{ 'ai-models.set' | translate }}">
 | 
			
		||||
              </mat-form-field>
 | 
			
		||||
            </div>
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
@ -108,7 +108,8 @@ export class AIModelDialogComponent extends DialogComponent<AIModelDialogCompone
 | 
			
		||||
        topK: [this.data.AIModel ? this.data.AIModel.configuration?.topK : null, [Validators.min(0)]],
 | 
			
		||||
        frequencyPenalty: [this.data.AIModel ? this.data.AIModel.configuration?.frequencyPenalty : null],
 | 
			
		||||
        presencePenalty: [this.data.AIModel ? this.data.AIModel.configuration?.presencePenalty : null],
 | 
			
		||||
        maxOutputTokens: [this.data.AIModel ? this.data.AIModel.configuration?.maxOutputTokens : null, [Validators.min(1)]]
 | 
			
		||||
        maxOutputTokens: [this.data.AIModel ? this.data.AIModel.configuration?.maxOutputTokens : null],
 | 
			
		||||
        contextLength: [this.data.AIModel ? this.data.AIModel.configuration?.contextLength : null]
 | 
			
		||||
      })
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -43,6 +43,7 @@ export interface AiModel extends Omit<BaseData<AiModelId>, 'label'>, HasTenantId
 | 
			
		||||
    frequencyPenalty?: number;
 | 
			
		||||
    presencePenalty?: number;
 | 
			
		||||
    maxOutputTokens?: number;
 | 
			
		||||
    contextLength?: number;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -91,7 +92,7 @@ export const ProviderFieldsAllList = [
 | 
			
		||||
  'baseUrl'
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
export const ModelFieldsAllList = ['temperature', 'topP', 'topK', 'frequencyPenalty', 'presencePenalty', 'maxOutputTokens'];
 | 
			
		||||
export const ModelFieldsAllList = ['temperature', 'topP', 'topK', 'frequencyPenalty', 'presencePenalty', 'maxOutputTokens', 'contextLength'];
 | 
			
		||||
 | 
			
		||||
export const AiModelMap = new Map<AiProvider, { modelList: string[], providerFieldsList: string[], modelFieldsList: string[] }>([
 | 
			
		||||
  [
 | 
			
		||||
@ -200,7 +201,7 @@ export const AiModelMap = new Map<AiProvider, { modelList: string[], providerFie
 | 
			
		||||
    {
 | 
			
		||||
      modelList: [],
 | 
			
		||||
      providerFieldsList: ['baseUrl'],
 | 
			
		||||
      modelFieldsList: ['temperature', 'topP', 'topK', 'maxOutputTokens'],
 | 
			
		||||
      modelFieldsList: ['temperature', 'topP', 'topK', 'maxOutputTokens', 'contextLength'],
 | 
			
		||||
    },
 | 
			
		||||
  ],
 | 
			
		||||
]);
 | 
			
		||||
 | 
			
		||||
@ -1156,8 +1156,9 @@
 | 
			
		||||
        "frequency-penalty": "Frequency penalty",
 | 
			
		||||
        "frequency-penalty-hint": "Applies a penalty to a token's likelihood that increases based on its frequency in the text.",
 | 
			
		||||
        "max-output-tokens": "Maximum output tokens",
 | 
			
		||||
        "max-output-tokens-min": "Must be greater than 0.",
 | 
			
		||||
        "max-output-tokens-hint": "Sets the maximum number of tokens that the \nmodel can generate in a single response.",
 | 
			
		||||
        "context-length": "Context length",
 | 
			
		||||
        "context-length-hint": "Defines the size of the context window in tokens. This value sets the total memory limit for the model, including both the user's input and the generated response.",
 | 
			
		||||
        "endpoint": "Endpoint",
 | 
			
		||||
        "endpoint-required": "Endpoint is required.",
 | 
			
		||||
        "baseurl": "Base URL",
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user