Class OpenAIModel
java.lang.Object
me.neurodock.backend.open.ai.OpenAIModel
- All Implemented Interfaces:
Model, StreamingModel
-
Constructor Summary
ConstructorsConstructorDescriptionOpenAIModel(@NotNull String backendURI, @NotNull String modelName) Constructs anme.neurodock.backend.open.ai.OpenAIModelbound to a specific backend and model. -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()static ToolSerializer@Nullable CompletableFuture<org.json.JSONObject> queryJSON(org.json.JSONObject payload, String endpoint, String method, Consumer<org.json.JSONObject> onChunk) Sends a blocking HTTP request to the given endpoint on the configured backend and parses the response body as JSON.qurryModel(ChatObject obj, List<Tool> tools) Sends the conversation history inobjto the backend and requests the next assistant response.qurryModel(ChatObject obj, List<Tool> tools, Consumer<org.json.JSONObject> chunkConsumer) singleFire(Message msg) Sends a single, standalone message to the model, without any prior conversation context.singleFire(Message msg, Consumer<org.json.JSONObject> chunkConsumer) singleFire(Message msg, List<Tool> tools) Sends a single, standalone message to the model with tool support, without any prior conversation context.singleFire(Message msg, List<Tool> tools, Consumer<org.json.JSONObject> chunkConsumer) voidunload()Unloads the current model.
And ignoring any errors
-
Constructor Details
-
OpenAIModel
public OpenAIModel(@NotNull @NotNull String backendURI, @NotNull @NotNull String modelName) throws ModelNotFoundException Constructs anme.neurodock.backend.open.ai.OpenAIModelbound to a specific backend and model.This performs a blocking request against the backend to fetch the list of available models, then fuzzy-matches
modelNameagainst the returned model IDs, selecting the closest match above a minimum confidence threshold.- Parameters:
backendURI- the base URL of the OpenAI-compatible backend (e.g.http://localhost:11434)modelName- the model name, or partial name, to fuzzy-match against the backend's available models- Throws:
ModelNotFoundException- if no models could be retrieved from the backend (e.g. the server is unreachable, misconfigured, or — see@apiNote— rejects the request due to a missing API key), or if none of the returned models sufficiently matchmodelNameRuntimeException- ifbackendURIis malformed
-
-
Method Details
-
unload
public void unload()Unloads the current model.
And ignoring any errors -
qurryModel
Sends the conversation history inobjto the backend and requests the next assistant response.This performs the request asynchronously; the returned future completes once the backend has responded (or completes exceptionally if the request fails at the transport level — see
queryJSON(JSONObject, String, String)).- Specified by:
qurryModelin interfaceModel- Parameters:
obj- the chat context, containing the full conversation history to send to the modeltools- the tools available to the model for this request (currently unused — tool support is not yet implemented)- Returns:
- a future resolving to the assistant's reply as a
Message. If the backend returns no choices, or the response is otherwise malformed/missing, resolves to aMessagewith empty content rather than throwing.
-
singleFire
Description copied from interface:ModelSends a single, standalone message to the model, without any prior conversation context.- Specified by:
singleFirein interfaceModel- Parameters:
msg- the message to send- Returns:
- a future resolving to the model's reply as a
Message
-
singleFire
Description copied from interface:ModelSends a single, standalone message to the model with tool support, without any prior conversation context.- Specified by:
singleFirein interfaceModel- Parameters:
msg- the message to sendtools- the tools available to the model for this request- Returns:
- a future resolving to the model's reply as a
Message
-
getToolSerializer
- Specified by:
getToolSerializerin interfaceModel- Returns:
- this backend's
ToolSerializer, used to convertTools into the JSON shape this backend expects. Each backend instance owns its own — this is not shared across the JVM.
-
getDefaultToolSerializer
-
cancel
public void cancel() -
queryJSON
@Nullable public @Nullable CompletableFuture<org.json.JSONObject> queryJSON(org.json.JSONObject payload, String endpoint, String method, Consumer<org.json.JSONObject> onChunk) Sends a blocking HTTP request to the given endpoint on the configured backend and parses the response body as JSON.- Parameters:
payload- the JSON request body to send, ornullto send no bodyendpoint- the endpoint to request, resolved againstbackendURL(e.g."v1/models")method- the HTTP method to use (e.g."GET","POST")- Returns:
- the parsed
JSONObjectresponse body if the request succeeds with a 200 status, ornullif a non-200 status is received - Throws:
RuntimeException- if an I/O error occurs while communicating with the backend, or ifendpointcannot be resolved into a valid URL
-
qurryModel
public CompletableFuture<Message> qurryModel(ChatObject obj, List<Tool> tools, Consumer<org.json.JSONObject> chunkConsumer) - Specified by:
qurryModelin interfaceStreamingModel
-
singleFire
public CompletableFuture<Message> singleFire(Message msg, Consumer<org.json.JSONObject> chunkConsumer) - Specified by:
singleFirein interfaceStreamingModel
-
singleFire
public CompletableFuture<Message> singleFire(Message msg, List<Tool> tools, Consumer<org.json.JSONObject> chunkConsumer) - Specified by:
singleFirein interfaceStreamingModel
-