Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Client Classes & Azure OpenAI as a separate Endpoint #532

Merged
merged 40 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
76d7511
refactor: start new client classes, test localAi support
danny-avila Jun 17, 2023
eadf871
feat: create base class, extend chatgpt from base
danny-avila Jun 17, 2023
05588fc
refactor(BaseClient.js): change userId parameter to user
danny-avila Jun 17, 2023
d9b6687
refactor(BaseClient.js): use optional chaining operator to access mes…
danny-avila Jun 18, 2023
4ac8e60
refactor: update import statements and remove unused imports in sever…
danny-avila Jun 18, 2023
d9c01ba
refactor(utils): rename migrateConversations to migrateDataToFirstUse…
danny-avila Jun 18, 2023
d831006
feat(chatgpt-client.js): add getAzureCredentials function to retrieve…
danny-avila Jun 18, 2023
f41abd3
chore: delete draft file
danny-avila Jun 18, 2023
b1913a3
refactor(OpenAIClient.js): extract sendCompletion method from sendMes…
danny-avila Jun 19, 2023
c2d263c
refactor(BaseClient.js): move sendMessage method to BaseClient class
danny-avila Jun 21, 2023
c25fe77
refactor(BaseClient.js): rename getBuildPromptOptions to getBuildMess…
danny-avila Jun 21, 2023
b9cce41
refactor(ChatGPTClient.js, OpenAIClient.js): improve code readability…
danny-avila Jun 21, 2023
2da5a95
refactor(OpenAIClient.js): extract instructions object to a separate …
danny-avila Jun 22, 2023
d0de53c
refactor(BaseClient.js): extract addInstructions method from sendMess…
danny-avila Jun 22, 2023
78cdec3
refactor(OpenAIClient.js): remove unnecessary condition for modelOpti…
danny-avila Jun 22, 2023
d4c603f
feat(BaseClient.js): add support for token count tracking and context…
danny-avila Jun 25, 2023
fc0c437
refactor(BaseClient.js): add support for refining messages based on t…
danny-avila Jun 25, 2023
b367266
refactor(BaseClient.js): change `remainingContext` to `remainingConte…
danny-avila Jun 25, 2023
e6d49b9
chore(openAI.js): comment out contextStrategy option in clientOptions
danny-avila Jun 25, 2023
d86c4ca
chore(openAI.js): comment out debug option in clientOptions object
danny-avila Jun 27, 2023
21bdc53
test: BaseClient tests in progress
danny-avila Jun 29, 2023
4d2e3f7
test: Complete OpenAIClient & BaseClient tests
danny-avila Jun 29, 2023
9fd7dcf
fix(OpenAIClient.js): remove unnecessary whitespace
danny-avila Jun 29, 2023
6dc60ab
chore(.eslintrc.js): add rule for maximum of 1 empty line
danny-avila Jun 29, 2023
223945e
test: complete additional tests
danny-avila Jun 29, 2023
5575d58
feat: Azure OpenAI as a separate endpoint
danny-avila Jul 2, 2023
3178419
chore: remove extraneous console logs
danny-avila Jul 2, 2023
4a6e039
fix(azureOpenAI): use chatCompletion endpoint
danny-avila Jul 2, 2023
5687597
chore(initializeClient.js): delete initializeClient.js file
danny-avila Jul 2, 2023
970e6c6
chore(chatgpt-client.js): remove unused chatgpt-client.js file
danny-avila Jul 2, 2023
800bc62
chore(chatgpt-client.tokens.js): update test script for memory usage …
danny-avila Jul 2, 2023
cb92113
feat(FakeClient.js): add a new class `FakeClient` that extends `BaseC…
danny-avila Jun 30, 2023
d8f7919
refactor(gptPlugins): refactor ChatAgent to PluginsClient, which exte…
danny-avila Jul 3, 2023
9f1f973
refactor: client paths
danny-avila Jul 3, 2023
a10daf4
chore(jest.config.js): remove jest.config.js file
danny-avila Jul 3, 2023
533e935
fix(PluginController.js): update file path to manifest.json
danny-avila Jul 3, 2023
bb8b3c2
fix(BaseClient.js): fix spacing in generateTextStream function signature
danny-avila Jul 3, 2023
3586b37
refactor(GoogleClient): GoogleClient now extends BaseClient
danny-avila Jul 3, 2023
9f0bb61
chore(.env.example): add AZURE_OPENAI_MODELS variable
danny-avila Jul 3, 2023
8108164
fix(e2e:popup): includes the icon + endpoint names in role, name prop…
danny-avila Jul 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(ChatGPTClient.js, OpenAIClient.js): improve code readability…
… and consistency

- In ChatGPTClient.js, update the roleLabel and messageString variables to handle cases where the message object does not have an isCreatedByUser property or a role property with a value of 'user'.
- In OpenAIClient.js, rename the freeAndInitializeEncoder method to freeAndResetEncoder to better reflect its functionality. Also, update the method calls to reflect the new name. Additionally, update the getTokenCount method to handle errors by calling the freeAndResetEncoder method instead of the now-renamed freeAndInitializeEncoder method.
  • Loading branch information
danny-avila committed Jul 3, 2023
commit b9cce41e3a825f747eddb76114cf5dfec7717140
4 changes: 2 additions & 2 deletions api/app/clients/classes/ChatGPTClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,8 @@ ${botMessage.message}
const buildPromptBody = async () => {
if (currentTokenCount < maxTokenCount && orderedMessages.length > 0) {
const message = orderedMessages.pop();
const roleLabel = message.isCreatedByUser ? this.userLabel : this.chatGptLabel;
const messageString = `${this.startToken}${roleLabel}:\n${message.text}${this.endToken}\n`;
const roleLabel = message?.isCreatedByUser || message?.role?.toLowerCase() === 'user' ? this.userLabel : this.chatGptLabel;
const messageString = `${this.startToken}${roleLabel}:\n${message?.text ?? message?.message}${this.endToken}\n`;
let newPromptBody;
if (promptBody || isChatGptModel) {
newPromptBody = `${messageString}${promptBody}`;
Expand Down
8 changes: 4 additions & 4 deletions api/app/clients/classes/OpenAIClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class OpenAIClient extends BaseClient {
return tokenizer;
}

freeAndInitializeEncoder() {
freeAndResetEncoder() {
try {
if (!this.gptEncoder) {
return;
Expand All @@ -146,20 +146,20 @@ class OpenAIClient extends BaseClient {
this.setupTokenizer();
tokenizersCache.count = 0;
} catch (error) {
console.log('freeAndInitializeEncoder error');
console.log('freeAndResetEncoder error');
console.error(error);
}
}

getTokenCount(text) {
try {
if (tokenizersCache.count >= 25) {
this.freeAndInitializeEncoder();
this.freeAndResetEncoder();
}
tokenizersCache.count = (tokenizersCache.count || 0) + 1;
return this.gptEncoder.encode(text, 'all').length;
} catch (error) {
this.freeAndInitializeEncoder();
this.freeAndResetEncoder();
return this.gptEncoder.encode(text, 'all').length;
}
}
Expand Down