Adithyare/oai chat completion
State: closed | Pull request: yes
Labels: name: NLP

name: Run CICD

# What does this PR do ?

Adds open ai compatible endpoints in for server based generation in NeMo.

**Collection**: [NLP]

# Changelog 
- Add specific line by line info of high level changes in this PR.

# Usage
To start the server, use the typical `megatron_gpt_eval.py` script and set `server=True`. For the client side snippets below you should also set the port to `port=6666`.

The client can then ping this server using oai completion and oai chat_completion requests.
Here is an example completion request:
```python
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:6666/v1", api_key="dummy_key")

response = client.completions.create(
  model="gpt-3.5-turbo-instruct", # for localhosted Nemo models any string can be used for model name.
  prompt="Write a tagline for an ice cream shop.",
  temperature=0.1,
  max_tokens=10,
  top_p=0.9,
) # type: ignore
```

Here is an example chat completion request (Note: to use this the `.nemo` model should be a chat-based model, i.e. trained on a chat-template): 
```python
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:6666/v1", api_key="dummy_key")

response = client.chat.completions.create(
  model="meta/llama-3.2-3b-instruct",
  messages=[{"role": "system", "content": ""}, 
            {"role": "user","content":"Write a limerick about the wonders of GPU computing."},
            {"role": "assistant", "content": "There once was a chip full of might, \
              That made data dance day and night. \
              With GPUs so grand, \
              Tasks were done on demand, \
              Turning code into speed and delight!"},
            {"role": "user", "content": "Can you change it to use the word NVIDIA?"}],
  temperature=0.2,
  top_p=0.7,
  max_tokens=1024,
  stream=False
) 
```

# GitHub Actions CI

The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.

The GitHub Actions CI will run automatically when the "Run CICD" label is added to the PR.
To re-run CI remove and add the label again.
To run CI on an untrusted fork, a NeMo user with write access must first click "Approve and run".

# Before your PR is "Ready for review"
**Pre checks**:
- [ ] Make sure you read and followed [Contributor guidelines](https://github.com/NVIDIA/NeMo/blob/main/CONTRIBUTING.md)
- [ ] Did you write any new necessary tests?
- [ ] Did you add or update any necessary documentation?
- [ ] Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
  - [ ] Reviewer: Does the PR have correct import guards for all optional libraries?
  
**PR Type**:
- [x] New Feature
- [ ] Bugfix
- [ ] Documentation

If you haven't finished some of the above items you can still open "Draft" PR.


## Who can review?

Anyone in the community is free to review the PR once the checks have passed. 
[Contributor guidelines](https://github.com/NVIDIA/NeMo/blob/main/CONTRIBUTING.md) contains specific people who can review PRs to various areas.

# Additional Information
* Related to # (issue)


[🤖]: Hi @arendu 👋,

We wanted to let you know that a [CICD pipeline](https://github.com/NVIDIA/NeMo/actions/runs/11279351983) for this PR just finished successfully

So it might be time to merge this PR or get some approvals

I'm just a bot so I'll leave it you what to do next.

//cc @pablo-garay @ko3n1g

[🤖]: Hi @arendu 👋,

We wanted to let you know that a [CICD pipeline](https://github.com/NVIDIA/NeMo/actions/runs/11355870596) for this PR just finished successfully

So it might be time to merge this PR or get some approvals

I'm just a bot so I'll leave it you what to do next.

//cc @pablo-garay @ko3n1g

[🤖]: Hi @arendu 👋,

We wanted to let you know that a [CICD pipeline](https://github.com/NVIDIA/NeMo/actions/runs/11370819235) for this PR just finished successfully

So it might be time to merge this PR or get some approvals

I'm just a bot so I'll leave it you what to do next.

//cc @pablo-garay @ko3n1g