-
-
Notifications
You must be signed in to change notification settings - Fork 14
feat:Broaden Ollama OpenAPI: response formats, think, provenance #145
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: main
Are you sure you want to change the base?
Conversation
WalkthroughThe 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
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
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.
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: uriRepeat 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: 1Optional 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: trueAlso applies to: 836-864
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (42)
src/libs/Ollama/Generated/Ollama..JsonSerializerContext.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.ChatClient.GenerateChatCompletion.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.CompletionsClient.GenerateCompletion.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.IChatClient.GenerateChatCompletion.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.ICompletionsClient.GenerateCompletion.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.IModelsClient.CreateModel.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.JsonConverters.GenerateChatCompletionRequestFormatEnum.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.JsonConverters.GenerateChatCompletionRequestFormatEnumNullable.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.JsonConverters.GenerateChatCompletionRequestThink.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.JsonConverters.GenerateChatCompletionRequestThinkNullable.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.JsonConverters.GenerateCompletionRequestFormatEnum.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.JsonConverters.GenerateCompletionRequestFormatEnumNullable.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.JsonConverters.GenerateCompletionRequestThink.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.JsonConverters.GenerateCompletionRequestThinkNullable.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.JsonConverters.OneOf2.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.JsonSerializerContextTypes.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.CreateModelRequest.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.CreateModelRequestAdapters.Json.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.CreateModelRequestAdapters.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.CreateModelRequestFiles.Json.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.CreateModelRequestFiles.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.CreateModelRequestParameters.Json.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.CreateModelRequestParameters.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.GenerateChatCompletionRequest.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.GenerateChatCompletionRequestFormatEnum.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.GenerateChatCompletionRequestFormatEnum2.Json.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.GenerateChatCompletionRequestFormatEnum2.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.GenerateChatCompletionRequestThink.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.GenerateChatCompletionResponse.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.GenerateCompletionRequest.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.GenerateCompletionRequestFormatEnum.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.GenerateCompletionRequestFormatEnum2.Json.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.GenerateCompletionRequestFormatEnum2.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.GenerateCompletionRequestThink.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.GenerateCompletionResponse.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.Message.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.Model.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.ModelInfo.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.Models.ToolCallFunction.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/Ollama.ModelsClient.CreateModel.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/OneOf.2.Json.g.csis excluded by!**/generated/**src/libs/Ollama/Generated/OneOf.2.g.csis 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.
Summary by CodeRabbit