-
Notifications
You must be signed in to change notification settings - Fork 494
/
chatgpt-pipeline.yaml
92 lines (84 loc) · 2.2 KB
/
chatgpt-pipeline.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: chatgpt-pipeline
kind: Pipeline
flow:
- filter: buildFinalResponse
- filter: checkRequestType
jumpIf:
result0: processText
"": END
# process text message
- filter: requestBuilderExtractText
alias: processText
namespace: extract
# send to ChatGPT
- filter: requestBuilderChatGPT
alias: chatGPT
namespace: gpt
- filter: proxyChatGPT
namespace: gpt
# send reply message to Telegram
- filter: requestBuilderReply
namespace: tg
- filter: proxyTelegram
namespace: tg
filters:
- kind: ResultBuilder
name: checkRequestType
template: |
{{- $msg := or .requests.DEFAULT.JSONBody.message .requests.DEFAULT.JSONBody.channel_post -}}
{{- if $msg.text}}result0{{end -}}
- kind: RequestBuilder
name: requestBuilderExtractText
template: |
{{- $msg := or .requests.DEFAULT.JSONBody.message .requests.DEFAULT.JSONBody.channel_post -}}
body: |
{
"exclude": true,
"text": "{{$msg.text | jsonEscape}}"
}
- kind: RequestBuilder
name: requestBuilderChatGPT
template: |
method: POST
url: /v1/chat/completions
headers:
"Authorization": ["Bearer {Your OpenAI API Key}"]
"Content-Type": ["application/json"]
body: |
{
"model": "gpt-3.5-turbo",
"messages": [{
"role": "user",
"content": "{{.requests.extract.JSONBody.text | jsonEscape}}"
}]
}
- kind: RequestBuilder
name: requestBuilderReply
template: |
{{$msg := or .requests.DEFAULT.JSONBody.message .requests.DEFAULT.JSONBody.channel_post}}
{{$resp := index .responses.gpt.JSONBody.choices 0}}
method: POST
# Please replace it with the url of your bot
url: https://api.telegram.org/bot{YOUR BOT TOKEN}/sendMessage
headers:
"Content-Type": ["application/json"]
body: |
{
"chat_id": {{$msg.chat.id}},
"reply_to_message_id": {{$msg.message_id}},
"text": "{{$resp.message.content | jsonEscape}}"
}
- name: proxyChatGPT
kind: Proxy
pools:
- servers:
- url: https://api.openai.com
- name: proxyTelegram
kind: Proxy
pools:
- servers:
- url: https://api.telegram.org
- kind: ResponseBuilder
name: buildFinalResponse
template: |
statusCode: 200