#!/usr/bin/env groovy
// PUBLIC DOMAIN - NO LICENSE, NO WARRANTY
// Copyright 2025 TimeHexOn & foxhop & russell@unturf
// https://www.permacomputer.com


// Hermes AI Non-Streaming Example using OpenAI Java Client
// Groovy leverages Java libraries seamlessly

@Grapes([
    @Grab(group='com.openai', module='openai-java', version='4.2.0')
])

import com.openai.client.OpenAIClient
import com.openai.client.okhttp.OpenAIOkHttpClient
import com.openai.models.ChatCompletion
import com.openai.models.ChatCompletionCreateParams
import com.openai.models.ChatCompletionMessageParam
import com.openai.models.ChatCompletionUserMessageParam

def baseUrl = "https://hermes.ai.unturf.com/v1"
def model = "adamo1139/Hermes-3-Llama-3.1-8B-FP8-Dynamic"

try {
    println "Requesting from Hermes AI...\n"

    // Create OpenAI client with custom base URL
    def client = OpenAIOkHttpClient.builder()
        .baseUrl(baseUrl)
        .apiKey("dummy-api-key")
        .build()

    // Create chat completion request
    def params = ChatCompletionCreateParams.builder()
        .model(model)
        .addMessage(ChatCompletionUserMessageParam.builder()
            .content("Give a Python Fizzbuzz solution in one line of code?")
            .build())
        .temperature(0.5)
        .maxTokens(150)
        .build()

    // Make request and get response
    def completion = client.chat().completions().create(params)
    def response = completion.choices()[0].message().content().get()

    println "Response: ${response}"

} catch (Exception e) {
    println "Error: ${e.message}"
    e.printStackTrace()
}
