Skip to content

Commit

Permalink
Merge pull request #2 from d4rkstar/php-openai
Browse files Browse the repository at this point in the history
feat(runtime/php): support for redis and openai
  • Loading branch information
giusdp authored May 11, 2024
2 parents 837e7ea + 793980a commit 7978791
Show file tree
Hide file tree
Showing 35 changed files with 665 additions and 35 deletions.
21 changes: 19 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# Mac
.DS_Store

Expand All @@ -13,6 +30,8 @@ test.out

# Dependencies
vendor/
virtulenv/
node_modules/

# Go binary proxy
proxy
Expand Down Expand Up @@ -69,7 +88,5 @@ pkg/
.vscode/
.task
.env
virtulenv/
node_modules/
.env
.env.nuv
37 changes: 37 additions & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
header:
license:
spdx-id: Apache-2.0
copyright-owner: Apache Software Foundation

paths-ignore:
- '**/*.sample'
- 'env.src'
- '.git-hooks/pre-commit'
- '**/_*'
- 'nuvroot.json'
- 'LICENSE'
- 'cert-manager.yaml'
- 'ingress-deploy.yaml'
- 'runtimes.json'
- '**/*.json'
- '**/*.service'
- 'update/update.ps1'
- '**/mime.types'
- '**/*.txt'
21 changes: 20 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

version: '3'

dotenv: [.env]
Expand Down Expand Up @@ -87,6 +104,7 @@ tasks:
- task build-lang RT=golang PUSH="{{.PUSH}}"
- task build-lang RT=python PUSH="{{.PUSH}}"
- task build-lang RT=nodejs PUSH="{{.PUSH}}"
- task build-lang RT=php PUSH="{{.PUSH}}"

build-and-push:
- task build PUSH=y
Expand All @@ -104,12 +122,13 @@ tasks:
dir: "runtime/{{.RT}}/{{.VER}}"
cmds:
- docker run -p 8080:8080 -ti --entrypoint=/bin/bash -v $PWD:/mnt -e OW_COMPILER=/mnt/bin/compile "{{.BASEIMG}}/runtime-{{.RT}}-{{.VER}}:{{.TAG}}"



init:
desc: intialize a runtime with a test
requires: { vars: [RT, VER, T] }
cmds:
- nuv ide {{.RT}} pack A={{.RT}}/{{.T}}
- python3 packages/invoke.py init packages/{{.RT}}/{{.T}}.zip

invoke:
Expand Down
19 changes: 19 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->

module github.com/nuvolaris/nuvolaris-runtimes-ng

go 1.21.4
Expand Down
17 changes: 17 additions & 0 deletions openwhisk/_test/action/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

.DS_Store
/.build
/Packages
Expand Down
2 changes: 1 addition & 1 deletion packages/invoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def parseArgs():
def init(args):
main = args.main
artifact = args.artifact

if artifact and (args.binary or artifact.endswith('.zip') or artifact.endswith('tgz') or artifact.endswith('jar')):
with open(artifact, 'rb') as fp:
contents = fp.read()
Expand Down
19 changes: 19 additions & 0 deletions packages/nodejs/ask.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

//--web true
//--docker ghcr.io/nuvolaris/runtime-nodejs-v21:3.1.0-mastrogpt.2403032235
//--param OPENAI_API_KEY $OPENAI_API_KEY
Expand Down
19 changes: 19 additions & 0 deletions packages/nodejs/hello.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

//--web true
//--docker ghcr.io/nuvolaris/runtime-nodejs-v21:3.1.0-mastrogpt.2402201748

Expand Down
19 changes: 19 additions & 0 deletions packages/nodejs/multifile/hello.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

function hello(args) {
let name = args['name'] || "world"
return `Hello, ${name}.`
Expand Down
19 changes: 19 additions & 0 deletions packages/nodejs/multifile/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

//--web true
//--kind nodeks:default

Expand Down
19 changes: 19 additions & 0 deletions packages/nodejs/withreqs/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

//--web true
//--docker ghcr.io/nuvolaris/runtime-nodejs-v21:3.1.0-mastrogpt.2402201748

Expand Down
27 changes: 27 additions & 0 deletions packages/php/hello.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

//--web true
//--kind php:default
function main(array $args): array
{
$name = array_key_exists("name", $args) ? $args["name"] : "world";
return ['body' => sprintf('Hello %s', $name)];
}
56 changes: 56 additions & 0 deletions packages/php/openai.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

//--web true
//--kind php:default
//--param OPENAI_API_KEY $OPENAI_API_KEY
//--param OPENAI_API_HOST $OPENAI_API_HOST
function main(array $args): array
{
$openaiKey = array_key_exists('OPENAI_API_KEY',$args) ? $args['OPENAI_API_KEY'] : null;
$openaiHost = array_key_exists('OPENAI_API_HOST',$args) ? $args['OPENAI_API_HOST'] : null;

$model = "gpt-35-turbo";

if (empty($openaiHost)) {
$openaiHost = 'openai.nuvolaris.io';
}
if (empty($openaiKey)) {
return ['error'=>"OpenAI Key is not set"];
}

print "Sending request to $openaiHost";

$client = OpenAI::factory()
->withApiKey($openaiKey)
->withBaseUri($openaiHost)
->make();

$response = $client->models()->list();

/*$response = $client->chat()->create([
'model' => $model,
'messages' => [
['role' => 'user', 'content' => 'Hello!'],
],
]);*/

return ['body' => print_r($response, true)];
}
5 changes: 5 additions & 0 deletions packages/php/withcomposer/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"twig/twig": "^3.9"
}
}
Loading

0 comments on commit 7978791

Please sign in to comment.