Skip to content

Commit

Permalink
Merge pull request #3850 from ethereum/test_gpt
Browse files Browse the repository at this point in the history
call gpt service
  • Loading branch information
yann300 authored Sep 11, 2023
2 parents f933aee + 94f6958 commit 3d98761
Show file tree
Hide file tree
Showing 10 changed files with 331 additions and 138 deletions.
9 changes: 7 additions & 2 deletions apps/remix-ide/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {FileDecorator} from './app/plugins/file-decorator'
import {CodeFormat} from './app/plugins/code-format'
import {SolidityUmlGen} from './app/plugins/solidity-umlgen'
import {ContractFlattener} from './app/plugins/contractFlattener'
import {OpenAIGpt} from './app/plugins/openaigpt'

const isElectron = require('is-electron')

Expand Down Expand Up @@ -180,6 +181,9 @@ class AppComponent {
// ----------------- ContractFlattener ----------------------------
const contractFlattener = new ContractFlattener()

// ----------------- Open AI --------------------------------------
const openaigpt = new OpenAIGpt()

// ----------------- import content service ------------------------
const contentImport = new CompilerImports()

Expand Down Expand Up @@ -297,7 +301,8 @@ class AppComponent {
search,
solidityumlgen,
contractFlattener,
solidityScript
solidityScript,
openaigpt
])

// LAYOUT & SYSTEM VIEWS
Expand Down Expand Up @@ -410,7 +415,7 @@ class AppComponent {
])
await this.appManager.activatePlugin(['settings'])
await this.appManager.activatePlugin(['walkthrough', 'storage', 'search', 'compileAndRun', 'recorder'])
await this.appManager.activatePlugin(['solidity-script'])
await this.appManager.activatePlugin(['solidity-script', 'openaigpt'])

this.appManager.on('filePanel', 'workspaceInitializationCompleted', async () => {
// for e2e tests
Expand Down
8 changes: 7 additions & 1 deletion apps/remix-ide/src/app/panels/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { QueryParams } from '@remix-project/remix-lib'
const profile: Profile = {
name: 'layout',
description: 'layout',
methods: ['minimize', 'maximiseSidePanel', 'resetSidePanel']
methods: ['minimize', 'maximiseSidePanel', 'resetSidePanel', 'maximizeTerminal']
}

interface panelState {
Expand Down Expand Up @@ -109,6 +109,12 @@ export class Layout extends Plugin {
this.maximised[current] = true
}

async maximizeTerminal() {
this.panels.terminal.minimized = false
this.event.emit('change', this.panels)
this.emit('change', this.panels)
}

async resetSidePanel () {
this.event.emit('resetsidepanel')
const current = await this.call('sidePanel', 'currentFocus')
Expand Down
47 changes: 47 additions & 0 deletions apps/remix-ide/src/app/plugins/openaigpt.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Plugin } from '@remixproject/engine'
import { CreateChatCompletionResponse } from 'openai'

const _paq = (window._paq = window._paq || [])

const profile = {
name: 'openaigpt',
displayName: 'openaigpt',
description: 'openaigpt',
methods: ['message'],
events: [],
maintainedBy: 'Remix',
}

export class OpenAIGpt extends Plugin {
constructor() {
super(profile)
}

async message(prompt): Promise<CreateChatCompletionResponse> {
this.call('layout', 'maximizeTerminal')
this.call('terminal', 'log', 'Waiting for GPT answer...')
let result
try {
result = await (
await fetch('https://openai-gpt.remixproject.org', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({ prompt }),
})
).json()
} catch (e) {
this.call('terminal', 'log', { type: 'typewritererror', value: `Unable to get a response ${e.message}` })
return
}

if (result && result.choices && result.choices.length) {
this.call('terminal', 'log', { type: 'typewritersuccess', value: result.choices[0].message.content })
} else {
this.call('terminal', 'log', { type: 'typewritersuccess', value: 'No response...' })
}
return result.data
}
}
Loading

0 comments on commit 3d98761

Please sign in to comment.