Skip to content

Commit

Permalink
Add Azure configuration section
Browse files Browse the repository at this point in the history
  • Loading branch information
kardolus committed Dec 5, 2023
1 parent b802655 commit 4d79bae
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 43 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Azure, featuring streaming capabilities and extensive configuration options.
- [Windows (amd64)](#windows-amd64)
- [Getting Started](#getting-started)
- [Configuration](#configuration)
- [General Configuration](#general-configuration)
- [Azure Configuration](#azure-configuration)
- [Development](#development)
- [Reporting Issues and Contributing](#reporting-issues-and-contributing)
- [Uninstallation](#uninstallation)
Expand Down Expand Up @@ -164,6 +166,8 @@ Choose the appropriate command for your system, which will download the binary,
The ChatGPT CLI adopts a three-tier configuration strategy, with different levels of precedence assigned to default
values, the `config.yaml` file, and environment variables, in that respective order.

### General Configuration

Configuration variables:

| Variable | Description | Default |
Expand Down Expand Up @@ -231,6 +235,35 @@ chatgpt --set-model gpt-3.5-turbo-16k

This feature allows for rapid changes to key configuration parameters, optimizing your experience with the ChatGPT CLI.

### Azure Configuration

For Azure, use a configuration similar to:

```yaml
name: azure
api_key: <your_key>
model: <not relevant, read from the completions path>
max_tokens: 4096
role: You are a helpful assistant.
temperature: 1
top_p: 1
frequency_penalty: 0
presence_penalty: 0
thread: default
omit_history: false
url: https://<your_resource>.openai.azure.com
completions_path: /openai/deployments/<your_deployment>/chat/completions?api-version=<your_api>
models_path: /v1/models # not relevant
auth_header: api-key
auth_token_prefix: " "
```

You can set the API key either in the `config.yaml` file as shown above or export it as an environment variable:

```shell
export AZURE_API_KEY=<your_key>
```

## Development

To start developing, set the `OPENAI_API_KEY` environment variable to
Expand Down
148 changes: 105 additions & 43 deletions docs/openai_api.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,6 @@
# OpenAI API
# ChatGPT API

### cURL davinci

```shell
curl https://api.openai.com/v1/completions \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${OPENAI_API_KEY}" \
-d '{
"model": "text-davinci-003",
"prompt": "What is your name?",
"max_tokens": 4000,
"temperature": 1.0
}' \
--insecure | jq .
```

Output:

```json
{
"id": "cmpl-7BQi5QXWoy83V1HR8VcC7MzrtArGp",
"object": "text_completion",
"created": 1682958637,
"model": "text-davinci-003",
"choices": [
{
"text": "\n\nMy name is John.",
"index": 0,
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 5,
"completion_tokens": 7,
"total_tokens": 12
}
}
```
## OpenAI

### cURL gpt-turbo

Expand Down Expand Up @@ -143,12 +106,14 @@ Overall, it's good to keep a variety of toys on hand and observe your dog's pref
```
### List Models
```shell
curl https://api.openai.com/v1/models \
-H "Authorization: Bearer ${OPENAI_API_KEY}"
```
### curl DALL-E
```shell
curl https://api.openai.com/v1/images/generations \
-H "Content-Type: application/json" \
Expand All @@ -161,6 +126,7 @@ curl https://api.openai.com/v1/images/generations \
```
Output:
```json
{
"created": 1683295449,
Expand All @@ -180,9 +146,18 @@ Output:
1. Create a `jsonl` training file and call it `mydata.jsonl`
```json lines
{"prompt": "Who is Piet Kernbom?'", "completion": "Piet Kernbom was a famous baseball player for the Yankees"}
{"prompt": "Where was Piet Kernbom from?", "completion": "He is from Suriname."}
{"prompt": "What are some of Piet Kernbom his hobbies", "completion": "Magic tricks and cooking."}
{
"prompt": "Who is Piet Kernbom?'",
"completion": "Piet Kernbom was a famous baseball player for the Yankees"
}
{
"prompt": "Where was Piet Kernbom from?",
"completion": "He is from Suriname."
}
{
"prompt": "What are some of Piet Kernbom his hobbies",
"completion": "Magic tricks and cooking."
}
```
2. Upload the `jsonl` training file. Run this `curl` from the same directory the file is located in.
Expand All @@ -194,7 +169,7 @@ curl https://api.openai.com/v1/files \
-F file="@mydata.jsonl"
```
Output:
Output:
```json
{
Expand Down Expand Up @@ -222,6 +197,7 @@ curl https://api.openai.com/v1/fine-tunes \
```
Output:
```json
{
"object": "fine-tune",
Expand Down Expand Up @@ -283,6 +259,7 @@ curl https://api.openai.com/v1/completions -H 'Content-Type: application/json'
```
Output:
```json
{
"id": "cmpl-7Cs7cr7GxXRYkD9YUc9DiXPPx6HJQ",
Expand All @@ -304,3 +281,88 @@ Output:
}
}
```
## Azure
```shell
curl "https://[resource].openai.azure.com/openai/deployments/[deployment]/chat/completions?api-version=[model]" \
-H "Content-Type: application/json" \
-H "api-key: ${AZURE_API_KEY}" \
-d '{
"messages": [{"role": "user", "content": "What is the OpenAI mission?"}],
"max_tokens": 800,
"temperature": 0.7,
"frequency_penalty": 0,
"presence_penalty": 0,
"top_p": 0.95,
"stop": null,
"stream": true
}'
```
Output:
```shell
{
"id": "chatcmpl-8SFrsgGImGyykR82c2KhdQ40B06rq",
"object": "chat.completion",
"created": 1701744872,
"model": "gpt-4-32k",
"prompt_filter_results": [
{
"prompt_index": 0,
"content_filter_results": {
"hate": {
"filtered": false,
"severity": "safe"
},
"self_harm": {
"filtered": false,
"severity": "safe"
},
"sexual": {
"filtered": false,
"severity": "safe"
},
"violence": {
"filtered": false,
"severity": "safe"
}
}
}
],
"choices": [
{
"index": 0,
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": "The mission of OpenAI is to ensure that artificial general intelligence (AGI) benefits all of humanity. OpenAI aims to build safe and beneficial AGI directly, but it is also committed to aiding others in achieving this outcome. It focuses on long-term safety, technical leadership, and a cooperative orientation to actively cooperate with other research and policy institutions and create a global community working together to address AGI’s global challenges."
},
"content_filter_results": {
"hate": {
"filtered": false,
"severity": "safe"
},
"self_harm": {
"filtered": false,
"severity": "safe"
},
"sexual": {
"filtered": false,
"severity": "safe"
},
"violence": {
"filtered": false,
"severity": "safe"
}
}
}
],
"usage": {
"prompt_tokens": 14,
"completion_tokens": 84,
"total_tokens": 98
}
}
```

0 comments on commit 4d79bae

Please sign in to comment.