1
+ <template >
2
+ <div >
3
+ <form >
4
+ <label >Key</label >
5
+ <input type =" text" v-model =" key" />
6
+ <label >Prompt:</label >
7
+ <textarea type =" text" v-model =" prompt" rows =" 20" cols =" 50" ></textarea >
8
+ <label >Temperature:</label >
9
+ <input v-model =" temperature" type =" number" min =" 0" max =" 1" step =" 0.1" />
10
+ <label >Top P:</label >
11
+ <input v-model =" top_p" type =" number" min =" 0" max =" 1" step =" 0.1" />
12
+ <label >Model:</label >
13
+ <select v-model =" model" >
14
+ <option v-for =" m in models" :value =" m" >{{ m }}</option >
15
+ </select >
16
+ </form >
17
+ <button @click =" submitForm" >Confirm</button >
18
+ <p style =" color :red ;white-space : pre-wrap ;" >{{response}}</p >
19
+ </div >
20
+ </template >
21
+
22
+
23
+ <script >
24
+ import axios from ' axios'
25
+ export default {
26
+ name: ' MainPage' ,
27
+ data () {
28
+ return {
29
+ key: ' ' ,
30
+ prompt: ' ' ,
31
+ temperature: 0.7 ,
32
+ top_p: 1 ,
33
+ max_tokens: 2048 ,
34
+ frequency_penalty: 0 ,
35
+ presence_penalty: 0.6 ,
36
+ stop: [" Human:" ," AI:" ],
37
+ model: ' text-davinci-003' ,
38
+ models: [' text-davinci-003' ,' text-davinci-002' , ' text-curie-001' ],
39
+ response: ' '
40
+ }
41
+ },
42
+ methods: {
43
+ submitForm () {
44
+ let data = {
45
+ prompt: this .prompt ,
46
+ temperature: this .temperature ,
47
+ top_p: this .top_p ,
48
+ model: this .model ,
49
+ max_tokens: this .max_tokens ,
50
+ frequency_penalty: this .frequency_penalty ,
51
+ presence_penalty: this .presence_penalty ,
52
+ stop: this .stop
53
+ }
54
+ axios .post (' https://api.openai.com/v1/completions' , data, {
55
+ headers: {
56
+ ' Content-Type' : ' application/json' ,
57
+ ' Authorization' : ` Bearer ` + this .key ,
58
+ }
59
+ })
60
+ .then (response => {
61
+ this .response = response .data .choices [0 ].text ;
62
+ console .log (this .response )
63
+ })
64
+ .catch (error => {
65
+ console .log (error);
66
+ });
67
+ }
68
+ }
69
+ }
70
+ </script >
0 commit comments