Skip to content

Commit

Permalink
Refactored the Mode enum in config/settings/index.ts to use numer…
Browse files Browse the repository at this point in the history
…ic values instead of string values, and updated the `useChatCompletion` hook to include the `modelName` and `temperature` properties when creating a new `ChatOpenAI` instance
  • Loading branch information
Royal-lobster committed Sep 23, 2023
1 parent fc2deeb commit eb8f7dc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/config/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export enum AvailableModels {
}

export enum Mode {
HIGHLY_PRECISE = '0',
PRECISE = '0.5',
BALANCED = '1',
CREATIVE = '1.5',
HIGHLY_PRECISE = 0,
PRECISE = 0.5,
BALANCED = 1,
CREATIVE = 1.5,
}

export type Settings = {
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/useChatCompletion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const useChatCompletion = ({
const chat = useMemo(() => new ChatOpenAI({
streaming: true,
openAIApiKey: apiKey,
modelName: model,
temperature: mode,
}), [])

const submitQuery = async (query: string) => {
Expand All @@ -44,7 +46,7 @@ export const useChatCompletion = ({
}
})
setGenerating(true)
const response = await chat.call([...previousMessages, new HumanMessage(query)], {
const response = await chat.call([new SystemMessage(systemPrompt), ...previousMessages, new HumanMessage(query)], {
signal: controller.signal,
callbacks: [
{
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useCurrentChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { useStorage } from "./useStorage"


export enum ChatRole {
"USER",
"ASSISTANT",
"SYSTEM"
"USER" = "USER",
"ASSISTANT" = "ASSISTANT",
"SYSTEM" = "SYSTEM",
}

export type ChatMessage = {
Expand Down

0 comments on commit eb8f7dc

Please sign in to comment.