Skip to content

Add Custom API Endpoint for Ollama #54

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion +llms/+internal/callOllamaChatAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
nvp.Seed
nvp.TimeOut
nvp.StreamFun
nvp.URL = "http://localhost:11434/api/chat" % Add the URL parameter with default value
end

URL = "http://localhost:11434/api/chat";
% Move URL to input argument
URL = nvp.URL;

% The JSON for StopSequences must have an array, and cannot say "stop": "foo".
% The easiest way to ensure that is to never pass in a scalar …
Expand Down
6 changes: 5 additions & 1 deletion ollamaChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
Model (1,1) string
TopK (1,1) {mustBeReal,mustBePositive} = Inf
TailFreeSamplingZ (1,1) {mustBeReal} = 1
Endpoint (1,1) string = "http://localhost:11434/api/chat" % Add default URL property
end

methods
Expand All @@ -82,6 +83,7 @@
nvp.TimeOut (1,1) {mustBeReal,mustBePositive} = 120
nvp.TailFreeSamplingZ (1,1) {mustBeReal} = 1
nvp.StreamFun (1,1) {mustBeA(nvp.StreamFun,'function_handle')}
nvp.Endpoint (1,1) string = "http://localhost:11434/api/chat" % Add Endpoint argument
end

if isfield(nvp,"StreamFun")
Expand All @@ -105,6 +107,7 @@
this.TailFreeSamplingZ = nvp.TailFreeSamplingZ;
this.StopSequences = nvp.StopSequences;
this.TimeOut = nvp.TimeOut;
this.Endpoint = nvp.Endpoint;
end

function [text, message, response] = generate(this, messages, nvp)
Expand Down Expand Up @@ -147,7 +150,8 @@
TailFreeSamplingZ=this.TailFreeSamplingZ,...
StopSequences=this.StopSequences, MaxNumTokens=nvp.MaxNumTokens, ...
ResponseFormat=this.ResponseFormat,Seed=nvp.Seed, ...
TimeOut=this.TimeOut, StreamFun=this.StreamFun);
TimeOut=this.TimeOut, StreamFun=this.StreamFun, ...
URL=this.Endpoint);

if isfield(response.Body.Data,"error")
err = response.Body.Data.error;
Expand Down