forked from mastrogpt/python-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solutions.txt
48 lines (39 loc) · 1.24 KB
/
solutions.txt
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
## 1a read the input field from args in input, return '' as default
input = args.get("input", "")
## 1b return a dictionary with key 'body' and value output
return {
"body": output
}
## 1c add the demo entry, an object with name Demo and url mastrogpt/demo
{
"name": "Demo",
"url": "mastrogpt/demo",
},
## 2a connect ai with Azure OpenAI and return the api object
return AzureOpenAI(
api_version="2023-12-01-preview",
api_key=args.get("OPENAI_API_KEY"),
azure_endpoint=args.get("OPENAI_API_HOST"))
## 2b retrieve the model we use, check the status and return 'Welcome.' if is 'succeeded'
global MODEL
model = ai.models.retrieve(MODEL)
if model.status == 'succeeded':
output = "Welcome."
## 2c add the OpenAI entry, an object with name OpenAI and url openai/chat
{
"name": "OpenAI",
"url": "openai/chat",
},
## 3a generate the role as shown in test3.test_request
system = {"role": "system", "content": role}
user = {"role": "user", "content": input}
return [system, user]
## 3b invoke the chat completion API
comp = ai.chat.completions.create(
model=MODEL,
messages=request(input, role)
)
## 3c read the first message content if any
if len(comp.choices) >0:
res = comp.choices[0].message.content
##