Skip to content

Commit

Permalink
Update initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
fatihturker committed May 7, 2023
1 parent 69d9b42 commit d99f58d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 34 deletions.
32 changes: 21 additions & 11 deletions NPM-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ Follow these steps to start exploring the world of PI AGI:
```javascript
import { v4 as uuidv4 } from 'uuid';
import * as path from 'path';
import { MainAGI, OpenAIAzureProvider } from '@pi-agi/core';
import { ActionType, MainAGI, OpenAIAzureProvider } from '@pi-agi/core';

/**
* A class representing a Senior Backend Software Engineer AGI.
*/
export class SeniorBackendSoftwareEngineerAGI extends MainAGI {
constructor(openAIProvider: OpenAIAzureProvider) {
super(openAIProvider);
export class SeniorBackendSoftwareEngineerAGI extends MainAGI<ActionType> {
constructor(
openAIProvider: OpenAIAzureProvider,
maxRetryCount: number,
maxRetryInterval: number
) {
super(openAIProvider, maxRetryCount, maxRetryInterval);
}

/**
Expand All @@ -54,7 +58,7 @@ export class SeniorBackendSoftwareEngineerAGI extends MainAGI {
this.consolidationId = uuidv4();
super.consolidationId = this.consolidationId;

super.initialize();
super.initialize(__dirname);

this.mainPrompt = await this.fileUtil.readFileContent(
path.join(
Expand Down Expand Up @@ -104,26 +108,28 @@ async function createContent(documentation: string): Promise<Content> {
} as Content;
}

function createProvider(): OpenAIAzureProvider {
function createProvider(): any {
const apiKey = process.env.API_KEY as string;
const apiEndpoint = process.env.API_ENDPOINT as string;
const apiVersion = process.env.API_VERSION as string;
const maxToken = Number.parseInt(process.env.MAX_TOKEN as string);
const maxRetryCount = Number.parseInt(process.env.MAX_RETRY_COUNT as string);
const retryInterval = Number.parseInt(process.env.RETRY_INTERVAL as string);

return new OpenAIAzureProvider(
const provider = new OpenAIAzureProvider(
apiKey,
apiEndpoint,
apiVersion,
maxToken,
maxRetryCount,
retryInterval
);

return { provider, maxRetryCount, retryInterval };
}

async function backend() {
const input = await new FileUtil().readFileContent(
const documentation = await new FileUtil().readFileContent(
path.join(
__dirname,
'asset',
Expand All @@ -132,9 +138,13 @@ async function backend() {
)
);

const content = await createContent(input);
const gptProvider = createProvider();
const agi = new SeniorBackendSoftwareEngineerAGI(gptProvider);
const content = await createContent(documentation);
const { gptProvider, maxRetryCount, maxRetryInterval } = createProvider();
const agi = new SeniorBackendSoftwareEngineerAGI(
gptProvider,
maxRetryCount,
maxRetryInterval
);

agi.init();
await agi.start(content);
Expand Down
32 changes: 21 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ Follow these steps to start exploring the world of PI AGI:
```javascript
import { v4 as uuidv4 } from 'uuid';
import * as path from 'path';
import { MainAGI, OpenAIAzureProvider } from '@pi-agi/core';
import { ActionType, MainAGI, OpenAIAzureProvider } from '@pi-agi/core';

/**
* A class representing a Senior Backend Software Engineer AGI.
*/
export class SeniorBackendSoftwareEngineerAGI extends MainAGI {
constructor(openAIProvider: OpenAIAzureProvider) {
super(openAIProvider);
export class SeniorBackendSoftwareEngineerAGI extends MainAGI<ActionType> {
constructor(
openAIProvider: OpenAIAzureProvider,
maxRetryCount: number,
maxRetryInterval: number
) {
super(openAIProvider, maxRetryCount, maxRetryInterval);
}

/**
Expand All @@ -54,7 +58,7 @@ export class SeniorBackendSoftwareEngineerAGI extends MainAGI {
this.consolidationId = uuidv4();
super.consolidationId = this.consolidationId;

super.initialize();
super.initialize(__dirname);

this.mainPrompt = await this.fileUtil.readFileContent(
path.join(
Expand Down Expand Up @@ -104,26 +108,28 @@ async function createContent(documentation: string): Promise<Content> {
} as Content;
}

function createProvider(): OpenAIAzureProvider {
function createProvider(): any {
const apiKey = process.env.API_KEY as string;
const apiEndpoint = process.env.API_ENDPOINT as string;
const apiVersion = process.env.API_VERSION as string;
const maxToken = Number.parseInt(process.env.MAX_TOKEN as string);
const maxRetryCount = Number.parseInt(process.env.MAX_RETRY_COUNT as string);
const retryInterval = Number.parseInt(process.env.RETRY_INTERVAL as string);

return new OpenAIAzureProvider(
const provider = new OpenAIAzureProvider(
apiKey,
apiEndpoint,
apiVersion,
maxToken,
maxRetryCount,
retryInterval
);

return { provider, maxRetryCount, retryInterval };
}

async function backend() {
const input = await new FileUtil().readFileContent(
const documentation = await new FileUtil().readFileContent(
path.join(
__dirname,
'asset',
Expand All @@ -132,9 +138,13 @@ async function backend() {
)
);

const content = await createContent(input);
const gptProvider = createProvider();
const agi = new SeniorBackendSoftwareEngineerAGI(gptProvider);
const content = await createContent(documentation);
const { gptProvider, maxRetryCount, maxRetryInterval } = createProvider();
const agi = new SeniorBackendSoftwareEngineerAGI(
gptProvider,
maxRetryCount,
maxRetryInterval
);

agi.init();
await agi.start(content);
Expand Down
16 changes: 4 additions & 12 deletions lib/agi/main.agi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export class MainAGI<T extends ActionType> {
/**
* Initializes the AGI.
*/
protected initialize() {
protected initialize(dirname: string) {
this.ltmPath = path.join(
__dirname,
dirname,
'..',
'..',
'output',
Expand All @@ -57,21 +57,15 @@ export class MainAGI<T extends ActionType> {
);

this.logPath = path.join(
__dirname,
dirname,
'..',
'..',
'output',
'log',
this.consolidationId + '.log'
);

this.taskDir = path.join(
__dirname,
'..',
'..',
'task',
this.consolidationId
);
this.taskDir = path.join(dirname, '..', '..', 'task', this.consolidationId);
}

/**
Expand All @@ -81,8 +75,6 @@ export class MainAGI<T extends ActionType> {
* @returns A promise that resolves when the action is completed.
*/
public start = async (content: Content): Promise<any> => {
this.initialize();

const loggerUtil = new LoggerUtil(this.consolidationId, this.logPath);

await this.clearFolders(loggerUtil);
Expand Down

0 comments on commit d99f58d

Please sign in to comment.