-
Notifications
You must be signed in to change notification settings - Fork 952
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3850 from ethereum/test_gpt
call gpt service
- Loading branch information
Showing
10 changed files
with
331 additions
and
138 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
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 | ||
} | ||
} |
Oops, something went wrong.