marp | theme | _class | paginate | backgroundColor | backgroundImage | html |
---|---|---|---|---|---|---|
true |
gaia |
lead |
true |
true |
-
a Python (or other languages) source code
- Single file or multi file
-
Receives a
dict
as input and returns adict
as output-
If it is a web actions, it produces HTML, JSON or others
-
You need to wrap the output in the
body
field:
-
{ "body": "<h1>Hello</h1>"}
-
[1a]
Read the input from the args -
[1b]
Return the result as an dictionary:{"output": output}
- remember to wrap the result in
{ "body" : ... }
- remember to wrap the result in
-
[1c]
Add the function to the index to use it...
from openai import AzureOpenAI
ver = "2023-12-01-preview"
# key and host provided by MastroGPT
key = args.get("OPENAI_API_KEY")
host = args.get("OPENAI_API_HOST")
# api call
ai = AzureOpenAI(
api_version=ver,
api_key=key,
azure_endpoint=host)
[2a]
connect ai with Azure OpenAI and return the api object
# retrieve informations about a model
MODEL = "gpt-35-turbo"
model = ai.models.retrieve(MODEL)
# if ok model.status == 'succeded'
-
[2b]
retrieve the model we use, check the status and return 'Welcome.' if is 'succeeded' -
[2c]
add the new chat to the index
Structure of a request:
[
{"role": "system", "content": ROLE},
{"role": "user", "content": input}
]
[3a]
a function to return a request
comp = ai.chat.completions.create(
model=MODEL,
messages=request(input, role)
)
[3b]
invoke the chat completion API
res = comp.choices[0].message.content
[3c]
read the first message content if any