No description
Find a file
2024-04-25 23:51:05 +02:00
src fixed doc comments and switched to using json helper procs 2024-04-25 23:51:05 +02:00
tests updated for Nim 2.0.0 2023-11-06 17:11:23 +01:00
.gitignore Updated .gitignore 2024-02-29 16:30:54 +01:00
config.nims initial commit 2023-07-28 15:53:06 +02:00
LICENSE initial commit 2023-07-28 15:53:06 +02:00
pyopenai.nimble updated for Nim 2.0.0 2023-11-06 17:11:23 +01:00
README.md fixed doc comments and switched to using json helper procs 2024-04-25 23:51:05 +02:00

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())