Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
Added chatgpt temperature environment variable (#162)
Browse files Browse the repository at this point in the history
* added chatgpt temperature enviroment variable

* accidentally use float instead of number

* fixed inline

* Updated the readme

* Updated the env example

---------

Co-authored-by: D <>
  • Loading branch information
deetungsten authored May 10, 2023
1 parent b11d566 commit 8efd3f9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ CHATGPT_API_MODEL=gpt-3.5-turbo
#CHATGPT_IGNORE_MEDIA=false
# (Optional) You can change the api url to use another (OpenAI-compatible) API endpoint
#CHATGPT_REVERSE_PROXY=https://api.openai.com/v1/chat/completions
# (Optional) Set the temperature of the model. 0.0 is deterministic, 1.0 is very creative.
# CHATGPT_TEMPERATURE=0.8

# Set data store settings
KEYV_BACKEND=file
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ Once the bot has started succesfully, it will output the following information t
## I use Docker but I don't see any console output
You most likely need to view the logs by running `docker logs matrix-chatgpt-bot`
## How to set the temperature
Set the temperature by using CHATGPT_TEMPERATURE in your .env file. The default is 0.8.
Here are some guidelines for setting the temperature:
| Temperature Values | Appropriate Tasks | Examples |
| --- | --- | --- |
| Below 0.5 (low) | Tasks requiring a single correct answer or predictable output | Programming |
| 0.5-0.9 (medium) | Tasks needing somewhat varied and creative content grounded in reality | E-mail response |
| Above 0.9 (high) | Tasks requiring more creative and unpredictable output | Story writing |
# Reporting issues
Expand Down
4 changes: 3 additions & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const {
CHATGPT_PROMPT_PREFIX,
CHATGPT_IGNORE_MEDIA,
CHATGPT_REVERSE_PROXY,
CHATGPT_TEMPERATURE,
} = parseEnv(process.env, {
DATA_PATH: { schema: z.string().default("./storage"), description: "Set to /storage/ if using docker, ./storage if running without" },
KEYV_BACKEND: { schema: z.enum(["file", "other"]).default("file"),description: "Set the Keyv backend to 'file' or 'other' if other set KEYV_URL" },
Expand Down Expand Up @@ -68,5 +69,6 @@ export const {
CHATGPT_API_MODEL: { schema: z.string().default(""), description: "The model for the ChatGPT-API to use. Keep in mind that these models will charge your OpenAI account depending on their pricing." },
CHATGPT_PROMPT_PREFIX: { schema: z.string().default('Instructions:\nYou are ChatGPT, a large language model trained by OpenAI.'), description: "Instructions to feed to ChatGPT on startup"},
CHATGPT_IGNORE_MEDIA: { schema: z.boolean().default(false), description: "Wether or not the bot should react to non-text messages"},
CHATGPT_REVERSE_PROXY: { schema: z.string().default(""), description: "Change the api url to use another (OpenAI-compatible) API endpoint" }
CHATGPT_REVERSE_PROXY: { schema: z.string().default(""), description: "Change the api url to use another (OpenAI-compatible) API endpoint" },
CHATGPT_TEMPERATURE: { schema: z.number().default(0.8), description: "Set the temperature for the model" }
});
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
DATA_PATH, KEYV_URL, OPENAI_API_KEY, MATRIX_HOMESERVER_URL, MATRIX_ACCESS_TOKEN, MATRIX_AUTOJOIN,
MATRIX_BOT_PASSWORD, MATRIX_BOT_USERNAME, MATRIX_ENCRYPTION, MATRIX_THREADS, CHATGPT_CONTEXT,
CHATGPT_API_MODEL, KEYV_BOT_STORAGE, KEYV_BACKEND, CHATGPT_PROMPT_PREFIX, MATRIX_WELCOME,
CHATGPT_REVERSE_PROXY
CHATGPT_REVERSE_PROXY, CHATGPT_TEMPERATURE
} from './env.js'
import CommandHandler from "./handlers.js"
import { KeyvStorageProvider } from './storage.js'
Expand Down Expand Up @@ -60,6 +60,7 @@ async function main() {
const clientOptions = { // (Optional) Parameters as described in https://platform.openai.com/docs/api-reference/completions
modelOptions: {
model: CHATGPT_API_MODEL, // The model is set to gpt-3.5-turbo by default
temperature: CHATGPT_TEMPERATURE,
},
promptPrefix: wrapPrompt(CHATGPT_PROMPT_PREFIX),
debug: false,
Expand Down

0 comments on commit 8efd3f9

Please sign in to comment.