~/docs/reference/sdks.md
5,008 bytesΒ·edit on github β†’

#SDKs

Official client libraries for the GPT-GOB API. All SDKs share the same interface, naming conventions, and error handling.

##Python

bash
pip install gpt-gob
python
from gpt_gob import GPTGob

client = GPTGob(api_key="gob-...")

# Standard chat
response = client.chat.completions.create(
    model="gob-5.5",
    messages=[{"role": "user", "content": "hi"}],
)
print(response.choices[0].message.content)

# Streaming
stream = client.chat.completions.create(
    model="gob-5.5",
    messages=[{"role": "user", "content": "tell me a story"}],
    stream=True,
)
for chunk in stream:
    if delta := chunk.choices[0].delta.content:
        print(delta, end="", flush=True)

# Embeddings
emb = client.embeddings.create(
    model="gob-embed-cave",
    input="text to embed",
)
vector = emb.data[0].embedding

# GRS scoring
score = client.grs.score(input="text to score")
print(score.score, score.interpretation)

###Async support

python
from gpt_gob import AsyncGPTGob

client = AsyncGPTGob(api_key="gob-...")

async def main():
    response = await client.chat.completions.create(
        model="gob-5.5",
        messages=[{"role": "user", "content": "hi"}],
    )
    print(response.choices[0].message.content)

###Configuration

python
client = GPTGob(
    api_key="gob-...",
    base_url="https://api.gpt-gob.ai/v1",  # default
    timeout=60.0,                          # seconds
    max_retries=3,
    default_headers={"X-Custom": "value"},
)

##Node.js / TypeScript

bash
npm install @gpt-gob/sdk
typescript
import { GPTGob } from "@gpt-gob/sdk";

const client = new GPTGob({ apiKey: process.env.GOB_API_KEY });

// Standard chat
const response = await client.chat.completions.create({
  model: "gob-5.5",
  messages: [{ role: "user", content: "hi" }],
});
console.log(response.choices[0].message.content);

// Streaming
const stream = await client.chat.completions.create({
  model: "gob-5.5",
  messages: [{ role: "user", content: "tell me a story" }],
  stream: true,
});
for await (const chunk of stream) {
  const delta = chunk.choices[0]?.delta?.content;
  if (delta) process.stdout.write(delta);
}

// Embeddings
const emb = await client.embeddings.create({
  model: "gob-embed-cave",
  input: "text to embed",
});

// GRS scoring
const score = await client.grs.score({ input: "text to score" });

###Edge runtime

The SDK is fully compatible with edge runtimes (Cloudflare Workers, Vercel Edge, Deno):

typescript
import { GPTGob } from "@gpt-gob/sdk/edge";

export default {
  async fetch(req: Request) {
    const client = new GPTGob({ apiKey: GOB_API_KEY });
    const response = await client.chat.completions.create({
      model: "gob-5.5-scout",
      messages: [{ role: "user", content: "hi" }],
    });
    return new Response(response.choices[0].message.content);
  },
};

##Go

bash
go get github.com/gptgob/gpt-gob-go
go
package main

import (
    "context"
    "fmt"

    "github.com/gptgob/gpt-gob-go"
)

func main() {
    client := gptgob.NewClient("gob-...")

    resp, err := client.Chat.Completions.Create(context.Background(), &gptgob.ChatCompletionRequest{
        Model: "gob-5.5",
        Messages: []gptgob.Message{
            {Role: "user", Content: "hi"},
        },
    })
    if err != nil {
        panic(err)
    }
    fmt.Println(resp.Choices[0].Message.Content)
}

##OpenAI SDK compatibility

Because our chat completions API is wire-compatible with OpenAI's, you can use the official OpenAI SDK as-is by changing the base URL:

python
from openai import OpenAI

client = OpenAI(
    api_key="gob-...",
    base_url="https://api.gpt-gob.ai/v1",
)

response = client.chat.completions.create(
    model="gob-5.5",
    messages=[{"role": "user", "content": "hi"}],
)
typescript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.GOB_API_KEY,
  baseURL: "https://api.gpt-gob.ai/v1",
});

const response = await client.chat.completions.create({
  model: "gob-5.5",
  messages: [{ role: "user", content: "hi" }],
});

GOB-specific parameters (mining_depth, shadow_attention, horde_mode, grs_target) are accepted via OpenAI SDK's typed-extra mechanism but won't show up in the type signature. For full type support, use our official SDKs.

##Community libraries

Maintained by the community, not officially supported:

LanguageLibraryMaintainer
Rubygob-ruby@goblin-ruby on GitHub
Rustgob-rs@rusty-goblin
Javagob-java@gob-jvm
C#/.NETgob-dotnet@goblin-net
PHPgob-php@goblin-php
Elixirgob_ex@gob-bytes

##Source code

All official SDKs are open source under the Apache 2.0 license:

  • β–ΈPython: github.com/gptgob/gpt-gob/tree/main/packages/sdk-python
  • β–ΈNode: github.com/gptgob/gpt-gob/tree/main/packages/sdk-node
  • β–ΈGo: github.com/gptgob/gpt-gob-go