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
fix(OpenAIClient.js): remove unnecessary whitespace
fix(OpenAIClient.js): remove unused variables and comments
fix(OpenAIClient.test.js): combine getTokenCount and freeAndResetEncoder tests
  • Loading branch information
danny-avila committed Jul 3, 2023
commit 9fd7dcfdee5ae651ca6866e2050f8cc93301803f
14 changes: 7 additions & 7 deletions api/app/clients/classes/OpenAIClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ class OpenAIClient extends BaseClient {
if (!isChatCompletion) {
return await this.buildPrompt(messages, parentMessageId, { isChatGptModel: isChatCompletion, promptPrefix });
}

let payload;
let instructions;
let tokenCountMap;
let orderedMessages = this.constructor.getMessagesForConversation(messages, parentMessageId);

promptPrefix = (promptPrefix || this.options.promptPrefix || '').trim();
if (promptPrefix) {
promptPrefix = `Instructions:\n${promptPrefix}`;
Expand All @@ -217,7 +217,7 @@ class OpenAIClient extends BaseClient {
instructions.tokenCount = this.getTokenCountForMessage(instructions);
}
}

const formattedMessages = orderedMessages.map((message) => {
let { role: _role, sender, text } = message;
const role = _role ?? sender;
Expand All @@ -234,14 +234,14 @@ class OpenAIClient extends BaseClient {
if (this.contextStrategy) {
formattedMessage.tokenCount = message.tokenCount ?? this.getTokenCountForMessage(formattedMessage);
}

return formattedMessage;
});

// TODO: need to handle interleaving instructions better
if (this.contextStrategy) {
({ payload, tokenCountMap } = await this.handleContextStrategy({instructions, orderedMessages, formattedMessages}));
}
}

const result = {
prompt: payload,
Expand All @@ -254,7 +254,7 @@ class OpenAIClient extends BaseClient {

return result;
}

async sendCompletion(payload, opts = {}) {
let reply = '';
let result = null;
Expand Down
14 changes: 6 additions & 8 deletions api/app/clients/classes/OpenAIClient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,17 @@ describe('OpenAIClient', () => {
});
});

describe('freeAndResetEncoder', () => {
it('should reset the encoder', () => {
client.freeAndResetEncoder();
expect(client.gptEncoder).toBeDefined();
});
});

describe('getTokenCount', () => {
describe('getTokenCount & freeAndResetEncoder', () => {
it('should return the correct token count', () => {
const count = client.getTokenCount('Hello, world!');
expect(count).toBeGreaterThan(0);
});

it('should reset the encoder', () => {
client.freeAndResetEncoder();
expect(client.gptEncoder).toBeDefined();
});

it('should reset the encoder and count when count reaches 25', () => {
const freeAndResetEncoderSpy = jest.spyOn(client, 'freeAndResetEncoder');

Expand Down