Feature request: Adding temperature as parameter (#513)

* Adding temperature as parameter

* NEXT_PUBLIC_ prefix added

* add spacing

---------

Co-authored-by: Ivan Fioravanti <>
Co-authored-by: Mckay Wrigley <mckaywrigley@gmail.com>
This commit is contained in:
Ivan Fioravanti
2023-04-13 13:09:03 +02:00
committed by GitHub
parent d1eb6ee29b
commit ea1d09244a
26 changed files with 142 additions and 25 deletions
+12 -1
View File
@@ -1,7 +1,7 @@
import { Conversation } from '@/types/chat';
import { OpenAIModelID, OpenAIModels } from '@/types/openai';
import { DEFAULT_SYSTEM_PROMPT } from './const';
import { DEFAULT_SYSTEM_PROMPT, DEFAULT_TEMPERATURE } from './const';
export const cleanSelectedConversation = (conversation: Conversation) => {
// added model for each conversation (3/20/23)
@@ -27,6 +27,13 @@ export const cleanSelectedConversation = (conversation: Conversation) => {
};
}
if (!updatedConversation.temperature) {
updatedConversation = {
...updatedConversation,
temperature: updatedConversation.temperature || DEFAULT_TEMPERATURE,
};
}
if (!updatedConversation.folderId) {
updatedConversation = {
...updatedConversation,
@@ -58,6 +65,10 @@ export const cleanConversationHistory = (history: any[]): Conversation[] => {
conversation.prompt = DEFAULT_SYSTEM_PROMPT;
}
if (!conversation.temperature) {
conversation.temperature = DEFAULT_TEMPERATURE;
}
if (!conversation.folderId) {
conversation.folderId = null;
}
+4 -1
View File
@@ -1,10 +1,13 @@
export const DEFAULT_SYSTEM_PROMPT =
process.env.DEFAULT_SYSTEM_PROMPT ||
process.env.NEXT_PUBLIC_DEFAULT_SYSTEM_PROMPT ||
"You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully. Respond using markdown.";
export const OPENAI_API_HOST =
process.env.OPENAI_API_HOST || 'https://api.openai.com';
export const DEFAULT_TEMPERATURE =
parseFloat(process.env.NEXT_PUBLIC_DEFAULT_TEMPERATURE || "1");
export const OPENAI_API_TYPE =
process.env.OPENAI_API_TYPE || 'openai';
+2 -1
View File
@@ -26,6 +26,7 @@ export class OpenAIError extends Error {
export const OpenAIStream = async (
model: OpenAIModel,
systemPrompt: string,
temperature : number,
key: string,
messages: Message[],
) => {
@@ -57,7 +58,7 @@ export const OpenAIStream = async (
...messages,
],
max_tokens: 1000,
temperature: 1,
temperature: temperature,
stream: true,
}),
});