Skip to content

Ruby OpenAI

Bojan Marjanovic requested to merge ruby-openai-gem into master

What does this MR do and why?

Part of https://gitlab.com/gitlab-org/gitlab/-/issues/403619+ Adds a wrapper around the OpenAI gem.

The idea is that we can immediately start using this wrapper and in the future, when we know better how to deal with the use cases in the code, to write an abstraction in the Llm layer.

This feature is behind the openai_experimentation feature flag.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

How to set up and validate locally

  1. Enable Feature flag: Feature.enable(:openai_experimentation)
  2. Get the Access Token for OpenAI API (Ask in #wg_ai_integration)
  3. Set the key ApplicationSetting.update(openai_api_key: 'MY_KEY')

Examples

client = Gitlab::Llm::OpenAi::Client.new(User.first)

client.completions(prompt: "GitLab is a").dig("choices", 0, "text")
# => " DevOps platform built around a Git repository. It helps developers, and IT"
client = Gitlab::Llm::OpenAi::Client.new(User.first)

client.chat(content: "What is GitLab?").dig("choices", 0, "message")
# => => {"role"=>"assistant",
# "content"=> "GitLab is a web-based Git repository manager that provides source code management (SCM), continuous integration/continuous delivery (CI/CD) pipelines, and other features for software development. It offers a web interface, wikis, issue tracking, and a code review system. GitLab is an open-source platform that can be installed on-premises or used as a cloud-based service. It is used by developers and organizations to collaborate on software development projects, manage code repositories, and automate software delivery pipelines."}
client = Gitlab::Llm::OpenAi::Client.new(User.first)

client.edits(input: "What is Gtlab?", instruction: "Fix spelling error").dig("choices", 0, "text")
# => "What is Gitlab?\n"

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Wayne Haber

Merge request reports