Skip to content

r4inX/svyGroq

Repository files navigation

svyGroq (Servoy Web-Service)

Servoy TI/NG Client Web-Service for calling Groq through the OpenAI-compatible API.

This package exposes a typed, documented API under plugins.svyGroq.* (SPM installable).

Installation (Servoy SPM)

In Servoy Developer:

  1. Open SPM.
  2. Click Add...
  3. Enter this URL:

https://hv-office.de/changelog/wpm.json

After that, svyGroq will appear in the list and you can download/install it from there.

Security / Architecture

Important: The TI/NG Client runs in the browser.

  • If you set plugins.svyGroq.apiKey / call setApiKey() in the client, that key is not secret.
  • Recommended production architecture is Servoy Server (or your backend) → Groq, and the client calls your server.

For that architecture:

  • Set plugins.svyGroq.baseUrl to your proxy endpoint.
  • Call plugins.svyGroq.setProxyMode(true) (so no Authorization header is sent from the client).

Quick start

// Direct mode (dev/testing only)
plugins.svyGroq.setApiKey(scopes.globals.GROQ_API_KEY);

var text = plugins.svyGroq.chatCompletionText(
  plugins.svyGroq.models.DEFAULT,
  [ plugins.svyGroq.user('Hello from Servoy') ],
  { temperature: 0.2 }
);

If your scripting context treats calls as Promises, use .then(...):

plugins.svyGroq.chatCompletionText(plugins.svyGroq.models.DEFAULT, [plugins.svyGroq.user('Hi')])
  .then(function(text) {
    application.output(text);
  })
  .catch(function(e) {
    application.output('Groq error: ' + e);
  });

API reference

Model properties (plugins.svyGroq.<property>)

  • apiKey: string | null
    • Only used if sendAuthHeader=true.
  • baseUrl: string
    • Default: https://api.groq.com/openai/v1
    • For proxy mode point to your server.
  • defaultModel: string
    • Used when model parameter is empty.
  • models: groqModels
    • Predefined aliases for convenience:
      • DEFAULT
      • LLAMA_3_3_70B_VERSATILE
      • LLAMA_3_1_8B_INSTANT
      • LLAMA3_70B_8192
      • LLAMA3_8B_8192
      • MIXTRAL_8X7B_32768
      • GEMMA2_9B_IT
  • sendAuthHeader: boolean
    • Default true. In proxy mode set false.
  • timeoutMs: number
    • Default 60000. Applies to non-streaming calls.
  • retry: groqRetryConfig
    • Default retries on: 408, 429, 500, 502, 503, 504.
  • debug: boolean
    • When true, writes debug logs to console and fills lastRequest.
  • lastRequest: groqLastRequestInfo | null
    • Contains request telemetry (status, duration, requestId, ...).

Core methods

  • setApiKey(apiKey)
  • setProxyMode(enabled)
    • true: client does not send Authorization header.
  • chatCompletion(model, messages, options) → full JSON response
  • chatCompletionText(model, messages, options) → convenience text response

Advanced methods (recommended for robust apps)

  • chatCompletionEx(model, messages, options, requestOptions)
    • requestOptions.timeoutMs, requestOptions.retry, requestOptions.headers
  • chatCompletionTextEx(model, messages, options, requestOptions)

Convenience helpers

  • system(text) / user(text) / assistant(text)
  • registerModel(alias, modelId) / getModels()
  • extractText(resp)
  • extractToolCalls(resp)
  • createFunctionTool(name, description?, parameters?)

JSON mode

chatCompletionJson(model, messages, options?, requestOptions?) returns parsed JSON.

plugins.svyGroq.setApiKey(scopes.globals.GROQ_API_KEY);

var obj = plugins.svyGroq.chatCompletionJson(plugins.svyGroq.models.DEFAULT, [
  plugins.svyGroq.system('Return JSON only.'),
  plugins.svyGroq.user('Give me {"ok":true,"n":1}')
]);

application.output(obj.ok);

Tool calling (function tools)

You can send tools and tool_choice through the regular options object.

var tool = plugins.svyGroq.createFunctionTool(
  'sum',
  'Sums two integers',
  {
    type: 'object',
    properties: {
      a: { type: 'integer' },
      b: { type: 'integer' }
    },
    required: ['a', 'b']
  }
);

var resp = plugins.svyGroq.chatCompletion(
  plugins.svyGroq.models.DEFAULT,
  [ plugins.svyGroq.user('Use the tool to sum 4 and 5') ],
  { tools: [tool], tool_choice: 'auto' }
);

var toolCalls = plugins.svyGroq.extractToolCalls(resp);
application.output(JSON.stringify(toolCalls));

Streaming (SSE)

chatCompletionStreamText(model, messages, options?, onDelta?, streamOptions?)

plugins.svyGroq.setApiKey(scopes.globals.GROQ_API_KEY);

var full = plugins.svyGroq.chatCompletionStreamText(
  plugins.svyGroq.models.DEFAULT,
  [ plugins.svyGroq.user('Write 5 short sentences.') ],
  { temperature: 0.2 },
  function(deltaText) {
    application.output(deltaText); // live chunks
  }
);

application.output('DONE: ' + full);

Note: Streaming depends on browser networking behavior. If your environment buffers the response, you may not see incremental deltas.

Troubleshooting

  • models is null / missing IntelliSense
    • Ensure you installed the latest zip and reloaded solution. The package includes .spec types and a definition stub to avoid null.
  • GroqService: apiKey not set
    • Call setApiKey() or set sendAuthHeader=false (proxy mode).
  • 429 / rate limits
    • Tune retry and/or reduce max_tokens, lower concurrency.

Development

Local build

  • npm install
  • npm run build

Output is written to dist/servoy/svy-groq.

Create release zip

  • npm run make_release

This generates:

  • svyGroq.zip (latest)
  • svyGroq-<version>.zip (versioned)

License

Licensed under the Apache License 2.0. See LICENSE and the attribution notes in NOTICE.

About

The groq-sdk as servoy service

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors