Skip to content

Conversation

@HavenDV
Copy link
Contributor

@HavenDV HavenDV commented Oct 15, 2025

Summary by CodeRabbit

  • New Features
    • More flexible response formats (JSON enum or custom schema) with nullable support.
    • Expanded “think” control: boolean or priority levels (high/medium/low).
    • Responses and model metadata now include upstream model and host details.
    • Messages can include a tool name; tool calls include a positional index.
    • Richer model creation options (source, files, adapters, template, system, parameters) with nullable fields.
  • Documentation
    • Clarified behavior for prompt truncation (end of history) and context shifting.

@coderabbitai
Copy link

coderabbitai bot commented Oct 15, 2025

Walkthrough

The OpenAPI spec for Ollama was updated to broaden request/response schemas: flexible response format typing, expanded chat “think” options, nullable markers, new federated provenance fields (remote_model/remote_host), tool call indexing, and an expanded CreateModelRequest with additional optional fields and nullability. Several descriptions were refined.

Changes

Cohort / File(s) Summary of Changes
Response format typing
src/libs/Ollama/openapi.yaml
ResponseFormat now oneOf: enum "json" or JSON schema object; nullable: true. GenerateCompletionRequest.format updated accordingly and descriptions adjusted.
Chat request options
src/libs/Ollama/openapi.yaml
GenerateChatCompletionRequest.think now oneOf boolean or enum (high/medium/low); nullable: true. truncate and shift marked nullable with clarified behaviors.
Federated metadata in responses/models
src/libs/Ollama/openapi.yaml
Added nullable remote_model and remote_host to GenerateCompletionResponse, GenerateChatCompletionResponse, Model, ModelInfo, and related schemas.
Tooling enhancements
src/libs/Ollama/openapi.yaml
Message gains nullable tool_name for tool role. ToolCallFunctionArgs and ToolCallFunction gain integer index for ordering.
CreateModelRequest expansion
src/libs/Ollama/openapi.yaml
modelfile now nullable. Added optional fields: from, files, adapters, template, system, parameters (nullable where appropriate).
Descriptions/nullable adjustments
src/libs/Ollama/openapi.yaml
Minor description updates and additional nullable markers across affected properties without changing core types beyond noted additions.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant API as Ollama API
  participant Upstream as Remote Model Host

  rect rgb(235,245,255)
    note over Client,API: Generate Chat Completion (with think/truncate/shift)
    Client->>API: POST /chat/completions { messages, think, format? }
    alt Federation used
      API->>Upstream: Forward request (model, messages, think)
      Upstream-->>API: Completion + remote_model/remote_host
    else Local
      API-->>API: Generate locally
    end
    API-->>Client: Response { choices..., remote_model?, remote_host? }
  end

  rect rgb(240,255,240)
    note over Client,API: Create Model (expanded payload)
    Client->>API: POST /models { modelfile?, from?, files?, adapters?, template?, system?, parameters? }
    API-->>Client: 202/200 Model info { remote_model?, remote_host? }
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

I twitch my ears at schemas new,
OneOf burrows widened through—
Think high or low, or simply true,
Tools in line, with indices too.
Remote scents drift on model breeze,
Nullables hop with graceful ease 🐇,
And builders mix their fields to please.

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title Check ❓ Inconclusive The title "feat:@coderabbitai" is vague and generic, failing to convey any meaningful information about the changeset. It appears to be a bot mention asking for a summary rather than an actual title describing the changes. The actual changeset contains significant OpenAPI schema modifications including new fields (remote_model, remote_host, tool_name, index), oneOf constructs for ResponseFormat, expanded CreateModelRequest fields, and nullable markers across multiple schemas, none of which are reflected in the title. A teammate scanning the repository history would have no understanding of what this pull request actually changes. The title should be revised to clearly describe the primary changes made to the OpenAPI specification. Consider a title such as "feat: enhance OpenAPI schema with federated model fields and tool call metadata" or similar that captures the main addition of remote_model/remote_host fields to response schemas and related schema enhancements. This would provide clarity about the changeset's primary intent when reviewing repository history.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bot/update-openapi_202510152122

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@HavenDV HavenDV enabled auto-merge (squash) October 15, 2025 21:23
@coderabbitai coderabbitai bot changed the title feat:@coderabbitai feat:Broaden Ollama OpenAPI: response formats, think, provenance Oct 15, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (6)
src/libs/Ollama/openapi.yaml (6)

289-299: Deduplicate ResponseFormat; use $ref with allOf + nullable to avoid drift.

You’ve inlined the same oneOf twice while also keeping components.schemas.ResponseFormat. Centralize via $ref to prevent divergence and keep nullable at the property level.

Apply for GenerateCompletionRequest.format:

-        format:
-          oneOf:
-            - enum:
-                - json
-              type: string
-              description: Enable JSON mode
-              default: json
-            - type: object
-              description: JSON schema object for structured output validation
-          description: "The format to return a response in. Can be:
- - "json" string to enable JSON mode
- - JSON schema object for structured output validation
-"
-          nullable: true
+        format:
+          allOf:
+            - $ref: '#/components/schemas/ResponseFormat'
+          nullable: true
+          description: 'The format to return a response in. See ResponseFormat.'

Apply for GenerateChatCompletionRequest.format:

-        format:
-          oneOf:
-            - enum:
-                - json
-              type: string
-              description: Enable JSON mode
-              default: json
-            - type: object
-              description: JSON schema object for structured output validation
-          description: "The format to return a response in. Can be:
- - "json" string to enable JSON mode
- - JSON schema object for structured output validation
-"
-          nullable: true
+        format:
+          allOf:
+            - $ref: '#/components/schemas/ResponseFormat'
+          nullable: true
+          description: 'The format to return a response in. See ResponseFormat.'

Also applies to: 572-582, 468-475


543-551: Validate remote_host as a URI; tighten remote_model.

Add URI format for remote_host and optionally minLength for remote_model.

         remote_model:
           type: string
           description: Name of the upstream remote model that generated the response (when using federated models)
           nullable: true
+          minLength: 1
         remote_host:
           type: string
           description: URL of the upstream Ollama host that served the request (when proxying to remote instances)
           nullable: true
+          format: uri

Repeat the same additions in:

  • GenerateChatCompletionResponse (lines 665-673)
  • Model (lines 912-920)
  • ModelInfo (lines 1095-1103)

Also applies to: 665-673, 912-920, 1095-1103


323-329: Clarify truncate vs shift precedence when both are true.

Specify how they interact (e.g., apply shift first, then truncate; or mutually exclusive).

Consider adding: “If both are true, shift is applied before truncate” (or the intended rule).

Also applies to: 604-610


716-720: Make tool_name required when role=tool (or minimally enforce non-empty).

Currently nullable. Either add conditional requirement or ensure non-empty if present.

Minimal tightening:

         tool_name:
           type: string
           description: The name of the tool when role is "tool" (used in tool response messages)
-          nullable: true
+          nullable: true
+          minLength: 1

Optional stronger schema (conditional requirement) can be done with oneOf variants for role=tool vs others; ask if you want a patch.


769-772: Constrain index to non-negative and consider placement.

Add minimum: 0. Also consider placing index on ToolCall (the list element) rather than inside function to avoid ambiguity if other tool types are added.

         index:
           type: integer
           description: The index of the tool call in the list of tool calls
+          minimum: 0

821-824: CreateModelRequest: clarify field precedence and expected values.

Good additions. Clarify:

  • Precedence between modelfile, path, and from.
  • That files/adapters map values should be server file paths returned by Create Blob.

Example tweaks:

         modelfile:
           type: string
-          description: The contents of the Modelfile.
+          description: The contents of the Modelfile. If provided, takes precedence over `path` and `from`.
           nullable: true
...
         from:
           type: string
-          description: Name of the model or file to use as the source
+          description: Name of the base model or model file to use as the source (used when `modelfile` is not provided).
           nullable: true
         files:
           type: object
           additionalProperties:
-            type: string
-          description: Map of files to include when creating the model
+            type: string
+            description: Server file path returned by the Create Blob endpoint.
+          description: Map of files to include when creating the model (key = logical name, value = server blob path)
           nullable: true
         adapters:
           type: object
           additionalProperties:
-            type: string
-          description: Map of LoRA adapters to include when creating the model
+            type: string
+            description: Server file path returned by the Create Blob endpoint (for adapter layers).
+          description: Map of LoRA adapters to include when creating the model (key = adapter name, value = server blob path)
           nullable: true

Also applies to: 836-864

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b176606 and 22635c9.

⛔ Files ignored due to path filters (42)
  • src/libs/Ollama/Generated/Ollama..JsonSerializerContext.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.ChatClient.GenerateChatCompletion.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.CompletionsClient.GenerateCompletion.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.IChatClient.GenerateChatCompletion.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.ICompletionsClient.GenerateCompletion.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.IModelsClient.CreateModel.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.JsonConverters.GenerateChatCompletionRequestFormatEnum.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.JsonConverters.GenerateChatCompletionRequestFormatEnumNullable.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.JsonConverters.GenerateChatCompletionRequestThink.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.JsonConverters.GenerateChatCompletionRequestThinkNullable.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.JsonConverters.GenerateCompletionRequestFormatEnum.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.JsonConverters.GenerateCompletionRequestFormatEnumNullable.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.JsonConverters.GenerateCompletionRequestThink.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.JsonConverters.GenerateCompletionRequestThinkNullable.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.JsonConverters.OneOf2.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.JsonSerializerContextTypes.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.CreateModelRequest.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.CreateModelRequestAdapters.Json.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.CreateModelRequestAdapters.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.CreateModelRequestFiles.Json.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.CreateModelRequestFiles.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.CreateModelRequestParameters.Json.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.CreateModelRequestParameters.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.GenerateChatCompletionRequest.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.GenerateChatCompletionRequestFormatEnum.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.GenerateChatCompletionRequestFormatEnum2.Json.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.GenerateChatCompletionRequestFormatEnum2.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.GenerateChatCompletionRequestThink.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.GenerateChatCompletionResponse.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.GenerateCompletionRequest.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.GenerateCompletionRequestFormatEnum.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.GenerateCompletionRequestFormatEnum2.Json.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.GenerateCompletionRequestFormatEnum2.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.GenerateCompletionRequestThink.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.GenerateCompletionResponse.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.Message.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.Model.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.ModelInfo.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.Models.ToolCallFunction.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/Ollama.ModelsClient.CreateModel.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/OneOf.2.Json.g.cs is excluded by !**/generated/**
  • src/libs/Ollama/Generated/OneOf.2.g.cs is excluded by !**/generated/**
📒 Files selected for processing (1)
  • src/libs/Ollama/openapi.yaml (12 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test / Build, test and publish
🔇 Additional comments (2)
src/libs/Ollama/openapi.yaml (2)

313-322: Confirm server supports think boolean or tiered strings.

Schema allows boolean or {high, medium, low}. Ensure backend accepts both and maps them consistently.

Would you like me to add brief description notes on how the server maps true/false to a tier?

Also applies to: 594-603


468-475: Incorrect review comment: ResponseFormat is actively used and referenced.

The ResponseFormat component defined in the OpenAPI spec is not dead code. It is actively used in:

  • src/libs/Ollama/Chat.cs (property and method parameter for structured output)
  • src/helpers/FixOpenApiSpec/Program.cs (processed during spec generation, lines 44–61)
  • Test code (src/tests/Ollama.IntegrationTests/Test.StructuredOutputInChat.cs)
  • Generated model classes, JSON converters, and serializers

No action required.

Likely an incorrect or invalid review comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants