-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checkpoint: user can select assistant id when in dev mode.
- Loading branch information
Showing
17 changed files
with
137 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { createContext } from "react"; | ||
import { AppConfigModelType } from "./models/app-config-model"; | ||
import { AppConfigModelType } from "../models/app-config-model"; | ||
|
||
export const AppConfigContext = createContext<AppConfigModelType | undefined>(undefined); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React, { createContext } from "react"; | ||
import { OpenAI } from "openai"; | ||
|
||
export const createNewConnection = () => { | ||
return new OpenAI({ | ||
apiKey: process.env.REACT_APP_OPENAI_API_KEY || "fake-key", | ||
baseURL: process.env.REACT_APP_OPENAI_BASE_URL, | ||
dangerouslyAllowBrowser: true, | ||
organization: "org-jbU1egKECzYlQI73HMMi7EOZ", | ||
project: "proj_VsykADfoZHvqcOJUHyVAYoDG", | ||
}); | ||
}; | ||
|
||
export const OpenAIConnectionContext = createContext<OpenAI|undefined>(undefined); | ||
|
||
export const OpenAIConnectionProvider = ({ children }: {children: React.ReactNode}) => { | ||
const apiConnection = createNewConnection(); | ||
return ( | ||
<OpenAIConnectionContext.Provider value={apiConnection}> | ||
{children} | ||
</OpenAIConnectionContext.Provider> | ||
) | ||
Check warning on line 22 in src/contexts/open-ai-connection-provider.tsx GitHub Actions / Build and Run Jest Tests
|
||
} | ||
Check warning on line 23 in src/contexts/open-ai-connection-provider.tsx GitHub Actions / Build and Run Jest Tests
Check warning on line 23 in src/contexts/open-ai-connection-provider.tsx GitHub Actions / Build and Run Jest Tests
Check warning on line 23 in src/contexts/open-ai-connection-provider.tsx GitHub Actions / Build and Run Jest Tests
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,14 @@ | ||
import { useMemo } from "react"; | ||
import { useAppConfigContext } from "./use-app-config-context"; | ||
import { AssistantModel } from "../models/assistant-model"; | ||
import { useChatTranscriptStore } from "./use-chat-transcript-store"; | ||
import { useOpenAIContext } from "./use-open-ai-context"; | ||
|
||
export const useAssistantStore = () => { | ||
const appConfig = useAppConfigContext(); | ||
const apiConnection = useOpenAIContext(); | ||
const transcriptStore = useChatTranscriptStore(); | ||
const { assistantId, instructions, modelName, useExisting } = appConfig.assistant; | ||
const assistantStore = useMemo(() => { | ||
return AssistantModel.create({ | ||
assistantId, | ||
modelName, | ||
instructions, | ||
transcriptStore, | ||
useExisting, | ||
}); | ||
}, [assistantId, instructions, modelName, transcriptStore, useExisting]); | ||
return AssistantModel.create({transcriptStore, apiConnection}); | ||
}, [transcriptStore, apiConnection]); | ||
|
||
return assistantStore; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useContext } from "react"; | ||
import { OpenAI } from "openai"; | ||
import { OpenAIConnectionContext } from "../contexts/open-ai-connection-provider"; | ||
|
||
export const useOpenAIContext = (): OpenAI => { | ||
const context = useContext(OpenAIConnectionContext); | ||
if (!context) { | ||
throw new Error("useOpenAIContext must be used within a OpenAIConnectionContext.Provider"); | ||
} | ||
return context; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.