pyopenai

An attempt to reimplement python OpenAI API bindings in nim

Pure Nim score 15/100 · tests present · no docs generated

Summary

Latest Version 0.2.0
License GPL-3.0-or-later
CI Status Failing
Downloads 0
Last Indexed 2026-07-21 05:25

Authors

  • jaredmontoya

Installation

nimble install pyopenai
choosenim install pyopenai
git clone https://github.com/jaredmontoya/pyopenai

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
pyopenai - - - - - - -

Dependencies

Package Version Optional
nim ^=2.0.0 No

Source

Repository https://github.com/jaredmontoya/pyopenai
Homepage https://github.com/jaredmontoya/pyopenai
Registry Source nimble_official

README

PyOpenAI

Github top language GitHub code size in bytes

An attempt to reimplement python OpenAI API bindings in nim

Project Status

  • streams not implemented
  • async not implemented
  • not fully tested so if you encounter errors open an issue

If you need features that are not implemented yet, try openaiclient

What is implemented

Installation

To install pyopenai, you can simply run

nimble install pyopenai

Requisites

Example

import pyopenai, json, os

var openai = OpenAiClient(
  apiKey: getEnv("OPENAI_API_KEY")
)

let response = openai.createCompletion(
  model = "text-davinci-003",
  prompt = "nim is the best programming language",
  temperature = 0.6,
  maxTokens = 500
)

echo(response["choices"][0]["text"].getStr())

echo()

var chatMessages: seq[JsonNode]

chatMessages.add(
  %*{"role": "user", "content": "nim is the best programming language"}
)

let resp = openai.createChatCompletion(
  model = "gpt-3.5-turbo",
  messages = chatMessages,
  temperature = 0.5,
  maxTokens = 1000
)

chatMessages.add(
  resp["choices"][0]["message"]
)

echo(resp["choices"][0]["message"]["content"].getStr())